使用Keycloak-js(版本:4.0.0)在Angular4中创建会话时,SSO无法正常工作
以下是重新创建
的步骤请求网址:
回复网址:
尝试了选项:
以下步骤适用
由于我可以单独登录这些应用程序,因此SSO可以在Grafana&詹金斯,我倾向于相信这个问题可能与Keycloak-Js适配器有关。
以下是我用来创建会话
的参数 const keycloakAuth: any = Keycloak({
url: environment.KEYCLOAK_URL,
realm: environment.KEYCLOAK_REALM,
clientId: environment.KEYCLOAK_CLIENTID,
'ssl-required': 'external',
'public-client': true,
});
答案 0 :(得分:0)
最终,我使用Angular-OIDC库(隐式流)https://github.com/manfredsteyer/angular-oauth2-oidc
实现了SSO功能 private configureWithNewConfigApi() {
// URL of the SPA to redirect the user to after login
this.oauthService.redirectUri = window.location.origin + "/index.html";
// set the scope for the permissions the client should request
this.oauthService.scope = "openid profile email";
// set to true, to receive also an id_token via OpenId Connect (OIDC) in addition to the
// OAuth2-based access_token
this.oauthService.oidc = true;
// Use setStorage to use sessionStorage or another implementation of the TS-type Storage
// instead of localStorage
this.oauthService.setStorage(sessionStorage);
this.oauthService.clientId = "<<clientId>>";
let url = 'https://<<keycloakhost>>:<<port>>/auth/realms/<<realmsname>>/.well-known/openid-configuration';
this.oauthService.loadDiscoveryDocument(url).then((doc) => {
// This method just tries to parse the token within the url when
// the auth-server redirects the user back to the web-app
// It dosn't initiate the login
this.oauthService.tryLogin({});
console.debug('discovery succeeded', doc);
});
感谢Jan Garag的suggestion