我正在尝试配置我的Angular应用程序以使用OAuth2库( angular-oauth2-oidc ) .
在auth.service.ts文件中,我的OAuthService配置为:
this.oauthService.loginUrl = 'https://serverdomain.com/authorization/';
this.oauthService.redirectUri = 'http://localhost:4200/auth';
this.oauthService.clientId = '1111-2222-3333-4444-5555-6666-7777';
this.oauthService.setStorage(localStorage);
this.oauthService.requireHttps = false;
this.oauthService.responseType = 'token';
this.oauthService.tokenEndpoint = 'https://serverdomain.com/token/';
this.oauthService.oidc = false;
this.oauthService.issuer = 'https://serverdomain.com/authorization/';
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.requestAccessToken = true;
this.oauthService.showDebugInformation = true;
this.oauthService.scope = 'openid profile email';
this.oauthService.tryLogin({
onTokenReceived: context => {
console.log(context);
}
});
obtainAccessToken() {
this.oauthService.initImplicitFlow();
}
isLoggedIn() {
if (this.oauthService.getAccessToken() === null) {
return false;
}
return true;
}
logout() {
this.oauthService.logOut();
location.reload();
}
logAuthData() {
console.log(this.oauthService.hasValidAccessToken());
}
在我的home组件中,我添加了一个按钮来触发隐式流并获取访问令牌 .
初始化隐式流后,应用程序会重定向到我登录的提供程序的正确登录页面,并重定向到我的OAuth配置的redirectUri .
但
如果我尝试获取状态,例如我调用isLoggedIn方法,我总是假的 . 此外,hasValidAccessToken()还有一个错误的返回 .
任何人都可以展示如何正确配置角度5和oauth2?我还需要存储我给定的访问令牌,以便在我的rest方法中使用它们来获取数据 .