auth0 http拦截器StaticInjectorError

问题描述

遵循auth0文档中有关在有角度的应用程序中设置auth0服务后调用api的文档

https://auth0.com/docs/quickstart/spa/angular/02-calling-an-api

并在更详细的示例的指导下创建httpinterceptor:

https://github.com/auth0/auth0-angular#configure-authhttpinterceptor-to-attach-access-tokens

我有我的拦截器:

imports: [
    browserModule,RouterModule,FontAwesomeModule,RecaptchaV3Module,FormsModule,HttpClientModule,AppRoutingModule,AuthModule.forRoot({
      domain: environment.auth0_domain,clientId: environment.auth0_client_id,redirectUri: window.location.origin,// The AuthHttpInterceptor configuration
      httpInterceptor: {
        allowedList: [
          'example.com/*','example2.com/*'
        ],},})

  ],providers: [Addemailtomarketinglistservice,{ provide: HTTP_INTERCEPTORS,useClass: AuthHttpInterceptor,multi: true },{provide: RECAPTCHA_V3_SITE_KEY,useValue: environment.recaptcha_site_key },Googlerecaptchaservice,AuthService,HidecomponentService,S3Service],bootstrap: [AppComponent]

进行任何api调用时都会收到以下错误

ERROR NullInjectorError: StaticInjectorError(AppModule)[InjectionToken HTTP_INTERCEPTORS -> AuthClientConfig]: 
  StaticInjectorError(Platform: core)[InjectionToken HTTP_INTERCEPTORS -> AuthClientConfig]: 
    NullInjectorError: No provider for AuthClientConfig!

这里还有一些导入,以查看我正在使用的库

import { AuthHttpInterceptor,AuthModule } from '@auth0/auth0-angular';

import {HttpClientModule,HTTP_INTERCEPTORS} from '@angular/common/http';

这是我的角度版本输出

 / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__,|\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 8.3.29
Node: 12.14.1
OS: darwin x64
Angular: 8.2.14
... animations,common,compiler,compiler-cli,core,forms
... language-service,platform-browser,platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.29
@angular-devkit/build-angular     0.803.29
@angular-devkit/build-optimizer   0.803.29
@angular-devkit/build-webpack     0.803.29
@angular-devkit/core              8.3.29
@angular-devkit/schematics        8.3.29
@angular/cli                      8.3.29
@ngtools/webpack                  8.3.29
@schematics/angular               8.3.29
@schematics/update                0.803.29
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2

解决方法

Auth0 Angular SDK-用于将Auth0集成到Angular 9+应用程序中的库。请更新您的angular。