最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Auth0 interceptor not attaching token for standalone Angular - Stack Overflow

programmeradmin1浏览0评论

Angular v19, configuration:

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({ eventCoalescing: true }),
    provideRouter(routes),
    provideAnimationsAsync(),
    provideAuth0({
      domain: 'xxx',
      clientId: 'yyy',
      authorizationParams: {
        audience: 'aaa',
        redirect_uri: window.location.origin,
      },
    }),
    provideHttpClient(
      withInterceptors([authHttpInterceptorFn])
    )
  ]
};

Simple calling:

this.auth.isAuthenticated$.subscribe((isAuthenticated) => {
  if (isAuthenticated) {
    this.http.get('/api/v1/tests').subscribe((data) => {
      console.log(data);
    });
  }
});

Token is never attached to Authorization header. When I try to get token by auth.getAccessTokenSilently() it works and I get the token.

I could probably build my own interceptor but I would like to use the one made by Auth0.

Angular v19, configuration:

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({ eventCoalescing: true }),
    provideRouter(routes),
    provideAnimationsAsync(),
    provideAuth0({
      domain: 'xxx',
      clientId: 'yyy',
      authorizationParams: {
        audience: 'aaa',
        redirect_uri: window.location.origin,
      },
    }),
    provideHttpClient(
      withInterceptors([authHttpInterceptorFn])
    )
  ]
};

Simple calling:

this.auth.isAuthenticated$.subscribe((isAuthenticated) => {
  if (isAuthenticated) {
    this.http.get('/api/v1/tests').subscribe((data) => {
      console.log(data);
    });
  }
});

Token is never attached to Authorization header. When I try to get token by auth.getAccessTokenSilently() it works and I get the token.

I could probably build my own interceptor but I would like to use the one made by Auth0.

Share Improve this question asked Mar 14 at 15:52 EdWoodEdWood 9273 gold badges20 silver badges40 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1
export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({ eventCoalescing: true }),
    provideRouter(routes),
    provideAnimationsAsync(),
    provideAuth0({
      domain: 'xxx',
      clientId: 'yyy',
      authorizationParams: {
        audience: 'aaa',
        redirect_uri: window.location.origin,
      },
      httpInterceptor: {
        allowedList: [
          '/api/*'
        ],
      }
    }),
    provideHttpClient(
      withInterceptors([authHttpInterceptorFn])
    )
  ]
};

Solved. You have to provide two things:

  • provideHttpClient with Interceptor
  • provideAuth0 with HttpInterceptor config
发布评论

评论列表(0)

  1. 暂无评论