Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for PKCE in OIDC social providers #4009

Closed
5 tasks done
OskarsPakers opened this issue Jul 19, 2024 · 9 comments · Fixed by #4078
Closed
5 tasks done

Support for PKCE in OIDC social providers #4009

OskarsPakers opened this issue Jul 19, 2024 · 9 comments · Fixed by #4078
Labels
feat New feature or request.

Comments

@OskarsPakers
Copy link

Preflight checklist

Ory Network Project

No response

Describe your problem

Some identity providers require Proof Key for Code Exchange (PKCE) code_challenge query parameter in authorization endpoint and code_verifier in token exchange endpoint

Describe your ideal solution

Generic provider had configuration to enable and generate code_challenge upon redirect to identity provider and sends verifier value when echanging code for token.
oauth2 go package already supports generating verifier and the challenge https://pkg.go.dev/golang.org/x/oauth2#S256ChallengeFromVerifier

Workarounds or alternatives

Implementing custom provider might be an option, but it seems that oidc strategy must be change too to pass AuthCodeOption to token exchange

token, err = te.Exchange(ctx, code)

Version

2.2.0

Additional Context

I`d like to submit pull request if this feature makes sense. Any hints appreciated

@OskarsPakers OskarsPakers added the feat New feature or request. label Jul 19, 2024
@IchordeDionysos
Copy link
Contributor

Would be amazing to have, we've also ran into this twice now (in our case we could just disable PKCE).
Had this with some customers identity provider and recently I've experienced it while enabling support for Salesforce.

@aeneasr
Copy link
Member

aeneasr commented Jul 23, 2024

Yeah, that makes sense. There’s probably a library for Go that does that and that can easily be added to e.g. Salesforce

@IchordeDionysos
Copy link
Contributor

Note: In Salesforce, you can disable PKCE :) See the documentation here ory/docs#1797

It would be nice to have that possibility in generic providers, though.

@OskarsPakers
Copy link
Author

We plan to submit pull request for this in upcoming days.
The plan is to extend provider_config.go Configuration object with PKCSMethod attribute with possible value "S256" and if it is set, generate code_verifier, send code_challenge parameter to authentication request and code_verifier value to /token endpoint when exchanging the code. Does it sound ok?
What is the appropriate place to persist generated code_verifier between requests in the flow?
Extend State struct or maybe s.d.LoginFlowPersister() or s.d.SessionManager()?
Thank you

@alnr
Copy link
Contributor

alnr commented Aug 13, 2024

Hey. We will probably make some adjustments to how OIDC login works (internally) in the near future, so I would recommend maybe holding off on PRs for the moment (sorry I haven't had time yet to look at yours).

Also, we'd probably need auto-discovery of PKCE support (coreos/go-oidc#401) with fallback to non-PKCE flows in case of failures for backwards-compatiblity.

@OskarsPakers
Copy link
Author

Well we already did the pull request. Should we then continue improving it with discovery and make it so that challenge is always sent if provider supports it and drop the pkcs_method from the config?

@alnr alnr changed the title Support for PKCS in OIDC social providers Support for PKCE in OIDC social providers Aug 14, 2024
@alnr
Copy link
Contributor

alnr commented Aug 14, 2024

I'm quite confident we don't need to make PKCE configurable. The only scenario where that would make sense is when the provider advertises PKCE support but doesn't actually support it. Seems far-fetched. Then again, you never know.

The more difficult question is where to store the verifier. There will be some changes regarding that part of the code in the near future, so I would recommend holding off on that part of the implementation for now.

@aeneasr
Copy link
Member

aeneasr commented Sep 14, 2024

Thank you @OskarsPakers for your original work on this! It has made it‘s way in another PR to master now :)

@OskarsPakers
Copy link
Author

Awesome! Thank you for finishing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request.
Projects
None yet
4 participants