File tree 2 files changed +15
-1
lines changed
projects/angular-auth-oidc-client/src/lib/utils/url
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,20 @@ describe('UrlService Tests', () => {
118
118
expect ( code ) . toBe ( 'thisisacode' ) ;
119
119
expect ( state ) . toBe ( '0000.1234.000' ) ;
120
120
} ) ;
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
+ } ) ;
121
135
} ) ;
122
136
123
137
describe ( 'createAuthorizeUrl' , ( ) => {
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ export class UrlService {
33
33
}
34
34
35
35
name = name . replace ( / [ \[ ] / , '\\[' ) . replace ( / [ \] ] / , '\\]' ) ;
36
- const regex = new RegExp ( '[\\?&]' + name + '=([^&#]*)' ) ;
36
+ const regex = new RegExp ( '[\\?&# ]' + name + '=([^&#]*)' ) ;
37
37
const results = regex . exec ( urlToCheck ) ;
38
38
39
39
return results === null ? '' : decodeURIComponent ( results [ 1 ] ) ;
You can’t perform that action at this time.
0 commit comments