@@ -85,6 +85,7 @@ export class OAuthService
85
85
this . configure ( config ) ;
86
86
}
87
87
88
+
88
89
try {
89
90
if ( storage ) {
90
91
this . setStorage ( storage ) ;
@@ -571,7 +572,7 @@ export class OAuthService
571
572
this . http . post < TokenResponse > ( this . tokenEndpoint , params , { headers } ) . subscribe (
572
573
( tokenResponse ) => {
573
574
this . debug ( 'tokenResponse' , tokenResponse ) ;
574
- this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in ) ;
575
+ this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in , tokenResponse . scope ) ;
575
576
576
577
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_received' ) ) ;
577
578
resolve ( tokenResponse ) ;
@@ -622,7 +623,7 @@ export class OAuthService
622
623
this . http . post < TokenResponse > ( this . tokenEndpoint , params , { headers } ) . subscribe (
623
624
( tokenResponse ) => {
624
625
this . debug ( 'refresh tokenResponse' , tokenResponse ) ;
625
- this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in ) ;
626
+ this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in , tokenResponse . scope ) ;
626
627
627
628
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_received' ) ) ;
628
629
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_refreshed' ) ) ;
@@ -726,6 +727,7 @@ export class OAuthService
726
727
document . body . appendChild ( iframe ) ;
727
728
} ) ;
728
729
730
+
729
731
let errors = this . events . pipe ( filter ( e => e instanceof OAuthErrorEvent ) , first ( ) ) ;
730
732
let success = this . events . pipe ( filter ( e => e . type === 'silently_refreshed' ) , first ( ) ) ;
731
733
let timeout = of ( new OAuthErrorEvent ( 'silent_refresh_timeout' , null ) )
@@ -1055,8 +1057,9 @@ export class OAuthService
1055
1057
}
1056
1058
}
1057
1059
1058
- private storeAccessTokenResponse ( accessToken : string , refreshToken : string , expiresIn : number ) : void {
1060
+ private storeAccessTokenResponse ( accessToken : string , refreshToken : string , expiresIn : number , grantedScopes : String ) : void {
1059
1061
this . _storage . setItem ( 'access_token' , accessToken ) ;
1062
+ this . _storage . setItem ( 'granted_scopes' , JSON . stringify ( grantedScopes . split ( '+' ) ) ) ;
1060
1063
this . _storage . setItem ( 'access_token_stored_at' , '' + Date . now ( ) ) ;
1061
1064
if ( expiresIn ) {
1062
1065
let expiresInMilliSeconds = expiresIn * 1000 ;
@@ -1105,6 +1108,7 @@ export class OAuthService
1105
1108
let idToken = parts [ 'id_token' ] ;
1106
1109
let state = decodeURIComponent ( parts [ 'state' ] ) ;
1107
1110
let sessionState = parts [ 'session_state' ] ;
1111
+ let grantedScopes = parts [ 'scope' ] ;
1108
1112
1109
1113
if ( ! this . requestAccessToken && ! this . oidc ) {
1110
1114
return Promise . reject ( 'Either requestAccessToken or oidc or both must be true.' ) ;
@@ -1146,7 +1150,7 @@ export class OAuthService
1146
1150
}
1147
1151
1148
1152
if ( this . requestAccessToken ) {
1149
- this . storeAccessTokenResponse ( accessToken , null , parts [ 'expires_in' ] ) ;
1153
+ this . storeAccessTokenResponse ( accessToken , null , parts [ 'expires_in' ] , grantedScopes ) ;
1150
1154
}
1151
1155
1152
1156
if ( ! this . oidc ) {
@@ -1292,6 +1296,7 @@ export class OAuthService
1292
1296
return Promise . reject ( err ) ;
1293
1297
}
1294
1298
1299
+
1295
1300
if ( ! this . disableAtHashCheck && this . requestAccessToken && ! claims [ 'at_hash' ] ) {
1296
1301
let err = 'An at_hash is needed!' ;
1297
1302
console . warn ( err ) ;
@@ -1352,6 +1357,15 @@ export class OAuthService
1352
1357
return JSON . parse ( claims ) ;
1353
1358
}
1354
1359
1360
+ /**
1361
+ * Returns the granted scopes from the server.
1362
+ */
1363
+ public getGrantedScopes ( ) : object {
1364
+ let scopes = this . _storage . getItem ( 'granted_scopes' ) ;
1365
+ if ( ! scopes ) return null ;
1366
+ return JSON . parse ( scopes ) ;
1367
+ }
1368
+
1355
1369
/**
1356
1370
* Returns the current id_token.
1357
1371
*/
0 commit comments