Skip to content

Using detailedResponse breaks AuthHttpInterceptor #731

@cgearing

Description

@cgearing

Checklist

Description

Hi there,

It looks like using the AuthHttpInterceptor along with detailedResponse: true on the httpInterceptor results in the interceptor attempting to send the full detailedResponse object as the Authorization header, rather than the access token in the response.

I've managed to recreate this with the sample app by filling in the relevant details, and adjusting the config in environment.ts to:

export const environment = {
  production: false,
  auth: {
    domain,
    clientId,
    authorizationParams: {
      ...(audience && audience !== '{yourApiIdentifier}' ? { audience } : null),
      redirect_uri: window.location.origin,
    },
    errorPath,
  },
  httpInterceptor: {
    allowedList: [
      {
        uri: `${apiUri}/*`,
        tokenOptions: {
          detailedResponse: true
        }
      }
    ],
  },
};

Trying to ping the external API results in a header of Authorization: Bearer [object Object].

It looks like the problem is in the AuthState class in setAccessToken

public setAccessToken(accessToken: string): void {
.

The input to this could be the access token or the detailed response object from the Auth0Client.getTokenSilently. I'm not sure if you'd expect getTokenSilently to return the full detailed response or just the access token.

Reproduction

Step 1: Clone the sample repo.
Step 2: Add the relevant Auth0 config.
Step 3: Add detailedResponse to the tokenOptions on the httpInterceptor config.
Step 4: Load the app and ping the external API - you'll get a 401 since we aren't attaching the access token.

Additional context

No response

auth0-angular version

2.2.3

Angular version

20

Which browsers have you tested in?

Chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis points to a verified bug in the code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions