Keycloak SSO - 重定向太多
Keycloak SSO - too many redirects
在 Angular4 中使用 Keycloak-js(版本:4.0.0)创建会话时,SSO 不工作
以下是重新创建这个的步骤
- 将 Keycloak 与 Angular 4 应用程序集成(例如:https://github.com/mauriciovigolo/keycloak-angular or https://github.com/cternes/slackspace-angular2-spring-keycloak/tree/master/frontend)
- 当用户尝试登录时,他将被自动重定向到 Keycloak 登录页面
- 创建会话后,尝试使用 Keycloak 或 Jenkins 通过另一个应用程序(如 Grafana)登录
- 重定向太多(Keycloak 运行 在端口 8081 中,Grafana 在 3000 中)
Request url :
Response URL:
尝试过的选项:
- Angular4 & 詹金斯
- Angular4 & Grafana
而以下步骤有效
- 直接登录 Grafana 或 Jenkins 或 KeyCloak
- 然后登录 Angular 4 ,就可以了
由于我能够分别登录到这些应用程序中的每一个,并且 SSO 在 Grafana 和 Jenkins 之间工作,我倾向于认为问题可能出在 Keycloak-Js 适配器上。
以下是我用来创建会话的参数
const keycloakAuth: any = Keycloak({
url: environment.KEYCLOAK_URL,
realm: environment.KEYCLOAK_REALM,
clientId: environment.KEYCLOAK_CLIENTID,
'ssl-required': 'external',
'public-client': true,
});
最终,我使用 Angular-OIDC 库(隐式流)实现了 SSO 功能 https://github.com/manfredsteyer/angular-oauth2-oidc
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 的
在 Angular4 中使用 Keycloak-js(版本:4.0.0)创建会话时,SSO 不工作
以下是重新创建这个的步骤
- 将 Keycloak 与 Angular 4 应用程序集成(例如:https://github.com/mauriciovigolo/keycloak-angular or https://github.com/cternes/slackspace-angular2-spring-keycloak/tree/master/frontend)
- 当用户尝试登录时,他将被自动重定向到 Keycloak 登录页面
- 创建会话后,尝试使用 Keycloak 或 Jenkins 通过另一个应用程序(如 Grafana)登录
- 重定向太多(Keycloak 运行 在端口 8081 中,Grafana 在 3000 中)
Request url :
Response URL:
尝试过的选项:
- Angular4 & 詹金斯
- Angular4 & Grafana
而以下步骤有效
- 直接登录 Grafana 或 Jenkins 或 KeyCloak
- 然后登录 Angular 4 ,就可以了
由于我能够分别登录到这些应用程序中的每一个,并且 SSO 在 Grafana 和 Jenkins 之间工作,我倾向于认为问题可能出在 Keycloak-Js 适配器上。
以下是我用来创建会话的参数
const keycloakAuth: any = Keycloak({
url: environment.KEYCLOAK_URL,
realm: environment.KEYCLOAK_REALM,
clientId: environment.KEYCLOAK_CLIENTID,
'ssl-required': 'external',
'public-client': true,
});
最终,我使用 Angular-OIDC 库(隐式流)实现了 SSO 功能 https://github.com/manfredsteyer/angular-oauth2-oidc
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 的