Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 多认证方案_Angular_Circular Dependency - Fatal编程技术网

Angular 多认证方案

Angular 多认证方案,angular,circular-dependency,Angular,Circular Dependency,我们希望在Angular应用程序中支持两种身份验证方案: oauth2,针对远程IDP 针对自己的服务器进行密码身份验证 应在构建时选择认证模式 我定义了两个模块:iaauth和otdsauth(使用angular-oauth2-oidc),并在app.module.ts中有条件地导入它们 environment.authMechanism === 'password' ? IaAuthenticationModule.forRoot({}) : OTDSAuthModule.forRoot

我们希望在Angular应用程序中支持两种身份验证方案:

  • oauth2,针对远程IDP
  • 针对自己的服务器进行密码身份验证 应在构建时选择认证模式
我定义了两个模块:iaauth和otdsauth(使用angular-oauth2-oidc),并在app.module.ts中有条件地导入它们

environment.authMechanism === 'password' ? IaAuthenticationModule.forRoot({}) : OTDSAuthModule.forRoot(),
并使用useFactory声明抽象服务:

@Injectable({
  providedIn: 'root', 
  useFactory: (http: HttpClient, router: Router, logger: NGXLogger) : any => {
      return new IaAuthService(http, router, logger)
  }
})
导出抽象类AuthService{ ... }

但出于某种原因,我

Uncaught ReferenceError: Cannot access 'AuthService' before initialization
at Module.AuthService (auth.service.ts:3)
at Module../src/ia-auth/ia-auth.service.ts (ia-auth.service.ts:13)
at __webpack_require__ (bootstrap:84)
at Module../src/app/auth.service.ts (auth.service.ts:3)
启动应用程序时。我还收到循环依赖的警告(在堆栈跟踪中也可见)

IaAuthService的定义如下:

export class IaAuthService extends AuthService {
  constructor(
    private http: HttpClient, 
    private router: Router, 
    private log: NGXLogger) {
  super()
  
}
  • 这是实现选择性身份验证的正确方法吗?(模式在构建期间设置)
  • 用抽象服务避免循环依赖的正确方法是什么