[GH-ISSUE #628] Withings OAuth2 not working #409

Closed
opened 2026-03-03 16:48:27 +03:00 by kerem · 1 comment
Owner

Originally created by @rowellx68 on GitHub (Oct 21, 2020).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/628

Description:

Withings has since moved to OAuth2 and they have since added a required parameter for all endpoints. This causes the the auth to fail since we are not providing action when we request the access token.

As per the new docs, we need to provide requesttoken to the action parameter. This is on top of what is already provided.

What is the best way to customise this section?

open func postOAuthAccessTokenWithRequestToken(byCode code: String, callbackURL: URL?, headers: OAuthSwift.Headers? = nil, completionHandler completion: @escaping TokenCompletionHandler) -> OAuthSwiftRequestHandle? {

        var parameters = OAuthSwift.Parameters()
        parameters["client_id"] = self.consumerKey
        parameters["code"] = code
        parameters["grant_type"] = "authorization_code"

        // PKCE - extra parameter
        if let codeVerifier = self.codeVerifier {
            parameters["code_verifier"] = codeVerifier
            // Don't send client secret when using PKCE, some services complain
        } else {
            // client secrets should only be used for web style apps where they can't be decompiled (use pkce instead), so if it's empty, don't post it as some servers will reject it
            // https://www.oauth.com/oauth2-servers/client-registration/client-id-secret/
            if !self.consumerSecret.isEmpty {
                parameters["client_secret"] = self.consumerSecret
            }
        }

        if let callbackURL = callbackURL {
            parameters["redirect_uri"] = callbackURL.absoluteString.safeStringByRemovingPercentEncoding
        }

        OAuthSwift.log?.trace("Add security parameters: \(parameters)")
        return requestOAuthAccessToken(withParameters: parameters, headers: headers, completionHandler: completion)
    }

OAuth Provider? (Twitter, Github, ..):

Withings

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

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

Installation method:

  • Carthage
  • CocoaPods
  • Swift Package Manager
  • Manually

Library version:

  • head
  • v2.1.0
  • v2.0.0
  • v1.4.1
  • other: (Please fill in the version you are using.)

Xcode version:

  • 11.4 (Swift 5.2)

  • 11.x (Swift 5.1)

  • 10.x (Swift 5.0)

  • other: 12

  • objective c

Originally created by @rowellx68 on GitHub (Oct 21, 2020). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/628 ### Description: Withings has since moved to OAuth2 and they have since added a required parameter for all endpoints. This causes the the auth to fail since we are not providing `action` when we request the access token. As per the new [docs](http://developer.withings.com/oauth2/#operation/oauth2-getaccesstoken), we need to provide `requesttoken` to the `action` parameter. This is on top of what is already provided. What is the best way to customise [this](https://github.com/OAuthSwift/OAuthSwift/blob/8e94866ddbb0b252be5483eac14fd3cd5065e0c9/Sources/OAuth2Swift.swift#L212-L237) section? ```swift open func postOAuthAccessTokenWithRequestToken(byCode code: String, callbackURL: URL?, headers: OAuthSwift.Headers? = nil, completionHandler completion: @escaping TokenCompletionHandler) -> OAuthSwiftRequestHandle? { var parameters = OAuthSwift.Parameters() parameters["client_id"] = self.consumerKey parameters["code"] = code parameters["grant_type"] = "authorization_code" // PKCE - extra parameter if let codeVerifier = self.codeVerifier { parameters["code_verifier"] = codeVerifier // Don't send client secret when using PKCE, some services complain } else { // client secrets should only be used for web style apps where they can't be decompiled (use pkce instead), so if it's empty, don't post it as some servers will reject it // https://www.oauth.com/oauth2-servers/client-registration/client-id-secret/ if !self.consumerSecret.isEmpty { parameters["client_secret"] = self.consumerSecret } } if let callbackURL = callbackURL { parameters["redirect_uri"] = callbackURL.absoluteString.safeStringByRemovingPercentEncoding } OAuthSwift.log?.trace("Add security parameters: \(parameters)") return requestOAuthAccessToken(withParameters: parameters, headers: headers, completionHandler: completion) } ``` ### OAuth Provider? (Twitter, Github, ..): Withings ### OAuth Version: - [ ] Version 1 - [x] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [ ] CocoaPods - [x] Swift Package Manager - [ ] Manually ### Library version: - [x] head - [ ] v2.1.0 - [ ] v2.0.0 - [ ] v1.4.1 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [ ] 11.4 (Swift 5.2) - [ ] 11.x (Swift 5.1) - [ ] 10.x (Swift 5.0) - [x] other: 12 - [ ] objective c
kerem closed this issue 2026-03-03 16:48:28 +03:00
Author
Owner

@phimage commented on GitHub (Nov 10, 2020):

I see nothing the with current code

you could subclass and override postOAuthAccessTokenWithRequestToken
and copy all code (I expect all is public)

if not or to do a better job all code from postOAuthAccessTokenWithRequestToken except the last line could be extracted to
parametersForPostOAuthAccessTokenWithRequestToken() -> OAuthSwift.Parameters()
and then you could also subclass and override only this function, call the super and add only your new attribute

or just a function(need override class too) or closure to customise it

<!-- gh-comment-id:724442388 --> @phimage commented on GitHub (Nov 10, 2020): I see nothing the with current code you could subclass and override `postOAuthAccessTokenWithRequestToken` and copy all code (I expect all is public) if not or to do a better job all code from postOAuthAccessTokenWithRequestToken except the last line could be extracted to `parametersForPostOAuthAccessTokenWithRequestToken() -> OAuthSwift.Parameters()` and then you could also subclass and override only this function, call the super and add only your new attribute or just a function(need override class too) or closure to customise it
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#409
No description provided.