【问题标题】:StaticInjectorError(AppModule)[MsalGuard -> Router]StaticInjectorError(AppModule)[MsalGuard -> 路由器]
【发布时间】:2019-11-21 18:57:29
【问题描述】:

我已经使用 ionic 构建了一个 webapp。我正在尝试将 MSALModule 导入我的应用程序。根据我在网上找到的教程等,您必须在应用模块中添加以下内容:

MsalModule.forRoot({
      clientID: OAuthSettings.appId
    }),

当前,当我尝试转到使用它的页面时,它给了我以下错误。

We have a generic Error:  Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[MsalGuard -> Router]: 
  StaticInjectorError(Platform: core)[MsalGuard -> Router]: 
    NullInjectorError: No provider for Router!
Error: StaticInjectorError(AppModule)[MsalGuard -> Router]: 
  StaticInjectorError(Platform: core)[MsalGuard -> Router]: 
    NullInjectorError: No provider for Router!
    at _NullInjector.get (core.js:994)
    at resolveToken (core.js:1292)
    at tryResolveToken (core.js:1234)
    at StaticInjector.get (core.js:1102)
    at resolveToken (core.js:1292)
    at tryResolveToken (core.js:1234)
    at StaticInjector.get (core.js:1102)
    at resolveNgModuleDep (core.js:10847)
    at _createClass (core.js:10888)
    at _createProviderInstance$1 (core.js:10858)
    at c (polyfills.js:3)
    at Object.reject (polyfills.js:3)
    at NavControllerBase._fireError (nav-controller-base.js:223)
    at NavControllerBase._failed (nav-controller-base.js:216)
    at nav-controller-base.js:263
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (core.js:4733)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3

我没有导入路由模块,因为我没有在应用程序中使用角度(或离子)路由。有没有办法在不使用路由的情况下摆脱这个错误?即我可以在我的应用程序中不设置路由的情况下使用 MSAL 吗?

【问题讨论】:

  • 你能把'Router'添加到服务数组中试试吗?
  • @ppgowda4 你是什么意思?
  • MSAL 需要路由模块。你需要导入那个
  • @ppgowda4 我试图使用 msal,因为我尝试通过向授权端点发送 get 请求(图形 api 的隐式流)来获取访问令牌,但它返回了一个无效的令牌。你知道这是为什么吗?
  • 如果有帮助可以查看这个问题stackoverflow.com/questions/52769462/…

标签: angular microsoft-graph-api ionic4 angular-router msal


【解决方案1】:

我看到您有导入声明...您是否添加到提供者部分:

{ 提供:HTTP_INTERCEPTORS,useClass:MsalInterceptor,multi:true }

我的理解是,这不是绝对必要的,只要您有自己开发的自定义提供程序即可。但是,如果这不存在,您需要在您的提供者部分中有它。

【讨论】:

    猜你喜欢
    • 2019-10-25
    • 2019-06-10
    • 1970-01-01
    • 2020-06-13
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    相关资源
    最近更新 更多