Created
June 11, 2021 02:43
-
-
Save StarLard/567585c3c11efd7cd16efe9a2433ca5b to your computer and use it in GitHub Desktop.
Brief demo showcasing ASWebAuthenticationSession
This file contains hidden or 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
import AuthenticationServices | |
var webAuthSession: ASWebAuthenticationSession? | |
@available(iOS 12.0, *) | |
func logInWithBlizzard() { | |
//Blizzard OAuth URL | |
let authURL = URL(string: "https://myRegioncode.battle.net/oauth/authorize?access_type=online&client_id=myClientID&redirect_uri=myRedirectURI&response_type=code&state=") | |
let loginUrlScheme = "myAppName" | |
//Initialize auth session | |
self.webAuthSession = ASWebAuthenticationSession.init(url: authURL!, callbackURLScheme: loginUrlScheme) { | |
(callBack, error) in | |
// handle errors if they occur | |
if let authError = error { | |
return | |
} | |
guard let successRedirectURL = callBack else { | |
return | |
} | |
// Get your code from the redirect url. You can also check for the state if needed. | |
let authCode = successRedirectURL.lastPathComponent | |
// Exchange your authorization code for an access token, and use your token to make calls to the API. | |
myRequestTokenFunc(withAuthCode: authCode) | |
}) | |
// Start the session | |
self.webAuthSession?.start() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment