ex_oauth2_provider
ex_oauth2_provider copied to clipboard
Implement PKCE
Implement PKCE for authorization code grant type, as per RFC-7637:
- add string fields
code_challengeandcode_challenge_methodtooauth_access_grantstable which will contain the PKCE information. Add instructions for upgrading. - add config option
use_pkce. Iftruewhen issuing grants thecode_challengeandcode_challenge_methodquery fields are mandatory and are saved to the grant model. Iffalsethese fields are ignored and the corresponding grant models are set tonil - when emitting an access token, the grant model is checking for having the
code_challenge_methodfield set. If set to a value not nil then thecode_verifierquery field is mandatory and it's used to check against the grant'scode_challengefield. If set to nil this query parameter is ignored and the grant acts as though PKCE is disabled.
Partially inspired by https://github.com/danschultzer/ex_oauth2_provider/pull/61
Aww man! I was going to implement this, but you beat me to it.
I think it would be a good idea to add a test with the examples in Appendix A and Appendix B.
Appendix B
I'll see If I have time later for this. But feel free to contribute with the tests if you need it right away :)
Appendix B
I'll see If I have time later for this. But feel free to contribute with the tests if you need it right away :)
I'm still new to Elixir, but I may give it a try later :)
Waiting for this to be merged to upstream. A very good PR!
Just one note. use_pkce: true forces PKCE for all applications. There are use cases when you want to enable it for some applications only. For example, I want to force it for javascript apps, but don't for server-side apps. What if instead of using the global config parameter we do these things instead:
- If
code_challengeis present in the authorization request, we assume the client wants PKCE check and enable it. - We add a field to the
oauth_applicationstable something likerequire_pkce, and if it's true, we fail the authorization if the parameters are not present.
What do you think?
@Ross65536 Made a PR to your repo :) https://github.com/Ross65536/ex_oauth2_provider/pull/1