Created
May 4, 2018 08:58
-
-
Save prasanthu/281f9da1b0cda92b106ac08a422a4178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func showLogin() { | |
guard let clientInfo = plistValues(bundle: Bundle.main) else { return } | |
//let APIIdentifier = "https://" + clientInfo.domain + "/userinfo" // Replace with the API Identifier value you created | |
let APIIdentifier = "http://google_api" // Replace with the API Identifier value you created | |
Auth0 | |
.webAuth() | |
.audience(APIIdentifier) | |
.scope("openid profile email") | |
.connectionScope("email") | |
.start { | |
switch $0 { | |
case .failure(let error): | |
// Handle the error | |
print("Error: \(error)") | |
case .success(let credentials): | |
print("credentials: \(credentials)") | |
guard let accessToken = credentials.accessToken, let idToken = credentials.idToken else { return } | |
//print("accessToken: \(accessToken)") | |
HomeViewController.printToken(token: accessToken) | |
//print("idToken: \(idToken)") | |
HomeViewController.printToken(token: idToken) | |
SessionManager.shared.storeTokens(accessToken, idToken: idToken) | |
SessionManager.shared.retrieveProfile { error in | |
guard error == nil else { | |
return self.showLogin() | |
} | |
DispatchQueue.main.async { | |
self.performSegue(withIdentifier: "ShowProfileNonAnimated", sender: nil) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment