Skip to content

Commit ffd88d4

Browse files
authored
Merge pull request #1359 from Samuel-B-D/get-url-parameter-test
Fix `getUrlParameter`'s handling of fragment response
2 parents fce6fdd + b374b5a commit ffd88d4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ describe('UrlService Tests', () => {
118118
expect(code).toBe('thisisacode');
119119
expect(state).toBe('0000.1234.000');
120120
});
121+
122+
it('gets correct params when response_mode=fragment', () => {
123+
// Test url taken from an example in the RFC: https://datatracker.ietf.org/doc/html/rfc6749#section-4.2.2
124+
const urlToCheck = 'http://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA&state=xyz&token_type=example&expires_in=3600';
125+
const accessToken = service.getUrlParameter(urlToCheck, 'access_token');
126+
const state = service.getUrlParameter(urlToCheck, 'state');
127+
const tokenType = service.getUrlParameter(urlToCheck, 'token_type');
128+
const expiresIn = service.getUrlParameter(urlToCheck, 'expires_in');
129+
130+
expect(accessToken).toBe('2YotnFZFEjr1zCsicMWpAA');
131+
expect(state).toBe('xyz');
132+
expect(tokenType).toBe('example');
133+
expect(expiresIn).toBe('3600');
134+
});
121135
});
122136

123137
describe('createAuthorizeUrl', () => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class UrlService {
3333
}
3434

3535
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
36-
const regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
36+
const regex = new RegExp('[\\?&#]' + name + '=([^&#]*)');
3737
const results = regex.exec(urlToCheck);
3838

3939
return results === null ? '' : decodeURIComponent(results[1]);

0 commit comments

Comments
 (0)