mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
[MNT-22836] - support PKCE code flow in SSO (#8884)
* [MNT-22836] - support PKCE code flow in SSO
This commit is contained in:
@@ -20,7 +20,8 @@
|
|||||||
"clientId": "alfresco",
|
"clientId": "alfresco",
|
||||||
"scope": "openid profile email",
|
"scope": "openid profile email",
|
||||||
"secret": "",
|
"secret": "",
|
||||||
"implicitFlow": true,
|
"implicitFlow": false,
|
||||||
|
"codeFlow": true,
|
||||||
"silentLogin": true,
|
"silentLogin": true,
|
||||||
"redirectSilentIframeUri": "{protocol}//{hostname}{:port}/assets/silent-refresh.html",
|
"redirectSilentIframeUri": "{protocol}//{hostname}{:port}/assets/silent-refresh.html",
|
||||||
"redirectUri": "/",
|
"redirectUri": "/",
|
||||||
|
@@ -33,6 +33,11 @@ if [ -n "${APP_CONFIG_OAUTH2_IMPLICIT_FLOW}" ]; then
|
|||||||
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
|
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "${APP_CONFIG_OAUTH2_CODE_FLOW}" ]; then
|
||||||
|
sed -e "s/\"codeFlow\": [^,]*/\"codeFlow\": ${APP_CONFIG_OAUTH2_CODE_FLOW}/g" \
|
||||||
|
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "${APP_CONFIG_OAUTH2_SILENT_LOGIN}" ]; then
|
if [ -n "${APP_CONFIG_OAUTH2_SILENT_LOGIN}" ]; then
|
||||||
sed -e "s/\"silentLogin\": [^,]*/\"silentLogin\": ${APP_CONFIG_OAUTH2_SILENT_LOGIN}/g" \
|
sed -e "s/\"silentLogin\": [^,]*/\"silentLogin\": ${APP_CONFIG_OAUTH2_SILENT_LOGIN}/g" \
|
||||||
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
|
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
|
||||||
|
@@ -14,6 +14,7 @@ docker run --rm -it \
|
|||||||
--env APP_CONFIG_OAUTH2_HOST=$APP_CONFIG_OAUTH2_HOST \
|
--env APP_CONFIG_OAUTH2_HOST=$APP_CONFIG_OAUTH2_HOST \
|
||||||
--env APP_CONFIG_OAUTH2_CLIENTID=$APP_CONFIG_OAUTH2_CLIENTID \
|
--env APP_CONFIG_OAUTH2_CLIENTID=$APP_CONFIG_OAUTH2_CLIENTID \
|
||||||
--env APP_CONFIG_OAUTH2_IMPLICIT_FLOW=$APP_CONFIG_OAUTH2_IMPLICIT_FLOW \
|
--env APP_CONFIG_OAUTH2_IMPLICIT_FLOW=$APP_CONFIG_OAUTH2_IMPLICIT_FLOW \
|
||||||
|
--env APP_CONFIG_OAUTH2_IMPLICIT_FLOW=$APP_CONFIG_OAUTH2_CODE_FLOW \
|
||||||
--env APP_CONFIG_OAUTH2_SILENT_LOGIN=$APP_CONFIG_OAUTH2_SILENT_LOGIN \
|
--env APP_CONFIG_OAUTH2_SILENT_LOGIN=$APP_CONFIG_OAUTH2_SILENT_LOGIN \
|
||||||
--env APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI=$APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI \
|
--env APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI=$APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI \
|
||||||
--env APP_CONFIG_BPM_HOST=$APP_CONFIG_BPM_HOST \
|
--env APP_CONFIG_BPM_HOST=$APP_CONFIG_BPM_HOST \
|
||||||
|
@@ -149,7 +149,7 @@ describe('AuthConfigService', () => {
|
|||||||
const expectedConfig = {
|
const expectedConfig = {
|
||||||
oidc: true,
|
oidc: true,
|
||||||
issuer: 'http://localhost:3000/auth/realms/alfresco',
|
issuer: 'http://localhost:3000/auth/realms/alfresco',
|
||||||
redirectUri: 'http://localhost:3000/#/view/authentication-confirmation',
|
redirectUri: 'http://localhost:3000/#/view/authentication-confirmation/?',
|
||||||
silentRefreshRedirectUri: 'http://localhost:3000/assets/silent-refresh.html',
|
silentRefreshRedirectUri: 'http://localhost:3000/assets/silent-refresh.html',
|
||||||
postLogoutRedirectUri: 'http://localhost:3000/#/logout',
|
postLogoutRedirectUri: 'http://localhost:3000/#/logout',
|
||||||
clientId: 'fakeClientId',
|
clientId: 'fakeClientId',
|
||||||
|
@@ -19,7 +19,7 @@ import { Inject, Injectable } from '@angular/core';
|
|||||||
import { AuthConfig } from 'angular-oauth2-oidc';
|
import { AuthConfig } from 'angular-oauth2-oidc';
|
||||||
import { take } from 'rxjs/operators';
|
import { take } from 'rxjs/operators';
|
||||||
import { AppConfigService } from '../../app-config/app-config.service';
|
import { AppConfigService } from '../../app-config/app-config.service';
|
||||||
import { AuthModuleConfig, AUTH_MODULE_CONFIG } from './auth-config';
|
import { AUTH_MODULE_CONFIG, AuthModuleConfig } from './auth-config';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create auth configuration factory
|
* Create auth configuration factory
|
||||||
@@ -84,7 +84,7 @@ export class AuthConfigService {
|
|||||||
|
|
||||||
// handle issue from the OIDC library with hashStrategy and implicitFlow, with would append &state to the url with would lead to error
|
// handle issue from the OIDC library with hashStrategy and implicitFlow, with would append &state to the url with would lead to error
|
||||||
// `cannot match any routes`, and displaying the wildcard ** error page
|
// `cannot match any routes`, and displaying the wildcard ** error page
|
||||||
return oauth2.implicitFlow && useHash ? `${redirectUri}/?` : redirectUri;
|
return (oauth2.codeFlow || oauth2.implicitFlow) && useHash ? `${redirectUri}/?` : redirectUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getLocationOrigin() {
|
private getLocationOrigin() {
|
||||||
|
@@ -44,7 +44,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="!implicitFlow">
|
<div *ngIf="!ssoLogin">
|
||||||
|
|
||||||
<!--USERNAME FIELD-->
|
<!--USERNAME FIELD-->
|
||||||
<div
|
<div
|
||||||
@@ -169,7 +169,7 @@
|
|||||||
</mat-checkbox>
|
</mat-checkbox>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="implicitFlow">
|
<div *ngIf="ssoLogin">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
(click)="implicitLogin()"
|
(click)="implicitLogin()"
|
||||||
|
@@ -721,7 +721,7 @@ describe('LoginComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
expect(component.implicitFlow).toBe(false);
|
expect(component.ssoLogin).toBe(false);
|
||||||
expect(component.redirectToImplicitLogin).toHaveBeenCalled();
|
expect(component.redirectToImplicitLogin).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -734,7 +734,7 @@ describe('LoginComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
expect(component.implicitFlow).toBe(true);
|
expect(component.ssoLogin).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
@@ -111,7 +111,7 @@ export class LoginComponent implements OnInit, OnDestroy {
|
|||||||
@Output()
|
@Output()
|
||||||
executeSubmit = new EventEmitter<LoginSubmitEvent>();
|
executeSubmit = new EventEmitter<LoginSubmitEvent>();
|
||||||
|
|
||||||
implicitFlow: boolean = false;
|
ssoLogin: boolean = false;
|
||||||
|
|
||||||
form: UntypedFormGroup;
|
form: UntypedFormGroup;
|
||||||
isError: boolean = false;
|
isError: boolean = false;
|
||||||
@@ -155,8 +155,8 @@ export class LoginComponent implements OnInit, OnDestroy {
|
|||||||
const oauth = this.appConfig.oauth2;
|
const oauth = this.appConfig.oauth2;
|
||||||
if (oauth?.silentLogin) {
|
if (oauth?.silentLogin) {
|
||||||
this.redirectToImplicitLogin();
|
this.redirectToImplicitLogin();
|
||||||
} else if (oauth?.implicitFlow) {
|
} else if (oauth?.implicitFlow || oauth?.codeFlow) {
|
||||||
this.implicitFlow = true;
|
this.ssoLogin = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user