Skip to content

fix: re-authenticate when requested scopes exceed the cached token - #68

Open
mjdavidson wants to merge 1 commit into
okta:mainfrom
mjdavidson:fix/reauth-on-scope-change
Open

fix: re-authenticate when requested scopes exceed the cached token#68
mjdavidson wants to merge 1 commit into
okta:mainfrom
mjdavidson:fix/reauth-on-scope-change

Conversation

@mjdavidson

Copy link
Copy Markdown

is_valid_token decided validity from token presence and age only, never comparing the requested OKTA_SCOPES to the scopes the cached token carries — so newly added scopes silently never took effect (a refresh exchange cannot widen scopes). This decodes the access token's scp/scope claim and forces a fresh device grant when a requested okta.* scope is missing. OIDC/base scopes are excluded from the comparison, and a one-shot guard prevents a re-auth loop when a scope was never granted to the app.\n\nTests: tests/test_auth_manager.py.

is_valid_token only checked token presence and age, never whether the cached
token actually grants the requested scopes. After adding a scope to OKTA_SCOPES
and restarting, the still-fresh cached token was reused and a refresh-token
exchange cannot widen scopes, so the new scopes never took effect without
manually deleting the keyring entries.

Decode the access token's scp/scope claim (no signature verification) and treat
the token as invalid when a requested okta.* scope is absent, forcing a fresh
device grant that re-requests the full scope set. OIDC/base scopes are excluded
from the comparison since Okta does not echo them in the access token, and
non-JWT tokens fall back to the existing age and 401/403 handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant