我有一个使用 Open Id Connect 对 Windows ADFS 2016 进行身份验证的 Angular 应用程序。该应用程序通过隐式流检索访问令牌和id 令牌,并且工作正常。当我尝试使用文档中所述的silentRefresh() 刷新令牌时出现问题: https ://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/refreshing-a-token.html
这是配置:
const authConfig: AuthConfig = {
issuer: <address to adfs>,
redirectUri: window.location.origin+'/index.html',
silentRefreshRedirectUri: window.location.origin + '/silent-refresh.html',
clientId: '<client-id>',
scope: 'openid email profile',
logoutUrl: window.location.origin+'/logout',
tokenEndpoint: '<adfs address>/adfs/oauth2/token',
loginUrl: '<adfs address>/adfs/oauth2/authorize',
strictDiscoveryDocumentValidation: false,
skipIssuerCheck: true,
oidc: true
};
OAuth 配置
private configureOauth(){
this.oauthService.configure(authConfig);
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.setStorage(sessionStorage);
this.oauthService.setupAutomaticSilentRefresh({});
this.oauthService.tryLogin({onTokenReceived: context => {
// tslint:disable-next-line:no-console
console.debug('logged in');
// tslint:disable-next-line:no-console
console.info( this.oauthService.getAccessToken() );
// tslint:disable-next-line:no-console
console.info( this.oauthService.getIdToken() );
}});
}
刷新我调用的令牌
public triggerSilentRefresh(){
this
.oauthService
.silentRefresh()
.then(info => console.debug('refresh ok', info))
.catch(err => console.error('refresh error', err));
}
但我收到以下错误:
core.js:6014 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'responseType' of null
TypeError: Cannot read property 'responseType' of null
at OAuthService.<anonymous> (angular-oauth2-oidc.js:1826)
at Generator.next (<anonymous>)
这是由 createLoginUrl 抛出的,因为AuthConfig为空。
createLoginUrl(state = '', loginHint = '', customRedirectUri = '', noPrompt = false, params = {}) {
return __awaiter(this, void 0, void 0, function* () {
/** @type {?} */
const that = this;
/** @type {?} */
let redirectUri;
if (customRedirectUri) {
redirectUri = customRedirectUri;
}
else {
redirectUri = this.redirectUri;
}
/** @type {?} */
const nonce = yield this.createAndSaveNonce();
if (state) {
state = nonce + this.config.nonceStateSeparator + state;
}
else {
state = nonce;
}
if (!this.requestAccessToken && !this.oidc) {
throw new Error('Either requestAccessToken or oidc or both must be true');
}
if (this.config.responseType) { //HERE config is null
this.responseType = this.config.responseType;
我不明白如果它已被初始化并且我成功地检索了我的访问令牌,它怎么可能为 null。是我做错了什么还是我错过了配置?