@@ -15,6 +15,7 @@ import {
15
15
OAuthSuccessEvent
16
16
} from './events' ;
17
17
import {
18
+ OAuthLogger ,
18
19
OAuthStorage ,
19
20
LoginOptions ,
20
21
ParsedIdToken ,
@@ -87,7 +88,8 @@ export class OAuthService extends AuthConfig {
87
88
@Optional ( ) storage : OAuthStorage ,
88
89
@Optional ( ) tokenValidationHandler : ValidationHandler ,
89
90
@Optional ( ) private config : AuthConfig ,
90
- private urlHelper : UrlHelperService
91
+ private urlHelper : UrlHelperService ,
92
+ private logger : OAuthLogger ,
91
93
) {
92
94
super ( ) ;
93
95
@@ -109,7 +111,7 @@ export class OAuthService extends AuthConfig {
109
111
this . setStorage ( sessionStorage ) ;
110
112
}
111
113
} catch ( e ) {
112
- console . error (
114
+ this . logger . error (
113
115
'cannot access sessionStorage. Consider setting an own storage implementation using setStorage' ,
114
116
e
115
117
) ;
@@ -186,7 +188,7 @@ export class OAuthService extends AuthConfig {
186
188
187
189
private debug ( ...args ) : void {
188
190
if ( this . showDebugInformation ) {
189
- console . debug . apply ( console , args ) ;
191
+ this . logger . debug . apply ( console , args ) ;
190
192
}
191
193
}
192
194
@@ -420,7 +422,7 @@ export class OAuthService extends AuthConfig {
420
422
} ) ;
421
423
} ,
422
424
err => {
423
- console . error ( 'error loading discovery document' , err ) ;
425
+ this . logger . error ( 'error loading discovery document' , err ) ;
424
426
this . eventsSubject . next (
425
427
new OAuthErrorEvent ( 'discovery_document_load_error' , err )
426
428
) ;
@@ -442,7 +444,7 @@ export class OAuthService extends AuthConfig {
442
444
resolve ( jwks ) ;
443
445
} ,
444
446
err => {
445
- console . error ( 'error loading jwks' , err ) ;
447
+ this . logger . error ( 'error loading jwks' , err ) ;
446
448
this . eventsSubject . next (
447
449
new OAuthErrorEvent ( 'jwks_load_error' , err )
448
450
) ;
@@ -459,7 +461,7 @@ export class OAuthService extends AuthConfig {
459
461
let errors : string [ ] ;
460
462
461
463
if ( ! this . skipIssuerCheck && doc . issuer !== this . issuer ) {
462
- console . error (
464
+ this . logger . error (
463
465
'invalid issuer in discovery document' ,
464
466
'expected: ' + this . issuer ,
465
467
'current: ' + doc . issuer
@@ -469,7 +471,7 @@ export class OAuthService extends AuthConfig {
469
471
470
472
errors = this . validateUrlFromDiscoveryDocument ( doc . authorization_endpoint ) ;
471
473
if ( errors . length > 0 ) {
472
- console . error (
474
+ this . logger . error (
473
475
'error validating authorization_endpoint in discovery document' ,
474
476
errors
475
477
) ;
@@ -478,7 +480,7 @@ export class OAuthService extends AuthConfig {
478
480
479
481
errors = this . validateUrlFromDiscoveryDocument ( doc . end_session_endpoint ) ;
480
482
if ( errors . length > 0 ) {
481
- console . error (
483
+ this . logger . error (
482
484
'error validating end_session_endpoint in discovery document' ,
483
485
errors
484
486
) ;
@@ -487,15 +489,15 @@ export class OAuthService extends AuthConfig {
487
489
488
490
errors = this . validateUrlFromDiscoveryDocument ( doc . token_endpoint ) ;
489
491
if ( errors . length > 0 ) {
490
- console . error (
492
+ this . logger . error (
491
493
'error validating token_endpoint in discovery document' ,
492
494
errors
493
495
) ;
494
496
}
495
497
496
498
errors = this . validateUrlFromDiscoveryDocument ( doc . userinfo_endpoint ) ;
497
499
if ( errors . length > 0 ) {
498
- console . error (
500
+ this . logger . error (
499
501
'error validating userinfo_endpoint in discovery document' ,
500
502
errors
501
503
) ;
@@ -504,12 +506,12 @@ export class OAuthService extends AuthConfig {
504
506
505
507
errors = this . validateUrlFromDiscoveryDocument ( doc . jwks_uri ) ;
506
508
if ( errors . length > 0 ) {
507
- console . error ( 'error validating jwks_uri in discovery document' , errors ) ;
509
+ this . logger . error ( 'error validating jwks_uri in discovery document' , errors ) ;
508
510
return false ;
509
511
}
510
512
511
513
if ( this . sessionChecksEnabled && ! doc . check_session_iframe ) {
512
- console . warn (
514
+ this . logger . warn (
513
515
'sessionChecksEnabled is activated but discovery document' +
514
516
' does not contain a check_session_iframe field'
515
517
) ;
@@ -595,7 +597,7 @@ export class OAuthService extends AuthConfig {
595
597
resolve ( info ) ;
596
598
} ,
597
599
err => {
598
- console . error ( 'error loading user info' , err ) ;
600
+ this . logger . error ( 'error loading user info' , err ) ;
599
601
this . eventsSubject . next (
600
602
new OAuthErrorEvent ( 'user_profile_load_error' , err )
601
603
) ;
@@ -677,7 +679,7 @@ export class OAuthService extends AuthConfig {
677
679
resolve ( tokenResponse ) ;
678
680
} ,
679
681
err => {
680
- console . error ( 'Error performing password flow' , err ) ;
682
+ this . logger . error ( 'Error performing password flow' , err ) ;
681
683
this . eventsSubject . next ( new OAuthErrorEvent ( 'token_error' , err ) ) ;
682
684
reject ( err ) ;
683
685
}
@@ -738,7 +740,7 @@ export class OAuthService extends AuthConfig {
738
740
resolve ( tokenResponse ) ;
739
741
} ,
740
742
err => {
741
- console . error ( 'Error performing password flow' , err ) ;
743
+ this . logger . error ( 'Error performing password flow' , err ) ;
742
744
this . eventsSubject . next (
743
745
new OAuthErrorEvent ( 'token_refresh_error' , err )
744
746
) ;
@@ -886,15 +888,15 @@ export class OAuthService extends AuthConfig {
886
888
return false ;
887
889
}
888
890
if ( ! this . sessionCheckIFrameUrl ) {
889
- console . warn (
891
+ this . logger . warn (
890
892
'sessionChecksEnabled is activated but there ' +
891
893
'is no sessionCheckIFrameUrl'
892
894
) ;
893
895
return false ;
894
896
}
895
897
const sessionState = this . getSessionState ( ) ;
896
898
if ( ! sessionState ) {
897
- console . warn (
899
+ this . logger . warn (
898
900
'sessionChecksEnabled is activated but there ' + 'is no session_state'
899
901
) ;
900
902
return false ;
@@ -1037,7 +1039,7 @@ export class OAuthService extends AuthConfig {
1037
1039
const iframe : any = document . getElementById ( this . sessionCheckIFrameName ) ;
1038
1040
1039
1041
if ( ! iframe ) {
1040
- console . warn (
1042
+ this . logger . warn (
1041
1043
'checkSession did not find iframe' ,
1042
1044
this . sessionCheckIFrameName
1043
1045
) ;
@@ -1175,8 +1177,8 @@ export class OAuthService extends AuthConfig {
1175
1177
location . href = url ;
1176
1178
} )
1177
1179
. catch ( error => {
1178
- console . error ( 'Error in initImplicitFlow' ) ;
1179
- console . error ( error ) ;
1180
+ this . logger . error ( 'Error in initImplicitFlow' ) ;
1181
+ this . logger . error ( error ) ;
1180
1182
this . inImplicitFlow = false ;
1181
1183
} ) ;
1182
1184
}
@@ -1302,7 +1304,7 @@ export class OAuthService extends AuthConfig {
1302
1304
}
1303
1305
1304
1306
if ( this . sessionChecksEnabled && ! sessionState ) {
1305
- console . warn (
1307
+ this . logger . warn (
1306
1308
'session checks (Session Status Change Notification) ' +
1307
1309
'is activated in the configuration but the id_token ' +
1308
1310
'does not contain a session_state claim'
@@ -1366,8 +1368,8 @@ export class OAuthService extends AuthConfig {
1366
1368
this . eventsSubject . next (
1367
1369
new OAuthErrorEvent ( 'token_validation_error' , reason )
1368
1370
) ;
1369
- console . error ( 'Error validating tokens' ) ;
1370
- console . error ( reason ) ;
1371
+ this . logger . error ( 'Error validating tokens' ) ;
1372
+ this . logger . error ( reason ) ;
1371
1373
return Promise . reject ( reason ) ;
1372
1374
} ) ;
1373
1375
}
@@ -1379,7 +1381,7 @@ export class OAuthService extends AuthConfig {
1379
1381
const savedNonce = this . _storage . getItem ( 'nonce' ) ;
1380
1382
if ( savedNonce !== nonceInState ) {
1381
1383
const err = 'validating access_token failed. wrong state/nonce.' ;
1382
- console . error ( err , savedNonce , nonceInState ) ;
1384
+ this . logger . error ( err , savedNonce , nonceInState ) ;
1383
1385
return false ;
1384
1386
}
1385
1387
return true ;
@@ -1428,28 +1430,28 @@ export class OAuthService extends AuthConfig {
1428
1430
if ( Array . isArray ( claims . aud ) ) {
1429
1431
if ( claims . aud . every ( v => v !== this . clientId ) ) {
1430
1432
const err = 'Wrong audience: ' + claims . aud . join ( ',' ) ;
1431
- console . warn ( err ) ;
1433
+ this . logger . warn ( err ) ;
1432
1434
return Promise . reject ( err ) ;
1433
1435
}
1434
1436
} else {
1435
1437
if ( claims . aud !== this . clientId ) {
1436
1438
const err = 'Wrong audience: ' + claims . aud ;
1437
- console . warn ( err ) ;
1439
+ this . logger . warn ( err ) ;
1438
1440
return Promise . reject ( err ) ;
1439
1441
}
1440
1442
}
1441
1443
1442
1444
/*
1443
1445
if (this.getKeyCount() > 1 && !header.kid) {
1444
1446
let err = 'There needs to be a kid property in the id_token header when multiple keys are defined via the property jwks';
1445
- console .warn(err);
1447
+ this.logger .warn(err);
1446
1448
return Promise.reject(err);
1447
1449
}
1448
1450
*/
1449
1451
1450
1452
if ( ! claims . sub ) {
1451
1453
const err = 'No sub claim in id_token' ;
1452
- console . warn ( err ) ;
1454
+ this . logger . warn ( err ) ;
1453
1455
return Promise . reject ( err ) ;
1454
1456
}
1455
1457
@@ -1469,25 +1471,25 @@ export class OAuthService extends AuthConfig {
1469
1471
claims [ 'sub' ]
1470
1472
} `;
1471
1473
1472
- console . warn ( err ) ;
1474
+ this . logger . warn ( err ) ;
1473
1475
return Promise . reject ( err ) ;
1474
1476
}
1475
1477
1476
1478
if ( ! claims . iat ) {
1477
1479
const err = 'No iat claim in id_token' ;
1478
- console . warn ( err ) ;
1480
+ this . logger . warn ( err ) ;
1479
1481
return Promise . reject ( err ) ;
1480
1482
}
1481
1483
1482
1484
if ( claims . iss !== this . issuer ) {
1483
1485
const err = 'Wrong issuer: ' + claims . iss ;
1484
- console . warn ( err ) ;
1486
+ this . logger . warn ( err ) ;
1485
1487
return Promise . reject ( err ) ;
1486
1488
}
1487
1489
1488
1490
if ( claims . nonce !== savedNonce ) {
1489
1491
const err = 'Wrong nonce: ' + claims . nonce ;
1490
- console . warn ( err ) ;
1492
+ this . logger . warn ( err ) ;
1491
1493
return Promise . reject ( err ) ;
1492
1494
}
1493
1495
@@ -1497,7 +1499,7 @@ export class OAuthService extends AuthConfig {
1497
1499
! claims [ 'at_hash' ]
1498
1500
) {
1499
1501
const err = 'An at_hash is needed!' ;
1500
- console . warn ( err ) ;
1502
+ this . logger . warn ( err ) ;
1501
1503
return Promise . reject ( err ) ;
1502
1504
}
1503
1505
@@ -1511,8 +1513,8 @@ export class OAuthService extends AuthConfig {
1511
1513
expiresAtMSec + tenMinutesInMsec <= now
1512
1514
) {
1513
1515
const err = 'Token has been expired' ;
1514
- console . error ( err ) ;
1515
- console . error ( {
1516
+ this . logger . error ( err ) ;
1517
+ this . logger . error ( {
1516
1518
now : now ,
1517
1519
issuedAtMSec : issuedAtMSec ,
1518
1520
expiresAtMSec : expiresAtMSec
@@ -1535,7 +1537,7 @@ export class OAuthService extends AuthConfig {
1535
1537
! this . checkAtHash ( validationParams )
1536
1538
) {
1537
1539
const err = 'Wrong at_hash' ;
1538
- console . warn ( err ) ;
1540
+ this . logger . warn ( err ) ;
1539
1541
return Promise . reject ( err ) ;
1540
1542
}
1541
1543
@@ -1776,7 +1778,7 @@ export class OAuthService extends AuthConfig {
1776
1778
1777
1779
private checkAtHash ( params : ValidationParams ) : boolean {
1778
1780
if ( ! this . tokenValidationHandler ) {
1779
- console . warn (
1781
+ this . logger . warn (
1780
1782
'No tokenValidationHandler configured. Cannot check at_hash.'
1781
1783
) ;
1782
1784
return true ;
@@ -1786,7 +1788,7 @@ export class OAuthService extends AuthConfig {
1786
1788
1787
1789
private checkSignature ( params : ValidationParams ) : Promise < any > {
1788
1790
if ( ! this . tokenValidationHandler ) {
1789
- console . warn (
1791
+ this . logger . warn (
1790
1792
'No tokenValidationHandler configured. Cannot check signature.'
1791
1793
) ;
1792
1794
return Promise . resolve ( null ) ;
0 commit comments