@@ -286,6 +286,15 @@ export class OAuthService extends AuthConfig implements OnDestroy {
286
286
return lcUrl . startsWith ( 'https://' ) ;
287
287
}
288
288
289
+ protected assertUrlNotNullAndCorrectProtocol ( url : string | undefined , description : string ) {
290
+ if ( ! url ) {
291
+ throw new Error ( `'${ description } ' should not be null` ) ;
292
+ }
293
+ if ( ! this . validateUrlForHttps ( url ) ) {
294
+ throw new Error ( `'${ description } ' must use HTTPS (with TLS), or config value for property 'requireHttps' must be set to 'false' and allow HTTP (without TLS).` ) ;
295
+ }
296
+ }
297
+
289
298
protected validateUrlAgainstIssuer ( url : string ) {
290
299
if ( ! this . strictDiscoveryDocumentValidation ) {
291
300
return true ;
@@ -420,7 +429,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
420
429
}
421
430
422
431
if ( ! this . validateUrlForHttps ( fullUrl ) ) {
423
- reject ( 'issuer must use https , or config value for property requireHttps must allow http ' ) ;
432
+ reject ( 'issuer must use HTTPS (with TLS) , or config value for property \' requireHttps\' must be set to \'false\' and allow HTTP (without TLS). ' ) ;
424
433
return ;
425
434
}
426
435
@@ -607,9 +616,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
607
616
throw new Error ( 'Can not load User Profile without access_token' ) ;
608
617
}
609
618
if ( ! this . validateUrlForHttps ( this . userinfoEndpoint ) ) {
610
- throw new Error (
611
- 'userinfoEndpoint must use https, or config value for property requireHttps must allow http'
612
- ) ;
619
+ throw new Error ( 'userinfoEndpoint must use HTTPS (with TLS), or config value for property \'requireHttps\' must be set to \'false\' and allow HTTP (without TLS).' ) ;
613
620
}
614
621
615
622
return new Promise ( ( resolve , reject ) => {
@@ -666,12 +673,9 @@ export class OAuthService extends AuthConfig implements OnDestroy {
666
673
userName : string ,
667
674
password : string ,
668
675
headers : HttpHeaders = new HttpHeaders ( )
676
+
669
677
) : Promise < TokenResponse > {
670
- if ( ! this . validateUrlForHttps ( this . tokenEndpoint ) ) {
671
- throw new Error (
672
- 'tokenEndpoint must use https, or config value for property requireHttps must allow http'
673
- ) ;
674
- }
678
+ this . assertUrlNotNullAndCorrectProtocol ( this . tokenEndpoint , 'tokenEndpoint' ) ;
675
679
676
680
return new Promise ( ( resolve , reject ) => {
677
681
/**
@@ -744,12 +748,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
744
748
* method silentRefresh.
745
749
*/
746
750
public refreshToken ( ) : Promise < TokenResponse > {
747
-
748
- if ( ! this . validateUrlForHttps ( this . tokenEndpoint ) ) {
749
- throw new Error (
750
- 'tokenEndpoint must use https, or config value for property requireHttps must allow http'
751
- ) ;
752
- }
751
+ this . assertUrlNotNullAndCorrectProtocol ( this . tokenEndpoint , 'tokenEndpoint' ) ;
753
752
754
753
return new Promise ( ( resolve , reject ) => {
755
754
let params = new HttpParams ( )
@@ -861,9 +860,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
861
860
}
862
861
863
862
if ( ! this . validateUrlForHttps ( this . loginUrl ) ) {
864
- throw new Error (
865
- 'tokenEndpoint must use https, or config value for property requireHttps must allow http'
866
- ) ;
863
+ throw new Error ( 'loginUrl must use HTTPS (with TLS), or config value for property \'requireHttps\' must be set to \'false\' and allow HTTP (without TLS).' ) ;
867
864
}
868
865
869
866
if ( typeof document === 'undefined' ) {
@@ -1284,7 +1281,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1284
1281
1285
1282
if ( ! this . validateUrlForHttps ( this . loginUrl ) ) {
1286
1283
throw new Error (
1287
- 'loginUrl must use https , or config value for property requireHttps must allow http '
1284
+ 'loginUrl must use HTTPS (with TLS) , or config value for property \' requireHttps\' must be set to \'false\' and allow HTTP (without TLS). '
1288
1285
) ;
1289
1286
}
1290
1287
@@ -1474,13 +1471,10 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1474
1471
1475
1472
private fetchAndProcessToken ( params : HttpParams ) : Promise < TokenResponse > {
1476
1473
1474
+ this . assertUrlNotNullAndCorrectProtocol ( this . tokenEndpoint , 'tokenEndpoint' ) ;
1477
1475
let headers = new HttpHeaders ( )
1478
1476
. set ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;
1479
1477
1480
- if ( ! this . validateUrlForHttps ( this . tokenEndpoint ) ) {
1481
- throw new Error ( 'tokenEndpoint must use Http. Also check property requireHttps.' ) ;
1482
- }
1483
-
1484
1478
if ( this . useHttpBasicAuth ) {
1485
1479
const header = btoa ( `${ this . clientId } :${ this . dummyClientSecret } ` ) ;
1486
1480
headers = headers . set (
@@ -2049,7 +2043,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
2049
2043
2050
2044
if ( ! this . validateUrlForHttps ( this . logoutUrl ) ) {
2051
2045
throw new Error (
2052
- 'logoutUrl must use https , or config value for property requireHttps must allow http '
2046
+ 'logoutUrl must use HTTPS (with TLS) , or config value for property \' requireHttps\' must be set to \'false\' and allow HTTP (without TLS). '
2053
2047
) ;
2054
2048
}
2055
2049
@@ -2201,7 +2195,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
2201
2195
) : void {
2202
2196
2203
2197
if ( ! this . validateUrlForHttps ( this . loginUrl ) ) {
2204
- throw new Error ( 'loginUrl must use Http. Also check property requireHttps.' ) ;
2198
+ throw new Error ( 'loginUrl must use HTTPS (with TLS), or config value for property \' requireHttps\' must be set to \'false\' and allow HTTP (without TLS) .' ) ;
2205
2199
}
2206
2200
2207
2201
this . createLoginUrl ( additionalState , '' , null , false , params )
0 commit comments