-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(oauth): omit blank pkce from url when not supported #21976
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
Conversation
danieldietzler
left a comment
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.
You can keep the old syntax and simply return undefined in the or case of the ternary instead.
|
i tried it with undefined: const url = buildAuthorizationUrl(client, {
redirect_uri: redirectUrl,
scope: config.scope,
state,
code_challenge: client.serverMetadata().supportsPKCE() ? codeChallenge : undefined,
code_challenge_method: client.serverMetadata().supportsPKCE() ? 'S256' : undefined,
}).toString();but that gives me some typing errors "Type 'string | undefined' is not assignable to type 'string'. would you accept something like this ? const url = buildAuthorizationUrl(client, {
redirect_uri: redirectUrl,
scope: config.scope,
state,
...(client.serverMetadata().supportsPKCE() && {code_challenge: codeChallenge, code_challenge_method: 'S256'}),
}).toString();
return { url, state, codeVerifier };
} |
|
I guess it doesn't really matter but I personally do prefer that, yes. FYI I just looked at the RFC and |
|
The spec that you pointed to is for the pkce extension specifically, and not oauth2 as a whole. Meaning IF you are using pkce then you must absolutely provide those keys. however my change is for setups that are not using pkce please see the below from section 5 (emphasis mine) "Server implementations of this specification may accept OAuth 2.0 clients that do not implement this extension. If the "code_verifier" is not received from the client in the Authorization Request, servers supporting backwards compatibility revert to the OAuth 2.0 [RFC6749] protocol without this extension." let me know if you are good with it or not and i can edit my merge thanks EDIT / PS: for additional info/clarity the Here is a cognito example : Since the "code_challenge_methods_supported" property is omitted, it means the provider does not support PKCE. Therefore, the supportsPKCE() function in the openid-client library will correctly return false. But right now the code is ignoring the metadata and sending the (blank) code challenge {
"authorization_endpoint": "https://login.domain.com/oauth2/authorize",
"end_session_endpoint": "https://login.domain.com/logout",
"id_token_signing_alg_values_supported": [
"RS256"
],
"issuer": "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_XXXXXXXX",
"jwks_uri": "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_XXXXXXXX/.well-known/jwks.json",
"response_types_supported": [
"code",
"token"
],
"revocation_endpoint": "https://login.domain.com/oauth2/revoke",
"scopes_supported": [
"openid",
"email",
"phone",
"profile"
],
"subject_types_supported": [
"public"
],
"token_endpoint": "https://login.domain.com/oauth2/token",
"token_endpoint_auth_methods_supported": [
"client_secret_basic",
"client_secret_post"
],
"userinfo_endpoint": "https://login.domain.com/oauth2/userInfo"
}In my opinion, the current behavior of sending a blank the code should be binary:
|
430e17d to
e8b20d2
Compare
Oh damn it, should've read more closely, apologies! Thanks for the very elaborate answer. :) |
jrasm91
left a comment
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'd probably prefer moving the options to a variable and then doing if(pkce) { add properties to object }
Can I get some guidance on my next steps? My initial commit was assembling the string as you discribed, but Daniel requested the update to the spread method. I'm happy to update as needed just need to know the right method to use Thanks |
|
That's too funny lol |
Description
This change fixes an issue with OAuth providers that do not support blank (empty) PKCE strings, such as AWS Cognito. The original code would send an empty
code_challengeandcode_challenge_methodto the OAuth provider, which would cause these providers to return an error. This change modifies the code to only send these parameters if the OAuth provider explicitly supports PKCE. this has been a problem for my instance since 1.132.0 . this issue is discussed in this thread by another user. #18482 (comment)Fixes # (issue)
How Has This Been Tested?
This change has been tested manually with AWS Cognito.
code_challengeandcode_challenge_methodparameters are not sent to the OAuth provider when the provider does not support PKCE.code_challengeandcode_challenge_methodparameters are sent to the OAuth provider when the provider does support empty PKCE strings.Screenshots (if appropriate)
Checklist:
src/services/uses repositories implementations for database calls, filesystem operations, etc.src/repositories/is pretty basic/simple and does not have any immich specific logic (that belongs insrc/services/)Please describe to which degree, if any, an LLM was used in creating this pull request.
I used an LLM to verify the spelling/grammar of this pull request description. LLM was not used for the actual code changes as they were relatively simple (adding a conditional check to the url builder)