cognito-oauth-token-tester
v0.1.2
Published
Local browser tool to fetch and inspect AWS Cognito OAuth tokens for multiple users federated via Entra ID, forcing a fresh per-user login each time.
Downloads
454
Maintainers
Readme
Cognito OAuth Token Tester
A local, browser-only tool to fetch and inspect AWS Cognito OAuth tokens
(id_token, access_token, refresh_token) for multiple users federated
through Entra ID. It forces a fresh, per-user login on every request so the
external IDP's cached session can't silently return the wrong user's token.
Run
Without installing (uses the published build):
npx cognito-oauth-token-testerThis serves the app at http://localhost:4173 (override with PORT).
From source (for development):
npm install
npm run devOpen http://localhost:5173.
Cognito app client requirements
- Public client, no client secret.
- PKCE enabled, grant type Authorization code.
- Allowed callback URL includes
http://localhost:5173(must match the Redirect URI you enter in the app exactly). - Allowed sign-out URL includes
http://localhost:5173(required for the logout-first flow below). - Entra ID configured as an OIDC identity provider on the user pool; note its
provider name (for
identity_provider) or set anidp_identifieralias.
Entra app registration requirements (for the logout-first flow)
- A post-logout redirect URI of
http://localhost:5173registered in the Entra app registration (Authentication → Front-channel logout / redirect URIs). - Your tenant id or domain (e.g.
contoso.onmicrosoft.com), entered in the app's Entra tenant config field.
How it forces the right user
Important: Cognito does not reliably forward
login_hint/promptto a federated IdP like Entra. So those params alone do not switch users — Entra's cached SSO session silently returns whoever is already signed in. That is why this tool clears the sessions first.
Logout-first flow (default, recommended). When force fresh login is on, each Get Token click runs this sequence before authorizing:
- Cognito sign-out (
/logout) — clears the Cognito hosted-UI session. - Entra logout (
/oauth2/v2.0/logout) — clears the Entra SSO cookie (only if an Entra tenant is configured). - Authorize — now Cognito re-federates and Entra is forced to prompt, so you can sign in as the user you actually picked.
The authorize request still sends (each toggleable in the UI):
identity_provider/idp_identifier— skip the Cognito chooser, go to Entra.login_hint=<email>— preselect the user if your setup forwards it.prompt=login— request a fresh login if your setup forwards it.
If you turn force fresh login off, the app skips the logout steps and relies only on those params — which may return the cached user (see the note above).
Usage
- Fill in Cognito Configuration (saved to
localStorage), including the Entra tenant if you want the Entra session cleared. - Add user emails under Users.
- Click Get Token → for a user. The app clears the cached sessions, then Entra prompts you — sign in as that user — and you return with tokens.
- Each user gets a token card with a live expiry countdown, Refresh, auto-refresh toggle, copy buttons, and JWT decode.
- Verify you got the right user: expand decode on the
id_tokenand check theemail/subclaims match the user you picked.
Tests
npm run testSecurity note
This is a local developer/testing tool. Tokens are stored in localStorage for
convenience across the redirect round-trip. Do not deploy it as-is to a shared
or public host.
