Skip to content

Device Authorization Flow requests the user code twice after authentication #1262

In review

Description

@dairoca90

Describe the bug

When using the OAuth 2.0 Device Authorization Grant (/oauth2/device/user), OpenAM requests the user_code before authenticating the end user.

If the user is not authenticated, submitting the code redirects the browser to the configured authentication service. After successful authentication, OpenAM redirects the browser back to /oauth2/device/user, but displays the user code form again instead of resuming the original verification flow.

As a result, the user must enter the same user_code twice to complete device authorization.

To Reproduce

Steps to reproduce the behavior:

  1. Request a device authorization code using the OAuth 2.0 Device Authorization endpoint.
  2. Open the returned verification_uri in a browser.
  3. Enter the generated user_code.
  4. Submit the form while not authenticated.
  5. Observe that OpenAM redirects the browser to the configured authentication service.
  6. Authenticate successfully.
  7. Observe that OpenAM redirects the browser back to /oauth2/device/user.
  8. Notice that the user code form is displayed again.
  9. Enter the same user_code a second time.
  10. Observe that OpenAM finally displays the completion page (done: true).

Expected behavior

The device verification flow should not require the user to enter the same user_code twice.

After successful authentication, OpenAM should either:

  • Resume the pending device verification using the previously submitted user_code, or
  • Authenticate the user before displaying the user code form.

In either case, the user should only need to enter the code once.

According to RFC 8628, Section 3.3, the authorization server defines the exact user interaction sequence, which includes authentication and supplying the user_code. The current behavior introduces an unnecessary repeated code-entry step when authentication interrupts the verification process.

Desktop (please complete the following information):

  • OS: macOS (Apple Silicon)
  • Browser: Google Chrome
  • Version: 158.0.0.0

Smartphone (please complete the following information):

  • Device: Not tested
  • OS: Not tested
  • Browser: Not tested
  • Version: Not tested

Additional context

  • Product: OpenIdentityPlatform OpenAM
  • Version: 16.1.4
  • Feature: OAuth 2.0 Device Authorization Grant
  • Endpoint: /oauth2/device/user
  • Authentication service: LDAP authentication service
  • Deployment: OpenAM behind an HTTPS reverse proxy (ngrok during testing)

The behavior appears to involve DeviceCodeVerificationResource.java:

openam-oauth2/src/main/java/org/forgerock/oauth2/restlet/DeviceCodeVerificationResource.java

The initial POST contains the submitted user_code. However, when authentication is required, the redirect to /UI/Login only preserves the destination /oauth2/device/user.

After successful authentication, the browser performs a new GET request to /oauth2/device/user, and the verification form is rendered again instead of resuming the pending verification.

The issue is reproducible with OpenAM 16.1.4.

RFC 8628 – OAuth 2.0 Device Authorization Grant

Activity

  1. added 7 commits that reference this issue on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions