fix(sso): request the OIDC scopes at the Entra ID authorization endpoint - #3226
Open
marevol wants to merge 1 commit into
Open
fix(sso): request the OIDC scopes at the Entra ID authorization endpoint#3226marevol wants to merge 1 commit into
marevol wants to merge 1 commit into
Conversation
The authorization request asked only for https://graph.microsoft.com/.default, so whether an id_token and a refresh token come back depended on the app registration's static permissions happening to include openid, profile and offline_access. msal4j already prepends those three to the token request -- see COMMON_SCOPES in OAuthAuthorizationGrant -- so the two halves of the flow were asking for different things. Naming them in the authorization request means consent is asked for the same set the token exchange goes on to request. The scope parameter is now URL encoded, which a space-separated value requires. The v1.0 branch is untouched: it uses the resource parameter rather than scopes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The v2.0 authorization request asked for one scope:
"/oauth2/v2.0/authorize?response_type=code&scope=https://graph.microsoft.com/.default&...".defaultresolves to whatever delegated permissions the app registration has been granted, sowhether an
id_tokenand a refresh token come back depends on that registration happening toinclude
openid,profileandoffline_access.validateNonce()readsauthData.idToken()unconditionally, so a registration withoutopenidfails the login with aconfusing message.
Meanwhile msal4j already asks for those three at the token endpoint —
COMMON_SCOPESinOAuthAuthorizationGrant:So the two halves of the same flow were asking for different things: consent was collected for one
set, the token exchange requested another.
Fix
Ask for the same set at the authorization endpoint:
Microsoft documents
.defaultas combinable with exactly these three. The scope parameter is nowURL encoded, which a space-separated value requires — previously the single scope happened to
contain no characters needing it.
The v1.0 branch is untouched: it identifies the resource with the
resourceparameter rather thanthrough scopes.
Scope of the claim
This is a consistency and robustness fix, not a repair of a confirmed breakage. Because msal4j
adds the OIDC scopes at the token step, an existing deployment whose app registration has consent
for them is already getting an id_token and a refresh token today. What changes is that the
authorization request no longer depends on that being true.
Tests
EntraIdAuthenticator's unit test class, 2 new tests, the first failing before the change(
expected: <openid profile offline_access https://graph.microsoft.com/.default> but was: <https://graph.microsoft.com/.default>):test_getAuthUrl_requestsTheOidcScopesUpFront— decodes thescopeparameter out of the builtURL and compares it exactly
test_getAuthUrl_encodesTheScopeParameter— a raw space would truncate the query string(the whole
org.codelibs.fess.ssopackage)