我正在尝试遵循documentation 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=,没有对服务的其他更改,似乎所有内容都已登录。我希望自己做了一些愚蠢的事情,或者误解了正在发生的事情,但任何建议都会有所帮助。
发布于 2020-05-17 20:28:17
事实证明我做得不对。
我没有像我应该做的那样在我的构造函数中调用负载发现文档。
如果页面重新加载,我没有检查令牌的发现文档,因此它是无效的。
发布于 2021-05-20 00:54:15
我也有同样的问题,我解决了:
文件config.ts:
import { AuthConfig } from 'angular-oauth2-oidc';
export const authCodeFlowConfig: AuthConfig = {
issuer: 'https://accounts.----/auth/realms/---',
redirectUri: window.location.origin + '/login',
clientId: 'my-project',
responseType: 'code',
scope: 'openid profile email offline_access',
showDebugInformation: true,
};文件login.ts:
ngOnInit(): void {
this.oauthService.configure(authCodeFlowConfig);
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.setupAutomaticSilentRefresh();
this.oauthService.loadDiscoveryDocumentAndTryLogin().then(() => {
if (this.oauthService.hasValidAccessToken()) {
// Load UserProfile to get the additional claims
this.oauthService.loadUserProfile();
this.router.navigateByUrl('/');
} else {
this.oauthService.initCodeFlow();
}
});
}https://stackoverflow.com/questions/61676890
复制相似问题