diff --git a/CHANGELOG.md b/CHANGELOG.md index 064000c9b..c9aaa41a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Add support for OAuth Pushed authorisation requests (PAR) - [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/978) - Add Pushed authorisation requests (PAR) example +- Added OAuth Pushed authorisation requests (PAR) template using schematics ### 2021-02-13 Version 11.5.1 diff --git a/projects/angular-auth-oidc-client/src/lib/check-auth.service.spec.ts b/projects/angular-auth-oidc-client/src/lib/check-auth.service.spec.ts index 4e32ce702..d48294424 100644 --- a/projects/angular-auth-oidc-client/src/lib/check-auth.service.spec.ts +++ b/projects/angular-auth-oidc-client/src/lib/check-auth.service.spec.ts @@ -19,6 +19,7 @@ import { SilentRenewServiceMock } from './iframe/silent-renew.service-mock'; import { LoggerService } from './logging/logger.service'; import { LoggerServiceMock } from './logging/logger.service-mock'; import { PopUpService } from './login/popup/popup.service'; +import { PopUpServiceMock } from './login/popup/popup.service-mock'; import { UserService } from './userData/user-service'; describe('CheckAuthService', () => { @@ -31,6 +32,7 @@ describe('CheckAuthService', () => { let silentRenewService: SilentRenewService; let periodicallyTokenCheckService: PeriodicallyTokenCheckService; let refreshSessionService: RefreshSessionService; + let popUpService: PopUpService; beforeEach(() => { TestBed.configureTestingModule({ @@ -45,7 +47,7 @@ describe('CheckAuthService', () => { { provide: CallbackService, useClass: CallbackServiceMock }, { provide: RefreshSessionService, useClass: RefreshSessionServiceMock }, { provide: PeriodicallyTokenCheckService, useClass: PeriodicallyTokenCheckServiceMock }, - PopUpService, + { provide: PopUpService, useClass: PopUpServiceMock }, ], }); }); @@ -60,6 +62,7 @@ describe('CheckAuthService', () => { callBackService = TestBed.inject(CallbackService); silentRenewService = TestBed.inject(SilentRenewService); periodicallyTokenCheckService = TestBed.inject(PeriodicallyTokenCheckService); + popUpService = TestBed.inject(PopUpService); }); it('should create', () => { @@ -75,6 +78,20 @@ describe('CheckAuthService', () => { }) ); + it( + 'returns null and sendMessageToMainWindow if currently in a popup', + waitForAsync(() => { + spyOn(configurationProvider, 'hasValidConfig').and.returnValue(true); + spyOnProperty(configurationProvider, 'openIDConfiguration', 'get').and.returnValue('stsServer'); + spyOn(popUpService, 'isCurrentlyInPopup').and.returnValue(true); + const popupSpy = spyOn(popUpService, 'sendMessageToMainWindow'); + checkAuthService.checkAuth().subscribe((result) => { + expect(result).toBeNull(); + expect(popupSpy).toHaveBeenCalled(); + }); + }) + ); + it( 'returns false in case handleCallbackAndFireEvents throws an error', waitForAsync(() => { diff --git a/projects/angular-auth-oidc-client/src/lib/login/popup/popup.service-mock.ts b/projects/angular-auth-oidc-client/src/lib/login/popup/popup.service-mock.ts index 8fddf454b..62da0c95e 100644 --- a/projects/angular-auth-oidc-client/src/lib/login/popup/popup.service-mock.ts +++ b/projects/angular-auth-oidc-client/src/lib/login/popup/popup.service-mock.ts @@ -12,6 +12,10 @@ export class PopUpServiceMock { return true; } + isCurrentlyInPopup(): boolean { + return false; + } + openPopUp(url: string, popupOptions?: PopupOptions) {} sendMessageToMainWindow(url: string) {} diff --git a/projects/schematics/src/ng-add/actions/configs.ts b/projects/schematics/src/ng-add/actions/configs.ts index fc8ce503d..b54087a82 100644 --- a/projects/schematics/src/ng-add/actions/configs.ts +++ b/projects/schematics/src/ng-add/actions/configs.ts @@ -50,6 +50,22 @@ const AZURE_AD_REFRESH_TOKENS = `{ autoUserinfo: false, }`; + const OAUTH_PAR = `{ + stsServer: '', + redirectUrl: window.location.origin, + postLogoutRedirectUri: window.location.origin, + clientId: 'please-enter-clientId', + usePushedAuthorisationRequests: true, + scope: 'please-enter-scopes', // 'openid profile offline_access ' + your scopes + responseType: 'code', + silentRenew: true, + useRefreshToken: true, + ignoreNonceAfterRefresh: true, + customParams: { + prompt: 'consent', // login, consent + }, + }`; + const AUTH_0 = `{ stsServer: '', redirectUrl: window.location.origin, @@ -71,4 +87,4 @@ const OIDC_PLAIN = `{ renewTimeBeforeTokenExpiresInSeconds: 10, }`; -export { DEFAULT_CONFIG, AZURE_AD_SILENT_RENEW, IFRAME_SILENT_RENEW, AZURE_AD_REFRESH_TOKENS, OIDC_PLAIN, AUTH_0 }; +export { DEFAULT_CONFIG, AZURE_AD_SILENT_RENEW, IFRAME_SILENT_RENEW, AZURE_AD_REFRESH_TOKENS, OIDC_PLAIN, AUTH_0, OAUTH_PAR }; diff --git a/projects/schematics/src/ng-add/actions/copy-module-file.ts b/projects/schematics/src/ng-add/actions/copy-module-file.ts index bf84b4a84..e09d48f85 100644 --- a/projects/schematics/src/ng-add/actions/copy-module-file.ts +++ b/projects/schematics/src/ng-add/actions/copy-module-file.ts @@ -9,12 +9,12 @@ import { SchematicsException, template, Tree, - url, + url } from '@angular-devkit/schematics'; import { getProject } from '../../utils/angular-utils'; import { NgAddOptions } from '../models/ng-add-options'; import { FlowType } from '../schema'; -import { AUTH_0, AZURE_AD_REFRESH_TOKENS, AZURE_AD_SILENT_RENEW, DEFAULT_CONFIG, IFRAME_SILENT_RENEW, OIDC_PLAIN } from './configs'; +import { AUTH_0, AZURE_AD_REFRESH_TOKENS, AZURE_AD_SILENT_RENEW, DEFAULT_CONFIG, IFRAME_SILENT_RENEW, OAUTH_PAR, OIDC_PLAIN } from './configs'; export function copyModuleFile(options: NgAddOptions): Rule { return (host: Tree, context: SchematicContext) => { @@ -67,6 +67,11 @@ function getConfig(flowType: FlowType, stsUrlOrTenantId: string) { break; } + case FlowType.OAuthPushAuthorizationRequestsUsingRefreshTokens: { + config = OAUTH_PAR; + break; + } + case FlowType.OidcCodeFlowPkceUsingIframeSilentRenew: { config = IFRAME_SILENT_RENEW; break; diff --git a/projects/schematics/src/ng-add/schema.json b/projects/schematics/src/ng-add/schema.json index 280f69ccd..dcf1bcd82 100644 --- a/projects/schematics/src/ng-add/schema.json +++ b/projects/schematics/src/ng-add/schema.json @@ -11,6 +11,7 @@ "OIDC Code Flow PKCE Azure AD using refresh tokens", "OIDC Code Flow PKCE Azure AD using iframe silent renew", "OIDC Code Flow PKCE using refresh tokens", + "OAuth Push authorization requests using refresh tokens", "OIDC Code Flow PKCE using iframe silent renew", "OIDC Code Flow PKCE using iframe silent renew getting config from http", "OIDC Code Flow PKCE (no renew)", diff --git a/projects/schematics/src/ng-add/schema.ts b/projects/schematics/src/ng-add/schema.ts index 6f77a2f57..02083d8b6 100644 --- a/projects/schematics/src/ng-add/schema.ts +++ b/projects/schematics/src/ng-add/schema.ts @@ -7,6 +7,7 @@ export enum FlowType { OidcCodeFlowPkceAzureAdUsingRefreshTokens = 'OIDC Code Flow PKCE Azure AD using refresh tokens', OidcCodeFlowPkceAzureAdUsingIframeSilentRenew = 'OIDC Code Flow PKCE Azure AD using iframe silent renew', OidcCodeFlowPkceUsingRefreshTokens = 'OIDC Code Flow PKCE using refresh tokens', + OAuthPushAuthorizationRequestsUsingRefreshTokens = 'OAuth Push authorization requests using refresh tokens', OidcCodeFlowPkceUsingIframeSilentRenew = 'OIDC Code Flow PKCE using iframe silent renew', OidcCodeFlowPkceUsingIframeSilentRenewGettingConfigFromHttp = 'OIDC Code Flow PKCE using iframe silent renew getting config from http', OIDCCodeFlowPkce = 'OIDC Code Flow PKCE (no renew)',