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 
6
  • 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 Commented Sep 30, 2019 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 Commented Sep 30, 2019 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 Commented Sep 30, 2019 at 19:23
  • 1
    based on 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 (stackoverflow.com/questions/39481636/…). Commented Sep 30, 2019 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: github.com/OAuthSwift/OAuthSwift maybe the code is outdated in the readme? Commented Oct 1, 2019 at 0:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.