I'm using OAuthSwift to send the user to Twitch to authorize my app. However, once the app is authorized, the user isn't sent back to my app. I get a message that appears in Safari:
You are about to leave Twitch. Twitch has no control over the content or security of http://localhost.
I tried to handle this in the AppDelegate but it doesn't seem to be redirecting:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (url.host == "http://localhost") {
OAuthSwift.handle(url: url)
}
return true
}
Here's the code that fires the Twitch auth:
@IBAction func didPressLoginButton(_ sender: Any) {
// create an instance and retain it
let oauthswift = OAuth2Swift(
consumerKey: "xxxxx",
consumerSecret: "xxxxx",
authorizeUrl: "https://id.twitch.tv/oauth2/authorize",
accessTokenUrl: "https://id.twitch.tv/oauth2/token",
responseType: "code",
contentType: "application/json"
)
oauthswift.authorizeURLHandler = OAuthSwiftOpenURLExternally.sharedInstance
self.oauthswift = oauthswift
//oauthswift.accessTokenBasicAuthentification = true
//let codeVerifier = base64url("abcd...")
//let codeChallenge = codeChallenge(for: codeVerifier)
let handle = oauthswift.authorize(withCallbackURL: URL(string: "http://localhost")!, scope: "user:read:email", state:"TWITCH") { result in
switch result {
case .success(let (credential, response, parameters)):
print(credential.oauthToken)
TwitchTokenManager.shared.accessToken = credential.oauthToken
//Twitch.Clips.getClips
// Do your request
case .failure(let error):
print(error.localizedDescription)
}
}
}
Any help would be greatly appreciated. Thanks :)