Skip to content

[#1262] Authenticate before prompting for the OAuth2 device user code - #1265

Open
vharseko wants to merge 3 commits into
OpenIdentityPlatform:masterfrom
vharseko:fix/1262-device-verification-login
Open

vharseko wants to merge 3 commits into
OpenIdentityPlatform:masterfrom
vharseko:fix/1262-device-verification-login

Conversation

@vharseko

@vharseko vharseko commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #1262

A signed-out user had to enter the same device code twice when login interrupted verification. With this change, the user enters the code once, including when the client requests a non-default authentication chain.

The default verification URI identifies the issuing realm and includes the requested acr_values as a hint for the first login. This lets a child realm on a shared hostname direct the browser to the right login. An existing URI without a realm still shows the code form first. Its POST uses the realm stored on the device code.

If the initial login used a different chain, OpenAM uses the ACR stored on the submitted code to select the mapped chain. The login return URL carries an opaque handle bound to the browser's HTTP session. On return, OpenAM checks the session against the ACR requested for that code. If a custom login page returns the default chain again, the browser shows the required authentication method and the device stays pending. If the chain matches, the form restores the code for confirmation. The device remains pending until a CSRF-protected POST, and explicit consent still requires the user's approval.

Tests

  • All 1,012 OAuth2 module tests passed.
  • All 32 Playwright scenarios in the device verification and device PKCE suites passed on a single OpenAM node running the PR WAR with the updated OAuth2 classes. They cover new and legacy verification URIs on a shared hostname, one code entry with implied and explicit consent, and session loss before submission. The mapped-chain scenarios check the acr claim in the issued ID token.
  • Two browser tests cover custom login templates. A template that forwards only goto leaves the device pending and shows an error naming the required ACR. A template that selects the mapped chain restores the submitted code and records the matching acr in the ID token after confirmation.
  • The explicit-consent fixture was also checked on a reused client. Setup changed its persisted isConsentImplied from true to false, and the browser displayed the consent prompt.
  • The original browser regression failed on the unmodified 16.1.4 release. Six browser scenarios passed on 16.1.4 with the initial fix.

@vharseko vharseko added bug javascript Pull requests that update Javascript code oauth2 OAuth2 / OpenID Connect tests Test suite: coverage, fixtures, or test infrastructure java Pull requests that update java code labels Dec 1, 2026
@vharseko
vharseko requested a review from maximthomas December 1, 2026 09:41

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The implied- and explicit-consent browser scenarios check that login alone leaves the device pending and that one code submission leads to token issuance.


issue (blocking): The default verification URI no longer works with a valid child-realm session on a shared hostname.

DeviceCodeVerificationResource.java:421–425

When a child provider leaves its verification URL blank, the issued URI is the deployment's realm-less /oauth2/device/user. On the base, GET displays the form and POST loads the code and applies its stored realm before client lookup and session validation, so a user signed into the child realm can complete verification on that URI. HEAD checks the realm inferred from the shared hostname on GET and sends that user to root login. If the subsequent POST directs the browser to child login, its return URL is still the realm-less URI, where the GET rejects the child session again. Default URI construction, base GET, POST code lookup and realm attributes, login return URL

Generate a realm-qualified verification URI by default and preserve compatibility for already-issued realm-less URLs by deferring the realm check on those URLs until the code identifies the provider.

Closure criterion On a shared hostname, a signed-out visitor can verify a child-realm device via its newly issued URI with one code entry. A visitor with a valid child session can still verify through an existing realm-less URI.


issue (blocking): Pre-login skips the mapped authentication chain for a signed-out device user.

ResourceOwnerSessionValidator.java:223–228

For a code issued with acr_values mapped to a non-default chain, the base learned that value on the first POST and selected the mapped chain in the login redirect. HEAD's GET authenticates against the realm default before the code is known. On the implied-consent POST, a valid same-realm session from the default chain can be accepted with ACR 0 because setCurrentAcr records the mismatch and validation proceeds. Stored ACR, base login chain selection, HEAD ACR matching, device approval

Keep the device verification pending while the browser completes the mapped chain when the initial login does not match. Preserve the verification continuation across that login.

Closure criterion A signed-out user with a code that requests a configured non-default chain completes that chain, the approved code records the matching ACR, and the user enters the code once.


suggestion (non-blocking): Check the consent setting before reusing a device client fixture.

device-flow-test.spec.mjs:125–129

The setup reuses an existing client based on its response type. On a reused instance where the explicit-consent client's persisted isConsentImplied is true, setup succeeds and the browser waits for an Allow button that never appears. Compare the stored flag with the requested value before returning and use the existing PUT for a mismatch. Fixture setup, browser assertion

@vharseko
vharseko force-pushed the fix/1262-device-verification-login branch from 2ef2757 to c772792 Compare December 1, 2026 11:52
@vharseko

vharseko commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@maximthomas, I addressed all three findings in c772792.

  • Child realms. The default verification URI now identifies the issuing realm. On a shared hostname, the browser tests complete verification both from the new URI after login and from the legacy realm-less URI with an existing child-realm session.
  • Mapped authentication chains. The issued URI selects the requested chain at the first login. I also tested a bookmark without the ACR hint. When its initial login uses the default chain, the device stays pending through the mapped login. The user confirms the previously entered code, and the issued ID token contains the mapped acr in both scenarios.
  • Consent fixture. Setup now checks the persisted consent flag before reusing a client. I seeded the explicit-consent client with isConsentImplied=true, ran the browser suite, and read the client back to verify that setup restored false.

All 1,012 OAuth2 module tests and all 30 device verification and PKCE Playwright scenarios passed.

@vharseko
vharseko requested a review from maximthomas December 1, 2026 11:54

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The bookmark scenario checks that the mapped login keeps the device pending, restores the submitted code, and records the matching ACR in the redeemed ID token.


issue (blocking): Stop repeating the mapped login when a custom login template keeps returning the default chain.

ResourceOwnerSessionValidator.java:229–238

With implied consent and a custom login template that forwards only goto, a signed-out user can get a valid session from the default chain and submit a code requesting a different mapped chain. Each POST now requires that chain, but the custom login builder renders the same login target without selecting it. The return GET accepts the same-realm session and shows the confirmation again. The previous revision approved the device with an unmatched ACR of 0. On HEAD the device remains pending until expiry. Custom-template test · POST guard · Login URL builders · Return GET · Previous approval path

Preserve the mapped-ACR requirement and track whether the server-side continuation already requested the mapped login. If the returned session still lacks the chain, show an actionable error. Custom login integrations that can satisfy the mapped ACR should complete the existing confirmation flow.

Closure criterion A custom login that returns the default chain never sends the user through repeated login and confirmation. When it returns the mapped chain, the browser completes authorization with one code entry, the same CSRF-protected confirmation, and the matching ACR.

@vharseko

vharseko commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@maximthomas, I fixed the custom login loop in 9d17593. OpenAM remembers which ACR it requested for the submitted device code and checks the session as soon as the browser returns. If the custom login page returns the default chain again, the browser shows the required authentication method and the device stays pending.

I reproduced the repeated confirmation on the previous revision with a template that forwards only goto. The new browser tests cover that template and one that selects the mapped chain. In the latter case the user enters the code once, confirms it with the CSRF-protected form, and receives an ID token with the matching acr.

All 1,012 OAuth2 module tests and all 32 device verification and PKCE browser scenarios passed.

@vharseko
vharseko requested a review from maximthomas December 1, 2026 13:14

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The custom-login browser tests check pending state on both return paths and verify the ID token ACR after successful confirmation.


suggestion (non-blocking): Preserve a pending confirmation when the user signs in again through the default chain.

DeviceCodeVerificationResource.java:189–191

After mapped login has displayed the confirmation, a sign-out and default-chain sign-in in another tab can replace the SSO session while the servlet continuation and form CSRF token remain valid. On the previous revision, submitting the open form offered mapped login again. The current POST returns access_denied and asks the user to restart. A separate follow-up could let this POST request a fresh mapped login and keep the terminal check on its return GET. Previous POST · Current mismatch handling

Follow-up priority Low

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug java Pull requests that update java code javascript Pull requests that update Javascript code oauth2 OAuth2 / OpenID Connect tests Test suite: coverage, fixtures, or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Device Authorization Flow requests the user code twice after authentication

2 participants