0

I'm trying to use the OAuthSwift library to get an authorization token for a user logging in with their Twitch account. I'm using the example code but I think there's an issue with Swift 5. I'm using XCode Version 10.3 (10G8):

    // create an instance and retain it
    oauthswift = OAuth2Swift(
        consumerKey:    "***",
        consumerSecret: "***",
        authorizeUrl: "https://id.twitch.tv/oauth2/validate",
        responseType: "code"
    )
    oauthswift.accessTokenBasicAuthentification = true

    //let codeVerifier = base64url("abcd...")
    //let codeChallenge = codeChallenge(for: codeVerifier)

    let handle = oauthswift.authorize(
        withCallbackURL: URL(string: "localhost")!,
        scope: "", state:"TWITCH") { result in
            switch result {
            case .success(let (credential, response, parameters)):
                print(credential.oauthToken)
            // Do your request
            case .failure(let error):
                print(error.localizedDescription)
            }
    }
} 

I got an error on line oauthswift.accessTokenBasicAuthentification = true:

Value of type 'OAuthSwift?' has no member 'accessTokenBasicAuthentification'

And then I get an error on the let handle = line:

Value of type 'OAuthSwift?' has no member 'authorize'

Any help would be greatly appreciated.

Thanks!

EDIT: Might be an issue with Cocoapods. I can't do pod 'OAuthSwift', '~> 2.0.0', says it can't find that version. Just installing using pod 'OAuthSwift' without the version number just installs v1.3.0

EDIT 2:

Got it! Thanks to Kiril I was able to update the library to v2 (I used pod install instead of pod update). Then once the library updated I had to use add the let initializer. Updated code:

// create an instance and retain it
        let oauthswift = OAuth2Swift(
            consumerKey:    "***",
            consumerSecret: "***",
            authorizeUrl: "https://id.twitch.tv/oauth2/validate",
            responseType: "code"
        )

        self.oauthswift = oauthswift
        oauthswift.accessTokenBasicAuthentification = true
winston
  • 3,000
  • 11
  • 44
  • 75
  • IMO there's no problem with your code, there's a problem with your project setup. Are you using cocoapods? what happens when you jump to definition of `OAuth2Swift` - does it have those properties, etc – timbre timbre Sep 30 '19 at 19:19
  • Yes I'm using cocoapods, sorry I didn't specify. XCode doesn't show that the property exists (intellisense isn't loading it). Really confused – winston Sep 30 '19 at 19:21
  • ok I think I know what the problem is, using cocoapods I can't do ` pod 'OAuthSwift', '~> 2.0.0'`, says it can't find that version. Just installing using ` pod 'OAuthSwift'` without the version number just installs v1.3.0 – winston Sep 30 '19 at 19:23
  • 1
    based on https://cocoapods.org/pods/OAuthSwift, version 2 should be there. I tried on my side, and have no error with v 2.0.0. So run `pod update` and if that doesn't help, update pods (https://stackoverflow.com/questions/39481636/updating-to-latest-version-of-cocoapods/41518456). – timbre timbre Sep 30 '19 at 21:38
  • Thanks! That helped. I was using `pod install` instead of `pod update`, and it installed 2.0 just fine! However I'm still getting the same errors from the original question. I'm trying to follow along this example right on the main library page: https://github.com/OAuthSwift/OAuthSwift maybe the code is outdated in the readme? – winston Oct 01 '19 at 00:35
  • fixed it! I think I was missing the `let` initializer. I also updated XCode to version 11 but I think my code was a bit off. Updated question – winston Oct 01 '19 at 12:39

0 Answers0