Skip to content

Commit

Permalink
Merge pull request #979 from damienbod/damien/par-schematic
Browse files Browse the repository at this point in the history
Added OAuth Pushed authorisation requests (PAR) template using schematics
  • Loading branch information
damienbod committed Feb 23, 2021
2 parents fc97882 + 3ff334f commit d7ad8e7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -31,6 +32,7 @@ describe('CheckAuthService', () => {
let silentRenewService: SilentRenewService;
let periodicallyTokenCheckService: PeriodicallyTokenCheckService;
let refreshSessionService: RefreshSessionService;
let popUpService: PopUpService;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -45,7 +47,7 @@ describe('CheckAuthService', () => {
{ provide: CallbackService, useClass: CallbackServiceMock },
{ provide: RefreshSessionService, useClass: RefreshSessionServiceMock },
{ provide: PeriodicallyTokenCheckService, useClass: PeriodicallyTokenCheckServiceMock },
PopUpService,
{ provide: PopUpService, useClass: PopUpServiceMock },
],
});
});
Expand All @@ -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', () => {
Expand All @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class PopUpServiceMock {
return true;
}

isCurrentlyInPopup(): boolean {
return false;
}

openPopUp(url: string, popupOptions?: PopupOptions) {}

sendMessageToMainWindow(url: string) {}
Expand Down
18 changes: 17 additions & 1 deletion projects/schematics/src/ng-add/actions/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ const AZURE_AD_REFRESH_TOKENS = `{
autoUserinfo: false,
}`;

const OAUTH_PAR = `{
stsServer: '<stsUrlOrTenantId>',
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: '<stsUrlOrTenantId>',
redirectUrl: window.location.origin,
Expand All @@ -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 };
9 changes: 7 additions & 2 deletions projects/schematics/src/ng-add/actions/copy-module-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions projects/schematics/src/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
1 change: 1 addition & 0 deletions projects/schematics/src/ng-add/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down

0 comments on commit d7ad8e7

Please sign in to comment.