raulriera / AuthenticationViewController

A simple to use, standard interface for authenticating to oauth 2.0 protected endpoints via SFSafariViewController.
MIT License
257 stars 14 forks source link

Google implementation connector for OAuth2 #8

Open jalopezsuarez opened 6 years ago

jalopezsuarez commented 6 years ago

Here I share the connector for Google OAuth2 with an usage example (hope its help):

OAuthGoogle.swift

static let ClientId = "188766122934-0t21j64fd4qmcomewpho6jeqwxe6kpwq.apps.googleusercontent.com"
static let ClientSecret = "AIza34De1h2JIehyugxcgYnXewtokGdi0xXPsJMTY"

static let ScopeYoutubeReadonly = "https://www.googleapis.com/auth/youtube.readonly"
static let ScopeUserinfoEmail = "https://www.googleapis.com/auth/userinfo.email"
static let ScopeUserinfoProfile = "https://www.googleapis.com/auth/userinfo.profile"
let provider = OAuthGoogle(clientId: ServiceRequest.ClientId, clientSecret: "", scopes: [ServiceRequest.ScopeUserinfoEmail, ServiceRequest.ScopeUserinfoProfile, ServiceRequest.ScopeYoutubeReadonly])
let authenticationViewController = AuthenticationViewController(provider: provider)
authenticationViewController.failureHandler = { error in
    print(error)
}
authenticationViewController.authenticationHandler = { token in
    print (token)
    authenticationViewController.dismiss(animated: true, completion: nil)
}
present(authenticationViewController, animated: true, completion: nil)
raulriera commented 6 years ago

I hope that clientId and secret are not the real ones 🙂, thanks for the demo tho