FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Self-service /account/login returns 401 "Access denied" after a successful code exchange (production only, 1.71.0)

    Scheduled Pinned Locked Moved Unsolved
    Q&A
    1
    1
    10
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tkates
      last edited by

      Summary
      On our production instance, the hosted self-service account pages deny every user. After login, the final
      redirect to /account/login returns 401 "Access denied" and clears the account-session cookies. The OAuth
      debug log shows that the authorization code exchange inside that flow succeeds, so the denial happens after
      it. The same configuration works on our other FusionAuth instances. We'd like to know which check after the
      exchange produces this 401, and how to see its reason.

      Environment

      • FusionAuth 1.71.0, self-hosted, Docker image fusionauth/fusionauth-app:1.71.0 on Kubernetes. Starter licence.
      • Installed in silent mode with Kickstart; configuration then applied through the API.
      • FUSIONAUTH_APP_RUNTIME_MODE=production, SEARCH_TYPE=database, managed PostgreSQL.
      • Two FusionAuth nodes, one in each of two Kubernetes clusters, sharing the same database. The clusters
        cannot reach each other, and fusionauth-app.url is http://localhost:9011 on both nodes.
      • Request path: a cloud load balancer, then an internal router, then an Apache reverse proxy that sets X-Forwarded-Proto:
        https, X-Forwarded-Host: auth.example.edu and X-Forwarded-Port: 443, then FusionAuth.
        trustedProxyConfiguration is OnlyConfigured and lists the proxy CIDRs. FusionAuth logs the real client IP,
        so the forwarded headers are being honoured.
      • One tenant. Self-service form set on the application: a custom form containing only the password field.
        requireCurrentPasswordOnPasswordChange is on.

      Reproduction (deterministic)

      1. Fresh private browser window: https://auth.example.edu/account/?client_id=<client_id>
      2. 302 to /account/login?client_id&tenantId, then 302 to /oauth2/authorize (PKCE S256,
        redirect_uri=/account/login, scope offline_access).
      3. Log in. It fails the same way with a local password user and with users from our SAML v2 identity provider.
      4. /oauth2/consent 302 to /account/login?client_id&tenantId&code&iss&locale&state&userState=Authenticated
      5. That request returns 401 "Access denied". The response sets fusionauth.at, fusionauth.rt, fusionauth.csrf
        and fusionauth.app.pkce-verifier to empty with Max-Age=0. The request carried prime-mvc-saved-request,
        fusionauth.csrf, fusionauth.app.pkce-verifier and fusionauth.sso, all set earlier in the same flow.

      Evidence that the code exchange succeeds
      With oauthConfiguration.debug enabled on the application, the event log records this for the flow
      (Scopes requested [offline_access]):
      Validate the provided authorization code ...
      Validate PKCE code_challenge ... Calculated code_challenge [matches]
      Ensure the provided request parameters match those provided the authorization request.
      User is registered for application with Id [<client_id>] the [roles] and [applicationId] claims will be added.
      The authorization code has been successfully exchanged for an access token.

      What we have ruled out

      • User or registration data: the test user is active and verified, and registered to the application with a
        role. A newly created local password user fails the same way.
      • Signing keys: a token from the Login API for the same user and application validates with
        GET /api/jwt/validate (200), and its RS256 signature verifies against /api/jwt/public-key for its kid.
        iss is https://auth.example.edu and aud is the client id.
      • Load balancing across nodes: in one captured failing attempt, every request in the flow went to the same
        node, including the 401.
      • IP reputation: users on several different networks are all denied.
      • Configuration: we diffed applications, tenant, keys, identity providers, forms, form fields, lambdas,
        themes, email templates, webhooks and system configuration against a working instance. Apart from debug
        flags, email settings, the IdP endpoint and the webhook URL, the only difference is trustedProxyConfiguration
        (OnlyConfigured here, All on the working instances). Adding 127.0.0.1/32 and ::1/128 to the trusted list
        did not help.

      Where it works
      The same version and configuration, installed the same way (Kickstart plus the same API configuration), work
      on two other instances. Each is a single node, one licensed and one unlicensed, with trustPolicy All.

      Questions

      1. After the code exchange, what does the /account/login handler check that can return 401 "Access denied"
        and clear the account cookies?
      2. Does that check depend on the node's fusionauth-app.url (http://localhost:9011), on the forwarded host or
        scheme, or on communication between nodes (ours cannot reach each other)?
      3. Is there a logger we can raise to debug, or a setting, that would show the reason for this 401?

      Happy to run any diagnostics suggested here and post the results.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post