我在我的angular 8项目中使用8.0.4的发布版本和授权码流:
下面是我拥有的代码
this.oauthService.configure(authConfig);
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService
.loadDiscoveryDocument()
.then(() => this.oauthService.tryLogin()) ---> [1]
.then(() => {
if (this.oauthService.hasValidAccessToken()) {
return Promise.resolve();
}else{
this.oauthService.initCodeFlow() ---> [2]
}
});
}最初,当用户未在代码中登录时,代码2将用户重定向到登录页面。
一旦用户提供用户名/密码并单击登录,身份提供者将重定向回应用程序,并在querystring中使用" code“,也就是说,我期望代码为1的代码使用code登录用户(通过将其兑换为令牌)。
相反,tryLogin()方法不起作用,用户再次被重定向到无限循环中的授权端点。
请帮助我理解,这里出了什么问题。
另外,这个例子:https://github.com/jeroenheijmans/sample-angular-oauth2-oidc-with-auth-guards/是否适用于版本8?
发布于 2021-05-11 21:36:36
此函数可用于判断您是否已经登录:
public isLoggedIn(): Promise<boolean> {
return this.oauthService.loadDiscoveryDocument('<your discoveryDocumentUrl>').then(() => {
return this.oauthService.silentRefresh().then(() => true).catch(() => false);
});
}https://stackoverflow.com/questions/62779970
复制相似问题