Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 1.15 KB

README.md

File metadata and controls

45 lines (31 loc) · 1.15 KB

Usage

GitHubAuth.shared.configure(
    clientId: "CLINET_ID",
    clientSecret: "CLIENT_SECRET"
)

GitHubAuth.shared.signIn { error in
    print(error) // nil
    
    print(GitHubAuth.shared.accessToken) // Access Token
    print(GitHubAuth.shared.isSignedIn) // True
    
    let req = NSMutableURLRequest(URL: NSURL(string: "https://api.github.com/user")!)

    GitHubAuth.shared.authorize(req)
    print(req.allHTTPHeaderFields) // Authorization: token ACCESS_TOKEN
    
    if let data = try? NSURLConnection.sendSynchronousRequest(req, returningResponse: nil) {
        if let content = String(data: data, encoding: NSUTF8StringEncoding) {
            print(content) // {"login":"tnantoka"...
        }
    }
    
    GitHubAuth.shared.signOut()
    print(GitHubAuth.shared.isSignedIn) // False
}

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • GitHub API (Default callback URL: https://example.com/)

Installation

GitHubAuth is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "GitHubAuth"