【问题标题】:Where to set AuthConfigConsts for the angular2-jwt?在哪里为 angular2-jwt 设置 AuthConfigConsts?
【发布时间】:2018-03-16 05:30:57
【问题描述】:

我正在使用angular2-jwt 进行身份验证。我需要将默认令牌名称从token 更改为customer

我知道我需要更改AuthConfigConsts 中的DEFAULT_TOKEN_NAME 属性。但我不确定我应该在哪里以及如何做。

【问题讨论】:

    标签: angular auth0 angular2-jwt


    【解决方案1】:

    您可以在创建将提供给NgModule 的工厂时执行此操作:

    // Provider
    
    /**
     * Factory for JWT Authentication.
     *
     * @param http
     * @param options
     * @returns {AuthHttp}
     */
    export function authHttpServiceFactory(http: Http, options: RequestOptions) {
      return new AuthHttp(new AuthConfig({
        tokenName: '<yourTokenName>',
      }), http, options);
    }
    
    
    // @NgModule provider:
    
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [Http, RequestOptions]
    },
    

    AuthConfig's constructor 使用Object.assign 设置那些属性。

    【讨论】:

      猜你喜欢
      • 2021-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-02
      • 2020-03-07
      • 2016-12-25
      • 1970-01-01
      • 2019-01-05
      相关资源
      最近更新 更多