Created
June 11, 2021 02:49
-
-
Save StarLard/3a3420ec664adb83de019fe0295f80a0 to your computer and use it in GitHub Desktop.
Brief demo showcasing SFAuthenticationSession
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 SafariServices | |
var authSession: SFAuthenticationSession? | |
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.authSession = SFAuthenticationSession.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.authSession?.start() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment