【发布时间】:2018-03-16 05:30:57
【问题描述】:
我正在使用angular2-jwt 进行身份验证。我需要将默认令牌名称从token 更改为customer。
我知道我需要更改AuthConfigConsts 中的DEFAULT_TOKEN_NAME 属性。但我不确定我应该在哪里以及如何做。
【问题讨论】:
标签: angular auth0 angular2-jwt
我正在使用angular2-jwt 进行身份验证。我需要将默认令牌名称从token 更改为customer。
我知道我需要更改AuthConfigConsts 中的DEFAULT_TOKEN_NAME 属性。但我不确定我应该在哪里以及如何做。
【问题讨论】:
标签: angular auth0 angular2-jwt
您可以在创建将提供给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 设置那些属性。
【讨论】: