@@ -6,21 +6,21 @@ import packageJson from "../../package.json";
6
6
import {
7
7
AccessTokenError ,
8
8
AccessTokenErrorCode ,
9
+ AccessTokenForConnectionError ,
10
+ AccessTokenForConnectionErrorCode ,
9
11
AuthorizationCodeGrantError ,
10
12
AuthorizationError ,
11
13
BackchannelLogoutError ,
12
14
DiscoveryError ,
13
- AccessTokenForConnectionError ,
14
- AccessTokenForConnectionErrorCode ,
15
15
InvalidStateError ,
16
16
MissingStateError ,
17
17
OAuth2Error ,
18
18
SdkError
19
19
} from "../errors" ;
20
20
import {
21
+ AccessTokenForConnectionOptions ,
21
22
AuthorizationParameters ,
22
23
ConnectionTokenSet ,
23
- AccessTokenForConnectionOptions ,
24
24
LogoutToken ,
25
25
SessionData ,
26
26
StartInteractiveLoginOptions ,
@@ -65,7 +65,6 @@ const DEFAULT_SCOPES = ["openid", "profile", "email", "offline_access"].join(
65
65
" "
66
66
) ;
67
67
68
-
69
68
/**
70
69
* A constant representing the grant type for federated connection access token exchange.
71
70
*
@@ -616,10 +615,16 @@ export class AuthClient {
616
615
expires_at : updatedTokenSet . expiresAt
617
616
} ) ;
618
617
619
- await this . sessionStore . set ( req . cookies , res . cookies , {
620
- ...session ,
621
- tokenSet : updatedTokenSet
622
- } ) ;
618
+ if (
619
+ updatedTokenSet . accessToken !== session . tokenSet . accessToken ||
620
+ updatedTokenSet . refreshToken !== session . tokenSet . refreshToken ||
621
+ updatedTokenSet . expiresAt !== session . tokenSet . expiresAt
622
+ ) {
623
+ await this . sessionStore . set ( req . cookies , res . cookies , {
624
+ ...session ,
625
+ tokenSet : updatedTokenSet
626
+ } ) ;
627
+ }
623
628
624
629
return res ;
625
630
}
@@ -1016,19 +1021,20 @@ export class AuthClient {
1016
1021
tokenSet : TokenSet ,
1017
1022
connectionTokenSet : ConnectionTokenSet | undefined ,
1018
1023
options : AccessTokenForConnectionOptions
1019
- ) : Promise < [ AccessTokenForConnectionError , null ] | [ null , ConnectionTokenSet ] > {
1024
+ ) : Promise <
1025
+ [ AccessTokenForConnectionError , null ] | [ null , ConnectionTokenSet ]
1026
+ > {
1020
1027
// If we do not have a refresh token
1021
1028
// and we do not have a connection token set in the cache or the one we have is expired,
1022
1029
// there is noting to retrieve and we return an error.
1023
1030
if (
1024
1031
! tokenSet . refreshToken &&
1025
- ( ! connectionTokenSet ||
1026
- connectionTokenSet . expiresAt <= Date . now ( ) / 1000 )
1032
+ ( ! connectionTokenSet || connectionTokenSet . expiresAt <= Date . now ( ) / 1000 )
1027
1033
) {
1028
1034
return [
1029
1035
new AccessTokenForConnectionError (
1030
1036
AccessTokenForConnectionErrorCode . MISSING_REFRESH_TOKEN ,
1031
- "A refresh token was not present, Connection Access Token requires a refresh token. The user needs to re-authenticate." ,
1037
+ "A refresh token was not present, Connection Access Token requires a refresh token. The user needs to re-authenticate."
1032
1038
) ,
1033
1039
null
1034
1040
] ;
@@ -1039,8 +1045,7 @@ export class AuthClient {
1039
1045
// we need to exchange the refresh token for a connection access token.
1040
1046
if (
1041
1047
tokenSet . refreshToken &&
1042
- ( ! connectionTokenSet ||
1043
- connectionTokenSet . expiresAt <= Date . now ( ) / 1000 )
1048
+ ( ! connectionTokenSet || connectionTokenSet . expiresAt <= Date . now ( ) / 1000 )
1044
1049
) {
1045
1050
const params = new URLSearchParams ( ) ;
1046
1051
@@ -1111,10 +1116,7 @@ export class AuthClient {
1111
1116
] ;
1112
1117
}
1113
1118
1114
- return [ null , connectionTokenSet ] as [
1115
- null ,
1116
- ConnectionTokenSet
1117
- ] ;
1119
+ return [ null , connectionTokenSet ] as [ null , ConnectionTokenSet ] ;
1118
1120
}
1119
1121
}
1120
1122
0 commit comments