我正在尝试遵循文档https://github.com/manfredsteyer/angular-oauth2-oidc上的指南。
我的服务构造函数中有以下配置:
authCodeFlowConfig: AuthConfig = {
issuer: 'https://demo.identityserver.io',
redirectUri: window.location.origin + '/home',
clientId: 'spa',
responseType: 'code',
scope: 'openid profile email offline_access api',
showDebugInformation: true
};
this.oauthService.configure(this.authCodeFlowConfig);
(我也尝试过使用 index.html 的重定向 url,但这似乎没有什么不同)
登录似乎工作得很好,我重定向到页面登录并重定向到主页:
this.oauthService.loadDiscoveryDocumentAndTryLogin().then((response) => {
if (!this.oauthService.hasValidIdToken() || !this.oauthService.hasValidAccessToken()) {
this.oauthService.initCodeFlow();
}
}).catch((err) => {
console.log(err);
});
但是以下仍然返回 false、false、null:
const claims = this.oauthService.getIdentityClaims();
console.log(this.oauthService.hasValidIdToken());
console.log(this.oauthService.hasValidAccessToken());
console.log(claims);
我的 url 中有一个 code= 对服务没有其他更改,而且一切似乎都让我登录了。我希望做一些愚蠢的事情或误解了正在发生的事情,但任何建议都会有所帮助。