-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/oauth2: support PKCE #59835
Comments
Implements incoming proposal golang/go#59835
CC @golang/security |
A remark: A client needs to store the verifier for the exchange, possibly for a long time, since user interaction is required. Also, since you may run the service distributed, serialization and a database (or a session cookie) might be involved. The challenge is only send with the initial request and not used afterwards. So using |
@ianlancetaylor Could this be added to the proposal discussion to give it more visibility? |
This proposal has been added to the active column of the proposals project |
I'm wondering if that ship has sailed if you want to reuse the existing |
I like this idea, it's simpler. I'll update the proposal. @andig the authhandler package has very few users and it seems skipped the proposal process, so I'm indifferent to reusing authhandler.PKCEParams |
Do we need a new method, or should the PKCE verifier just be an AuthCodeOption? |
@rsc For PKCE you need to send one set of query parameters with AuthCodeURL (code_challenge and code_challenge_method) and a different set with Exchange (code_verifier). Passing the same AuthCodeOption to both AuthCodeURL and Exchange thus won't work. A solution could be to introduce intermediate functions That's very appealing to me, because the API and code changes are both smaller. I'll prepare to update the proposal and CL. |
Updated proposal and https://go-review.googlesource.com/c/oauth2/+/463979 including example |
Logical next step if this gets accepted would be deprecating the authhandler package. |
With regards to #61401 there are a number of oauth2 applications that today cannot use the |
It sounds like the current proposal is:
Do I have that right? Does that look right to people? |
Having re-checked my code I would additionally suggest
Otherwise this API is strictly tied to being able to use |
With the three funcs in my comment and the one func in @andig's followup comment, have all remaining concerns been addressed? |
When you need code for the above: https://github.com/fillmore-labs/login-sample/blob/main/web/app/pkce/pkce.go I could adapt the signatures to the one suggested by @rsc . Otherwise, take what you like and thanks for the work. Just an additional note: This needs documentation, sample code and should probably be the default. It might be useful to discuss at least the last aspect, since the current approach is only an extension to the existing library, which has “state“ directly in the API, but not PKCE. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
@rsc @ianlancetaylor @andig Brilliant! https://go-review.googlesource.com/c/oauth2/+/463979 is ready for review. Please add more reviewers. The oauth2 code owners are inactive. |
Change https://go.dev/cl/463979 mentions this issue: |
Noticed one thing after the merge.
Yet, |
Fixes golang#603 Fixes golang/go#59835 Change-Id: Ica0cfef975ba9511e00f097498d33ba27dafca0d GitHub-Last-Rev: f01f759 GitHub-Pull-Request: golang#625 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/463979 Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Matt Hickford <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
feature request golang/oauth2#603
Motivation: support PKCE (RFC 7636), also known as code_challenge and code_verifier. PKCE is an OAuth best practice that protects against authorization code injection attacks and CSRF. Draft spec OAuth 2.1 makes PKCE required by default:
Currently to use PKCE with x/oauth2, you have to generate the verifier and challenge yourself, and use SetAuthURLParam to send the appropriate subsets of parameters with AuthCodeURL and Exchange. GitHub code search shows few users doing this.
Adding user-friendly PKCE support to x/oauth2 would make it easier to write secure OAuth clients.
Proposed x/oauth2 API:
And also #59835 (comment)
Prototype implementation https://go-review.googlesource.com/c/oauth2/+/463979
The text was updated successfully, but these errors were encountered: