[GH-ISSUE #413] Error with Lyft oAuth2 - Invalid client #264

Closed
opened 2026-03-03 16:47:11 +03:00 by kerem · 4 comments
Owner

Originally created by @sanchexx on GitHub (Sep 30, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/413

Description:

I'm trying to implement Lyft API but keep getting Invalid client errors.

I've found people were having similar issues with Uber #59 . Tried their solution but no luck. I still suspect it have something to do with encoding.

Attached snippets of code and error below

OAuth Provider (Twitter, Github, ..):

Lyft
https://developer.lyft.com/v1/docs/authentication

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.2 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 9.0 (Swift 4.0)

  • 9.0 (Swift 3.2)

  • 8.x (Swift 3.x)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c


Tried both with the block in comment and the one below it
`
var oauthswift:OAuth2Swift!

func authenticate(){
    oauthswift = OAuth2Swift(
        consumerKey:    "xxxxxxxxx",
        consumerSecret: "xxxxxxxxxxxxxxxxxx",
        authorizeUrl:   "https://api.lyft.com/oauth/authorize",
        accessTokenUrl: "https://api.lyft.com/oauth/token",
        responseType:   "code",
        contentType:    "application/json"
    )
    
    //oauthswift.authorize(
    //    withCallbackURL: URL(string: "wellness-prototype://oauth-callback/lyft")!,
    //    scope: "rides.read", state:"LYFT",
    //    success: { credential, response, parameters in
    //        print(credential.oauthToken)
    //         // Do your request
    //},
    //    failure: { error in
    //        print("ERROR USER INFO \(error.errorUserInfo)")
    //        print("ERROR UNDERLYING ERROR \(error.underlyingError)")
    //        print("ERROR DESCRIPTION \(error.description)")
    //}
    //)
    
    let state = generateState(withLength: 20)
    let redirectURL = "wellness-prototype://oauth-callback/lyft".addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed)
    let _ = oauthswift.authorize(
        withCallbackURL: URL(string: redirectURL!)!, scope: "rides.read", state: state,
        success: { credential, response, parameters in
            print(credential.oauthToken)
    },
        failure: { error in
            print(error.errorUserInfo)
            print(error.localizedDescription, terminator: "")
    }
    )
}

`

It seem that before even getting the request error, there is an Error copying creds
`
2017-09-30 18:04:13.197537-0400 Wellness Prototype[17594:13646546] CredStore - performQuery - Error copying matching creds. Error=-25300, query={
class = inet;
"m_Limit" = "m_LimitAll";
ptcl = htps;
"r_Attributes" = 1;
sdmn = "lyft-public-api";
srvr = "api.lyft.com";
sync = syna;
}

["request": https://api.lyft.com/oauth/token, "error": Error Domain=NSURLErrorDomain Code=401 "invalid_client Unauthorized" UserInfo={Response-Body={
"error_description": "Unauthorized",
"error": "invalid_client"
}
, NSErrorFailingURLKey=https://api.lyft.com/oauth/token, Response-Headers={
"Cache-Control" = "no-store";
"Content-Length" = 72;
"Content-Type" = "application/json;charset=UTF-8";
Date = "Sat, 30 Sep 2017 22:04:13 GMT";
Pragma = "no-cache";
Server = "envoy-iad";
"Www-Authenticate" = "Basic realm="lyft-public-api"";
"request-id" = "d8bd8080-7086-90c8-82df-fabf19523d68";
"x-envoy-upstream-service-time" = 2;
}, OAuthSwiftError.response=<NSHTTPURLResponse: 0x60c0002204c0> { URL: https://api.lyft.com/oauth/token } { status code: 401, headers {
"Cache-Control" = "no-store";
"Content-Length" = 72;
"Content-Type" = "application/json;charset=UTF-8";
Date = "Sat, 30 Sep 2017 22:04:13 GMT";
Pragma = "no-cache";
Server = "envoy-iad";
"Www-Authenticate" = "Basic realm="lyft-public-api"";
"request-id" = "d8bd8080-7086-90c8-82df-fabf19523d68";
"x-envoy-upstream-service-time" = 2;
} }, OAuthSwiftError.response.data=<7b0a2020 22657272 6f725f64 65736372 69707469 6f6e223a 2022556e 61757468 6f72697a 6564222c 200a2020 22657272 6f72223a 2022696e 76616c69 645f636c 69656e74 220a7d0a>, NSLocalizedDescription=invalid_client Unauthorized}]

The operation couldn’t be completed. (OAuthSwiftError error -11.)2017-09-30 18:04:13.273343-0400
`

Originally created by @sanchexx on GitHub (Sep 30, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/413 ### Description: I'm trying to implement Lyft API but keep getting Invalid client errors. I've found people were having similar issues with Uber #59 . Tried their solution but no luck. I still suspect it have something to do with encoding. Attached snippets of code and error below ### OAuth Provider (Twitter, Github, ..): Lyft https://developer.lyft.com/v1/docs/authentication ### OAuth Version: - [ ] Version 1 - [X] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [X] CocoaPods - [ ] Manually ### Library version: - [ ] head - [X] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [X] 9.0 (Swift 4.0) - [ ] 9.0 (Swift 3.2) - [ ] 8.x (Swift 3.x) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c --- Tried both with the block in comment and the one below it ` var oauthswift:OAuth2Swift! func authenticate(){ oauthswift = OAuth2Swift( consumerKey: "xxxxxxxxx", consumerSecret: "xxxxxxxxxxxxxxxxxx", authorizeUrl: "https://api.lyft.com/oauth/authorize", accessTokenUrl: "https://api.lyft.com/oauth/token", responseType: "code", contentType: "application/json" ) //oauthswift.authorize( // withCallbackURL: URL(string: "wellness-prototype://oauth-callback/lyft")!, // scope: "rides.read", state:"LYFT", // success: { credential, response, parameters in // print(credential.oauthToken) // // Do your request //}, // failure: { error in // print("ERROR USER INFO \(error.errorUserInfo)") // print("ERROR UNDERLYING ERROR \(error.underlyingError)") // print("ERROR DESCRIPTION \(error.description)") //} //) let state = generateState(withLength: 20) let redirectURL = "wellness-prototype://oauth-callback/lyft".addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed) let _ = oauthswift.authorize( withCallbackURL: URL(string: redirectURL!)!, scope: "rides.read", state: state, success: { credential, response, parameters in print(credential.oauthToken) }, failure: { error in print(error.errorUserInfo) print(error.localizedDescription, terminator: "") } ) } ` It seem that before even getting the request error, there is an Error copying creds ` 2017-09-30 18:04:13.197537-0400 Wellness Prototype[17594:13646546] CredStore - performQuery - Error copying matching creds. Error=-25300, query={ class = inet; "m_Limit" = "m_LimitAll"; ptcl = htps; "r_Attributes" = 1; sdmn = "lyft-public-api"; srvr = "api.lyft.com"; sync = syna; } ["request": https://api.lyft.com/oauth/token, "error": Error Domain=NSURLErrorDomain Code=401 "invalid_client Unauthorized" UserInfo={Response-Body={ "error_description": "Unauthorized", "error": "invalid_client" } , NSErrorFailingURLKey=https://api.lyft.com/oauth/token, Response-Headers={ "Cache-Control" = "no-store"; "Content-Length" = 72; "Content-Type" = "application/json;charset=UTF-8"; Date = "Sat, 30 Sep 2017 22:04:13 GMT"; Pragma = "no-cache"; Server = "envoy-iad"; "Www-Authenticate" = "Basic realm=\"lyft-public-api\""; "request-id" = "d8bd8080-7086-90c8-82df-fabf19523d68"; "x-envoy-upstream-service-time" = 2; }, OAuthSwiftError.response=<NSHTTPURLResponse: 0x60c0002204c0> { URL: https://api.lyft.com/oauth/token } { status code: 401, headers { "Cache-Control" = "no-store"; "Content-Length" = 72; "Content-Type" = "application/json;charset=UTF-8"; Date = "Sat, 30 Sep 2017 22:04:13 GMT"; Pragma = "no-cache"; Server = "envoy-iad"; "Www-Authenticate" = "Basic realm=\"lyft-public-api\""; "request-id" = "d8bd8080-7086-90c8-82df-fabf19523d68"; "x-envoy-upstream-service-time" = 2; } }, OAuthSwiftError.response.data=<7b0a2020 22657272 6f725f64 65736372 69707469 6f6e223a 2022556e 61757468 6f72697a 6564222c 200a2020 22657272 6f72223a 2022696e 76616c69 645f636c 69656e74 220a7d0a>, NSLocalizedDescription=invalid_client Unauthorized}] The operation couldn’t be completed. (OAuthSwiftError error -11.)2017-09-30 18:04:13.273343-0400 `
kerem closed this issue 2026-03-03 16:47:12 +03:00
Author
Owner

@sanchexx commented on GitHub (Sep 30, 2017):

Testing on iOS 10.3 instead of iOS 11, I don't get the first error 'Error copying matching creds'

The invalid client problem still happens though

<!-- gh-comment-id:333340302 --> @sanchexx commented on GitHub (Sep 30, 2017): Testing on iOS 10.3 instead of iOS 11, I don't get the first error 'Error copying matching creds' The invalid client problem still happens though
Author
Owner

@phimage commented on GitHub (Oct 1, 2017):

I cannot create account, I think with my french phone number
So I can't test and help...

I fix the demo apps for swift4 and put a code for lyft (but not activated yet)

<!-- gh-comment-id:333374717 --> @phimage commented on GitHub (Oct 1, 2017): I cannot create account, I think with my french phone number So I can't test and help... I fix the demo apps for swift4 and put a code for lyft (but not activated yet)
Author
Owner

@phimage commented on GitHub (Oct 1, 2017):

@sanchexx try to set oauthswift.accessTokenBasicAuthentification to true
I see basic auth in doc

<!-- gh-comment-id:333375689 --> @phimage commented on GitHub (Oct 1, 2017): @sanchexx try to set oauthswift.accessTokenBasicAuthentification to true I see basic auth in doc
Author
Owner

@sanchexx commented on GitHub (Oct 1, 2017):

@phimage Thanks! Adding the Basic Authentification solved the issue.

<!-- gh-comment-id:333391764 --> @sanchexx commented on GitHub (Oct 1, 2017): @phimage Thanks! Adding the Basic Authentification solved the issue.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#264
No description provided.