@@ -282,6 +282,15 @@ export class OAuthService extends AuthConfig implements OnDestroy {
282
282
return lcUrl . startsWith ( 'https://' ) ;
283
283
}
284
284
285
+ protected assertUrlNotNullAndCorrectProtocol ( url : string | undefined , description : string ) {
286
+ if ( ! url ) {
287
+ throw new Error ( `'${ description } ' should not be null` ) ;
288
+ }
289
+ if ( ! this . validateUrlForHttps ( url ) ) {
290
+ 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).` ) ;
291
+ }
292
+ }
293
+
285
294
protected validateUrlAgainstIssuer ( url : string ) {
286
295
if ( ! this . strictDiscoveryDocumentValidation ) {
287
296
return true ;
@@ -416,7 +425,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
416
425
}
417
426
418
427
if ( ! this . validateUrlForHttps ( fullUrl ) ) {
419
- reject ( 'issuer must use https , or config value for property requireHttps must allow http ' ) ;
428
+ reject ( 'issuer must use HTTPS (with TLS) , or config value for property \' requireHttps\' must be set to \'false\' and allow HTTP (without TLS). ' ) ;
420
429
return ;
421
430
}
422
431
@@ -603,9 +612,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
603
612
throw new Error ( 'Can not load User Profile without access_token' ) ;
604
613
}
605
614
if ( ! this . validateUrlForHttps ( this . userinfoEndpoint ) ) {
606
- throw new Error (
607
- 'userinfoEndpoint must use https, or config value for property requireHttps must allow http'
608
- ) ;
615
+ 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).' ) ;
609
616
}
610
617
611
618
return new Promise ( ( resolve , reject ) => {
@@ -663,11 +670,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
663
670
password : string ,
664
671
headers : HttpHeaders = new HttpHeaders ( )
665
672
) : Promise < object > {
666
- if ( ! this . validateUrlForHttps ( this . tokenEndpoint ) ) {
667
- throw new Error (
668
- 'tokenEndpoint must use https, or config value for property requireHttps must allow http'
669
- ) ;
670
- }
673
+ this . assertUrlNotNullAndCorrectProtocol ( this . tokenEndpoint , 'tokenEndpoint' ) ;
671
674
672
675
return new Promise ( ( resolve , reject ) => {
673
676
/**
@@ -740,12 +743,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
740
743
* method silentRefresh.
741
744
*/
742
745
public refreshToken ( ) : Promise < object > {
743
-
744
- if ( ! this . validateUrlForHttps ( this . tokenEndpoint ) ) {
745
- throw new Error (
746
- 'tokenEndpoint must use https, or config value for property requireHttps must allow http'
747
- ) ;
748
- }
746
+ this . assertUrlNotNullAndCorrectProtocol ( this . tokenEndpoint , 'tokenEndpoint' ) ;
749
747
750
748
return new Promise ( ( resolve , reject ) => {
751
749
let params = new HttpParams ( )
@@ -857,9 +855,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
857
855
}
858
856
859
857
if ( ! this . validateUrlForHttps ( this . loginUrl ) ) {
860
- throw new Error (
861
- 'tokenEndpoint must use https, or config value for property requireHttps must allow http'
862
- ) ;
858
+ 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).' ) ;
863
859
}
864
860
865
861
if ( typeof document === 'undefined' ) {
@@ -1264,7 +1260,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1264
1260
}
1265
1261
1266
1262
return url ;
1267
-
1263
+
1268
1264
}
1269
1265
1270
1266
initImplicitFlowInternal (
@@ -1279,7 +1275,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1279
1275
1280
1276
if ( ! this . validateUrlForHttps ( this . loginUrl ) ) {
1281
1277
throw new Error (
1282
- 'loginUrl must use https , or config value for property requireHttps must allow http '
1278
+ 'loginUrl must use HTTPS (with TLS) , or config value for property \' requireHttps\' must be set to \'false\' and allow HTTP (without TLS). '
1283
1279
) ;
1284
1280
}
1285
1281
@@ -1469,13 +1465,10 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1469
1465
1470
1466
private fetchAndProcessToken ( params : HttpParams ) : Promise < object > {
1471
1467
1468
+ this . assertUrlNotNullAndCorrectProtocol ( this . tokenEndpoint , 'tokenEndpoint' ) ;
1472
1469
let headers = new HttpHeaders ( )
1473
1470
. set ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;
1474
1471
1475
- if ( ! this . validateUrlForHttps ( this . tokenEndpoint ) ) {
1476
- throw new Error ( 'tokenEndpoint must use Http. Also check property requireHttps.' ) ;
1477
- }
1478
-
1479
1472
if ( this . useHttpBasicAuth ) {
1480
1473
const header = btoa ( `${ this . clientId } :${ this . dummyClientSecret } ` ) ;
1481
1474
headers = headers . set (
@@ -1503,32 +1496,32 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1503
1496
( tokenResponse ) => {
1504
1497
this . debug ( 'refresh tokenResponse' , tokenResponse ) ;
1505
1498
this . storeAccessTokenResponse (
1506
- tokenResponse . access_token ,
1507
- tokenResponse . refresh_token ,
1499
+ tokenResponse . access_token ,
1500
+ tokenResponse . refresh_token ,
1508
1501
tokenResponse . expires_in ,
1509
1502
tokenResponse . scope ) ;
1510
1503
1511
1504
if ( this . oidc && tokenResponse . id_token ) {
1512
- this . processIdToken ( tokenResponse . id_token , tokenResponse . access_token ) .
1505
+ this . processIdToken ( tokenResponse . id_token , tokenResponse . access_token ) .
1513
1506
then ( result => {
1514
1507
this . storeIdToken ( result ) ;
1515
-
1508
+
1516
1509
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_received' ) ) ;
1517
1510
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_refreshed' ) ) ;
1518
-
1511
+
1519
1512
resolve ( tokenResponse ) ;
1520
1513
} )
1521
1514
. catch ( reason => {
1522
1515
this . eventsSubject . next ( new OAuthErrorEvent ( 'token_validation_error' , reason ) ) ;
1523
1516
console . error ( 'Error validating tokens' ) ;
1524
1517
console . error ( reason ) ;
1525
-
1518
+
1526
1519
reject ( reason ) ;
1527
1520
} ) ;
1528
1521
} else {
1529
1522
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_received' ) ) ;
1530
1523
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_refreshed' ) ) ;
1531
-
1524
+
1532
1525
resolve ( tokenResponse ) ;
1533
1526
}
1534
1527
} ,
@@ -1688,7 +1681,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1688
1681
) : boolean {
1689
1682
const savedNonce = this . _storage . getItem ( 'nonce' ) ;
1690
1683
if ( savedNonce !== nonceInState ) {
1691
-
1684
+
1692
1685
const err = 'Validating access_token failed, wrong state/nonce.' ;
1693
1686
console . error ( err , savedNonce , nonceInState ) ;
1694
1687
return false ;
@@ -2026,7 +2019,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
2026
2019
2027
2020
if ( ! this . validateUrlForHttps ( this . logoutUrl ) ) {
2028
2021
throw new Error (
2029
- 'logoutUrl must use https , or config value for property requireHttps must allow http '
2022
+ 'logoutUrl must use HTTPS (with TLS) , or config value for property \' requireHttps\' must be set to \'false\' and allow HTTP (without TLS). '
2030
2023
) ;
2031
2024
}
2032
2025
@@ -2165,7 +2158,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
2165
2158
) : void {
2166
2159
2167
2160
if ( ! this . validateUrlForHttps ( this . loginUrl ) ) {
2168
- throw new Error ( 'loginUrl must use Http. Also check property requireHttps.' ) ;
2161
+ 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) .' ) ;
2169
2162
}
2170
2163
2171
2164
this . createLoginUrl ( additionalState , '' , null , false , params ) . then ( function ( url ) {
0 commit comments