【问题标题】:auth0 http interceptor StaticInjectorErrorauth0 http拦截器StaticInjectorError
【发布时间】:2021-02-22 01:24:30
【问题描述】:

按照 auth0 文档中有关在 Angular 应用程序中设置 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,
    HttpClientModule,
    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

【问题讨论】:

  • 你使用的是什么版本的角度?
  • @Tejeshree 用它更新了问题

标签: angular auth0 httpinterceptor


【解决方案1】:

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

【讨论】:

  • 不幸的是,问题仍然存在。有什么其他的想法吗?立即查看文档
  • 问题仍然是 NullInjectorError: No provider for AuthClientConfig!?你能提供更多信息吗
  • 我能够解决的那个问题。所以不,你在哪里,谢谢你
  • @ChristopherJakob 你是怎么做到的
猜你喜欢
  • 2023-03-13
  • 2014-05-29
  • 1970-01-01
  • 1970-01-01
  • 2017-11-07
  • 2018-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多