1

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 :)

winston
  • 3,000
  • 11
  • 44
  • 75

1 Answers1

0

Mine said this in Android (not sure it will help) but turns out, I had the wrong Client ID entered into my webview.

Once i changed it to the right client ID that was in the Twitch dev dashboard, it pulled up the auth page. Also, I am using my home URL as the redirect, not localhost. Not sure if that made a difference either. Good luck!!