[GH-ISSUE #501] Does OAuthSwift support the Authorization code with proof key flow? I am not seeing where we can send a code challenge. #330

Closed
opened 2026-03-03 16:47:44 +03:00 by kerem · 8 comments
Owner

Originally created by @scottblomquistjr on GitHub (Dec 12, 2018).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/501

Description:

I am trying to use this library with Okta Authorization code with proof key flow. However I keep getting an error on my server "code_challenge is missing". Is this flow not supported?

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

Okta

OAuth Version:

  • Version 1
  • [x ] Version 2

OS (Please fill the version) :

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

Installation method:

  • Carthage
  • [ x] CocoaPods
  • Manually

Library version:

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

Xcode version:

  • 9.3 (Swift 4.1)

  • 9.0 (Swift 4.0)

  • 9.0 (Swift 3.2)

  • 8.x (Swift 3.x)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • [x ] other: (Please fill in the version you are using.)
    10 (Swift 4.2)

  • objective c

Originally created by @scottblomquistjr on GitHub (Dec 12, 2018). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/501 ### Description: I am trying to use this library with Okta Authorization code with proof key flow. However I keep getting an error on my server "code_challenge is missing". Is this flow not supported? ### OAuth Provider? (Twitter, Github, ..): Okta ### 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: - [ x] head - [ ] v1.2.1 - [ ] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [ ] 9.3 (Swift 4.1) - [ ] 9.0 (Swift 4.0) - [ ] 9.0 (Swift 3.2) - [ ] 8.x (Swift 3.x) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [x ] other: (Please fill in the version you are using.) 10 (Swift 4.2) - [ ] objective c
kerem 2026-03-03 16:47:44 +03:00
Author
Owner

@BjoeBrunn commented on GitHub (Jan 4, 2019):

I have the same issue.
There is no way to insert a code_verifier parameter during the second step to get the access token with the code provided in the first step.
As a quick workaround I inserted a new variable codeVerifier in the OAuth2Swift code, a new initializer and modified the postOAuthAccessTokenWithRequestToken function in order to add this extra parameter as the parameters in the original function are limited to client_id, client_secret, code and grant_type.
This way, authentication with PKCE works.

<!-- gh-comment-id:451559781 --> @BjoeBrunn commented on GitHub (Jan 4, 2019): I have the same issue. There is no way to insert a code_verifier parameter during the second step to get the access token with the code provided in the first step. As a quick workaround I inserted a new variable codeVerifier in the OAuth2Swift code, a new initializer and modified the postOAuthAccessTokenWithRequestToken function in order to add this extra parameter as the parameters in the original function are limited to client_id, client_secret, code and grant_type. This way, authentication with PKCE works.
Author
Owner

@phimage commented on GitHub (Jan 7, 2019):

https://tools.ietf.org/html/rfc7636

@BjoeBrunn if you make a fork (or a PR) I will look at it to see the flow
If you know other provider which use that. I see Okta, Salesforce

<!-- gh-comment-id:451854153 --> @phimage commented on GitHub (Jan 7, 2019): https://tools.ietf.org/html/rfc7636 @BjoeBrunn if you make a fork (or a PR) I will look at it to see the flow If you know other provider which use that. I see Okta, Salesforce
Author
Owner

@mraible commented on GitHub (Feb 3, 2019):

@BjoeBrunn I’d love to see your code too. I’m trying to make an Ionic 4 app work with Okta using https://github.com/moberwasserlechner/capacitor-oauth2 (which uses this library).

<!-- gh-comment-id:460077942 --> @mraible commented on GitHub (Feb 3, 2019): @BjoeBrunn I’d love to see your code too. I’m trying to make an Ionic 4 app work with Okta using https://github.com/moberwasserlechner/capacitor-oauth2 (which uses this library).
Author
Owner

@BjoeBrunn commented on GitHub (Feb 3, 2019):

Hi Matt,

This is a sketch, how to use the proof key flow :


var oauth: OAuth2Swift {
        let oauth = OAuth2Swift(consumerKey: consumerKey,
                           consumerSecret: consumerSecret,
                           authorizeUrl: authorizeUrl,
                           accessTokenUrl: accessTokenUrl,
                           responseType: "code")
        oauth.accessTokenBasicAuthentification = true
        return oauth
}


let _ = oauth.authorize(
    withCallbackURL: provider.callback,
        scope: provider.scope,
        state: state,
        codeChallenge: codeChallenge.challenge,
        codeChallengeMethod: codeChallenge.method,
        codeVerifier: codeChallenge.verifier,
        success: { (credential, response, parameters) in
        print("Authorize: success!")
                success()
        },
        failure: { (error) in
                failure(error)
                print("Authorize: error: \(error.localizedDescription)")
        })

I hope this helps,

Regards,

Björn

<!-- gh-comment-id:460082221 --> @BjoeBrunn commented on GitHub (Feb 3, 2019): Hi Matt, This is a sketch, how to use the proof key flow : ```swift var oauth: OAuth2Swift { let oauth = OAuth2Swift(consumerKey: consumerKey, consumerSecret: consumerSecret, authorizeUrl: authorizeUrl, accessTokenUrl: accessTokenUrl, responseType: "code") oauth.accessTokenBasicAuthentification = true return oauth } let _ = oauth.authorize( withCallbackURL: provider.callback, scope: provider.scope, state: state, codeChallenge: codeChallenge.challenge, codeChallengeMethod: codeChallenge.method, codeVerifier: codeChallenge.verifier, success: { (credential, response, parameters) in print("Authorize: success!") success() }, failure: { (error) in failure(error) print("Authorize: error: \(error.localizedDescription)") }) ``` I hope this helps, Regards, Björn
Author
Owner

@phimage commented on GitHub (Feb 4, 2019):

readme edited by #510
implementation done by #506

I close
If any issue, feel free to open a new github issue

<!-- gh-comment-id:460289428 --> @phimage commented on GitHub (Feb 4, 2019): readme edited by #510 implementation done by #506 I close If any issue, feel free to open a new github issue
Author
Owner

@moberwasserlechner commented on GitHub (Feb 9, 2019):

Hey,

It would be really appreciated if you create a release with PKCE in Cocoapods.

I develop a library so I have to use a version from cocoapods because other depends on it. For testing I could use the master directly but for a production release it's to risky.

Thanks & BR

<!-- gh-comment-id:462058580 --> @moberwasserlechner commented on GitHub (Feb 9, 2019): Hey, It would be really appreciated if you create a release with PKCE in Cocoapods. I develop a library so I have to use a version from cocoapods because other depends on it. For testing I could use the master directly but for a production release it's to risky. Thanks & BR
Author
Owner

@mraible commented on GitHub (Feb 21, 2019):

I agree! A release with this feature would be awesome.

<!-- gh-comment-id:465864355 --> @mraible commented on GitHub (Feb 21, 2019): I agree! A release with this feature would be awesome.
Author
Owner

@phimage commented on GitHub (Feb 21, 2019):

🎉 Congrats

🚀 OAuthSwift (1.3.0) successfully published
📅 February 21st
🌎 https://cocoapods.org/pods/OAuthSwift
👍 Tell your friends!

<!-- gh-comment-id:466009663 --> @phimage commented on GitHub (Feb 21, 2019): 🎉 Congrats 🚀 OAuthSwift (1.3.0) successfully published 📅 February 21st 🌎 https://cocoapods.org/pods/OAuthSwift 👍 Tell your friends!
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#330
No description provided.