Skip to content

Commit 517ee68

Browse files
authored
Merge pull request #1455 from Kwoin/main
add disablePkce config parameter
2 parents 6dc4174 + 070928d commit 517ee68

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

projects/angular-auth-oidc-client/src/lib/config/openid-configuration.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,9 @@ export interface OpenIdConfiguration {
176176
*/
177177
allowUnsafeReuseRefreshToken?: boolean;
178178
/** Disable validation for id_token expiry time */
179-
disableIdTokenValidation?: boolean
179+
disableIdTokenValidation?: boolean;
180+
/** Disables PKCE support.
181+
* Authorize request will be sent without code challenge.
182+
*/
183+
disablePkce?: boolean;
180184
}

projects/angular-auth-oidc-client/src/lib/utils/url/url.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ describe('UrlService Tests', () => {
230230
expect(value).toEqual(expectValue);
231231
});
232232

233-
it('createAuthorizeUrl with code flow adds "code_challenge" and "code_challenge_method" param', () => {
233+
it('createAuthorizeUrl with code flow and codeChallenge adds "code_challenge" and "code_challenge_method" param', () => {
234234
const config = { authority: 'https://localhost:5001' } as OpenIdConfiguration;
235235
config.clientId = '188968487735-b1hh7k87nkkh6vv84548sinju2kpr7gn.apps.googleusercontent.com';
236236
config.responseType = 'code';
@@ -245,7 +245,7 @@ describe('UrlService Tests', () => {
245245
.and.returnValue({ authorizationEndpoint: 'http://example' });
246246

247247
const value = (service as any).createAuthorizeUrl(
248-
'', // Implicit Flow
248+
'codeChallenge', // Code Flow
249249
config.redirectUrl,
250250
'nonce',
251251
'state',
@@ -259,7 +259,7 @@ describe('UrlService Tests', () => {
259259
'&scope=openid%20email%20profile' +
260260
'&nonce=nonce' +
261261
'&state=state' +
262-
'&code_challenge=&code_challenge_method=S256' +
262+
'&code_challenge=codeChallenge&code_challenge_method=S256' +
263263
'&testcustom=customvalue';
264264

265265
expect(value).toEqual(expectValue);

projects/angular-auth-oidc-client/src/lib/utils/url/url.service.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export class UrlService {
356356
params = params.append('nonce', nonce);
357357
params = params.append('state', state);
358358

359-
if (this.flowHelper.isCurrentFlowCodeFlow(configuration)) {
359+
if (this.flowHelper.isCurrentFlowCodeFlow(configuration) && codeChallenge != null) {
360360
params = params.append('code_challenge', codeChallenge);
361361
params = params.append('code_challenge_method', 'S256');
362362
}
@@ -469,10 +469,7 @@ export class UrlService {
469469
return of(null);
470470
}
471471

472-
// code_challenge with "S256"
473-
const codeVerifier = this.flowsDataService.createCodeVerifier(config);
474-
475-
return this.jwtWindowCryptoService.generateCodeChallenge(codeVerifier).pipe(
472+
return this.getCodeChallenge(config).pipe(
476473
map((codeChallenge: string) => {
477474
const authWellKnownEndPoints = this.storagePersistenceService.read('authWellKnownEndPoints', config);
478475
if (authWellKnownEndPoints) {
@@ -488,6 +485,18 @@ export class UrlService {
488485
);
489486
}
490487

488+
private getCodeChallenge(config: OpenIdConfiguration): Observable<string> {
489+
490+
if (config.disablePkce) {
491+
return of(null);
492+
}
493+
494+
// code_challenge with "S256"
495+
const codeVerifier = this.flowsDataService.createCodeVerifier(config);
496+
497+
return this.jwtWindowCryptoService.generateCodeChallenge(codeVerifier);
498+
}
499+
491500
private getRedirectUrl(configuration: OpenIdConfiguration, authOptions?: AuthOptions): string {
492501
let { redirectUrl } = configuration;
493502

0 commit comments

Comments
 (0)