@@ -778,8 +778,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
778
778
tap ( result => this . storeIdToken ( result ) ) ,
779
779
map ( _ => tokenResponse )
780
780
) ;
781
- }
782
- else {
781
+ } else {
783
782
return of ( tokenResponse ) ;
784
783
}
785
784
} ) )
@@ -1264,7 +1263,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1264
1263
}
1265
1264
1266
1265
return url ;
1267
-
1266
+
1268
1267
}
1269
1268
1270
1269
initImplicitFlowInternal (
@@ -1374,8 +1373,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1374
1373
public tryLogin ( options : LoginOptions = null ) : Promise < boolean > {
1375
1374
if ( this . config . responseType === 'code' ) {
1376
1375
return this . tryLoginCodeFlow ( ) . then ( _ => true ) ;
1377
- }
1378
- else {
1376
+ } else {
1379
1377
return this . tryLoginImplicitFlow ( options ) ;
1380
1378
}
1381
1379
}
@@ -1397,7 +1395,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1397
1395
1398
1396
public tryLoginCodeFlow ( ) : Promise < void > {
1399
1397
1400
- const parts = this . parseQueryString ( window . location . search )
1398
+ const parts = this . parseQueryString ( window . location . search ) ;
1401
1399
1402
1400
const code = parts [ 'code' ] ;
1403
1401
const state = parts [ 'state' ] ;
@@ -1503,32 +1501,32 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1503
1501
( tokenResponse ) => {
1504
1502
this . debug ( 'refresh tokenResponse' , tokenResponse ) ;
1505
1503
this . storeAccessTokenResponse (
1506
- tokenResponse . access_token ,
1507
- tokenResponse . refresh_token ,
1504
+ tokenResponse . access_token ,
1505
+ tokenResponse . refresh_token ,
1508
1506
tokenResponse . expires_in ,
1509
1507
tokenResponse . scope ) ;
1510
1508
1511
1509
if ( this . oidc && tokenResponse . id_token ) {
1512
- this . processIdToken ( tokenResponse . id_token , tokenResponse . access_token ) .
1510
+ this . processIdToken ( tokenResponse . id_token , tokenResponse . access_token ) .
1513
1511
then ( result => {
1514
1512
this . storeIdToken ( result ) ;
1515
-
1513
+
1516
1514
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_received' ) ) ;
1517
1515
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_refreshed' ) ) ;
1518
-
1516
+
1519
1517
resolve ( tokenResponse ) ;
1520
1518
} )
1521
1519
. catch ( reason => {
1522
1520
this . eventsSubject . next ( new OAuthErrorEvent ( 'token_validation_error' , reason ) ) ;
1523
1521
console . error ( 'Error validating tokens' ) ;
1524
1522
console . error ( reason ) ;
1525
-
1523
+
1526
1524
reject ( reason ) ;
1527
1525
} ) ;
1528
1526
} else {
1529
1527
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_received' ) ) ;
1530
1528
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_refreshed' ) ) ;
1531
-
1529
+
1532
1530
resolve ( tokenResponse ) ;
1533
1531
}
1534
1532
} ,
@@ -1688,7 +1686,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1688
1686
) : boolean {
1689
1687
const savedNonce = this . _storage . getItem ( 'nonce' ) ;
1690
1688
if ( savedNonce !== nonceInState ) {
1691
-
1689
+
1692
1690
const err = 'Validating access_token failed, wrong state/nonce.' ;
1693
1691
console . error ( err , savedNonce , nonceInState ) ;
1694
1692
return false ;
@@ -2084,22 +2082,24 @@ export class OAuthService extends AuthConfig implements OnDestroy {
2084
2082
}
2085
2083
2086
2084
/*
2087
- * This alphabet uses a-z A-Z 0-9 _- symbols.
2088
- * Symbols order was changed for better gzip compression.
2085
+ * This alphabet is from:
2086
+ * https://tools.ietf.org/html/rfc7636#section-4.1
2087
+ *
2088
+ * [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~"
2089
2089
*/
2090
2090
const unreserved = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~' ;
2091
2091
let size = 45 ;
2092
2092
let id = '' ;
2093
2093
2094
2094
const crypto = self . crypto || self [ 'msCrypto' ] ;
2095
2095
if ( crypto ) {
2096
- const bytes = crypto . getRandomValues ( new Uint8Array ( size ) ) ;
2097
- while ( 0 < size -- ) {
2098
- id += unreserved [ bytes [ size ] & 63 ] ;
2099
- }
2096
+ let bytes = new Uint8Array ( size ) ;
2097
+ crypto . getRandomValues ( bytes ) ;
2098
+ bytes = bytes . map ( x => unreserved . charCodeAt ( x % unreserved . length ) ) ;
2099
+ id = String . fromCharCode . apply ( null , bytes ) ;
2100
2100
} else {
2101
2101
while ( 0 < size -- ) {
2102
- id += unreserved [ Math . random ( ) * 64 | 0 ] ;
2102
+ id += unreserved [ Math . random ( ) * unreserved . length | 0 ] ;
2103
2103
}
2104
2104
}
2105
2105
0 commit comments