【发布时间】:2021-02-17 05:36:46
【问题描述】:
我正在尝试获取访问令牌,我可以通过登录但我无法获取访问令牌。我正在使用 angular-oauth2-oidc。以下是我的尝试:
constructor(private route: ActivatedRoute,
private authService: OAuthService) {
const authCodeFlowConfig: AuthConfig = {
issuer: '...',
redirectUri: 'http://localhost:4200',
clientId: 'secret',
tokenEndpoint:'..../access_token',
responseType: 'code',
scope: 'openid profile',
showDebugInformation: true,
disablePKCE: true,
nonceStateSeparator: '.',
};
this.authService.configure(authCodeFlowConfig);
this.authService.loadDiscoveryDocumentAndTryLogin().then(_ => {
console.log("Logged in");
if(!this.authService.hasValidAccessToken()){
setTimeout(() => {
this.authService.initCodeFlow();
}, 10000);
}
}).catch(err => {
console.log("Unable to login");
})
我错过了什么吗?
【问题讨论】:
-
我认为您应该在应用启动时致电
this.oauthService.initCodeFlow(); -
配置行之后?
-
是的,我相信是的。它应该使用返回的令牌
-
我编辑了,现在卡住了,它总是重定向
-
我编辑它。感谢您的帮助