-
Couldn't load subscription status.
- Fork 2
add PKCE support #17
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
add PKCE support #17
Conversation
|
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #17 +/- ##
==========================================
- Coverage 50.45% 42.85% -7.61%
==========================================
Files 1 1
Lines 109 133 +24
==========================================
+ Hits 55 57 +2
- Misses 54 76 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
BTW, I tested the code with two different servers with and without extra certificate. |
|
Meanwhile, I am not so sure whether it's a clever idea to store the code and code_verifier in a global dict. Maybe it's better to append the verifier to the code and do a split inside flow_get_token. Let me try ... |
|
Switched to concatenating code and code_verifier rather than storing it temporarily in ctx. |
|
@tanmaykm would you mind reviewing this PR? |
|
Thanks @hhaensel . Will take a look! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, except for a suggestion regarding the type of "code" returned from flow_get_authorization_code.
| if haskey(ctx.code_verifiers, state) | ||
| code_verifier = pop!(ctx.code_verifiers, state) | ||
| # as space characters are not allowed in code strings, it is safe to conacatenate with ' ' | ||
| code *= " $code_verifier" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should have a new Code struct that can hold both code and code_verifier? There is a small chance that it may break code that assumes the returned code to be a string. But it seems much cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thoughts, but I didn't want it to be breaking. Then I verified that a space character is not part of the code (https://docs.unidy.io/technical-documentation/43Yox8946664zbsR6p9VyD/oidc-authorization-flow-requesting-an-authorization-code/4c2Hsrxi5YB8w2HScPWnjx), so I opted for the current solution.
If you are in favour of a type, say
struct Code
code::String
verifier::String
endwe could add
Base.convert(String, code::Code) = code.codeor
Base.convert(String, code::Code) = isempty(code.verifier) ? code.code : "$(code.code) $(code.verifier)"which would avoid a part of breaking scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks for explaining. Let's keep it as it is.
This PR fixes #12 by adding a keyword
pkceto `flow_request_authorization_code()Usage
Call
flow_request_authorization_code(ctx; pkce = true)Internal Flow
OIDCCtxnow contains a fieldcode_verifiersto hold the verifiers that are generated during the code_challenge.flow_request_authorization_code(ctx; pkce = true)generates a pair ofcode_challengeandcode_verifierand stores the latter inctx.code_verifiers[state].flow_get_authorization_code(ctx, query)retrieves the code together with the state and checks whether a verifier is stored under the state. If so it appends the verifier to the code with a leading space character and deletes it fromcode_verifiers(This is safe as the space character is not allowed as part of the code.)flow_get_token(ctx, code)checks whethercodecontains an appended verifier, if so it sends it together with the token request.purge_states!()method has been adapted to also purge the verifiers. (And it has been renamed due to inconsistency with and without exclamation mark.)Miscellaneous
Manifest.tomlhas been added to.gitignoreEDIT: adapted to the changed verfier handling