@@ -37,12 +37,16 @@ public Uni<String> createTokenState(RoutingContext routingContext, OidcTenantCon
37
37
sb .append (CodeAuthenticationMechanism .COOKIE_DELIM )
38
38
.append (tokens .getAccessToken ())
39
39
.append (CodeAuthenticationMechanism .COOKIE_DELIM )
40
+ .append (tokens .getAccessTokenExpiresIn () != null ? tokens .getAccessTokenExpiresIn () : "" )
41
+ .append (CodeAuthenticationMechanism .COOKIE_DELIM )
40
42
.append (tokens .getRefreshToken ());
41
43
} else if (oidcConfig .tokenStateManager ().strategy () == Strategy .ID_REFRESH_TOKENS ) {
42
44
// But sometimes the access token is not required.
43
45
// For example, when the Quarkus endpoint does not need to use it to access another service.
44
- // Skip access token, add refresh token
46
+ // Skip access token and access token expiry , add refresh token
45
47
sb .append (CodeAuthenticationMechanism .COOKIE_DELIM )
48
+ .append ("" )
49
+ .append (CodeAuthenticationMechanism .COOKIE_DELIM )
46
50
.append ("" )
47
51
.append (CodeAuthenticationMechanism .COOKIE_DELIM )
48
52
.append (tokens .getRefreshToken ());
@@ -60,11 +64,18 @@ public Uni<String> createTokenState(RoutingContext routingContext, OidcTenantCon
60
64
// By default, all three tokens are retained
61
65
if (oidcConfig .tokenStateManager ().strategy () == Strategy .KEEP_ALL_TOKENS ) {
62
66
67
+ StringBuilder sb = new StringBuilder ();
68
+
69
+ // Add access token and its expires_in property
70
+ sb .append (tokens .getAccessToken ())
71
+ .append (CodeAuthenticationMechanism .COOKIE_DELIM )
72
+ .append (tokens .getAccessTokenExpiresIn () != null ? tokens .getAccessTokenExpiresIn () : "" );
73
+
63
74
// Encrypt access token and create a `q_session_at` cookie.
64
75
CodeAuthenticationMechanism .createCookie (routingContext ,
65
76
oidcConfig ,
66
77
getAccessTokenCookieName (oidcConfig ),
67
- encryptToken (tokens . getAccessToken (), routingContext , oidcConfig ),
78
+ encryptToken (sb . toString (), routingContext , oidcConfig ),
68
79
routingContext .get (CodeAuthenticationMechanism .SESSION_MAX_AGE_PARAM ), true );
69
80
70
81
// Encrypt refresh token and create a `q_session_rt` cookie.
@@ -97,6 +108,7 @@ public Uni<AuthorizationCodeTokens> getTokens(RoutingContext routingContext, Oid
97
108
98
109
String idToken = null ;
99
110
String accessToken = null ;
111
+ Long accessTokenExpiresIn = null ;
100
112
String refreshToken = null ;
101
113
102
114
if (!oidcConfig .tokenStateManager ().splitTokens ()) {
@@ -113,9 +125,10 @@ public Uni<AuthorizationCodeTokens> getTokens(RoutingContext routingContext, Oid
113
125
114
126
if (oidcConfig .tokenStateManager ().strategy () == Strategy .KEEP_ALL_TOKENS ) {
115
127
accessToken = tokens [1 ];
116
- refreshToken = tokens [2 ];
128
+ accessTokenExpiresIn = tokens [2 ].isEmpty () ? null : Long .valueOf (tokens [2 ]);
129
+ refreshToken = tokens [3 ];
117
130
} else if (oidcConfig .tokenStateManager ().strategy () == Strategy .ID_REFRESH_TOKENS ) {
118
- refreshToken = tokens [2 ];
131
+ refreshToken = tokens [3 ];
119
132
}
120
133
} catch (ArrayIndexOutOfBoundsException ex ) {
121
134
return Uni .createFrom ().failure (new AuthenticationCompletionException ("Session cookie is malformed" ));
@@ -130,7 +143,14 @@ public Uni<AuthorizationCodeTokens> getTokens(RoutingContext routingContext, Oid
130
143
Cookie atCookie = getAccessTokenCookie (routingContext , oidcConfig );
131
144
if (atCookie != null ) {
132
145
// Decrypt access token from the q_session_at cookie
133
- accessToken = decryptToken (atCookie .getValue (), routingContext , oidcConfig );
146
+ String accessTokenState = decryptToken (atCookie .getValue (), routingContext , oidcConfig );
147
+ String [] accessTokenData = CodeAuthenticationMechanism .COOKIE_PATTERN .split (accessTokenState );
148
+ accessToken = accessTokenData [0 ];
149
+ try {
150
+ accessTokenExpiresIn = accessTokenData [1 ].isEmpty () ? null : Long .valueOf (accessTokenData [1 ]);
151
+ } catch (ArrayIndexOutOfBoundsException ex ) {
152
+ return Uni .createFrom ().failure (new AuthenticationCompletionException ("Session cookie is malformed" ));
153
+ }
134
154
}
135
155
Cookie rtCookie = getRefreshTokenCookie (routingContext , oidcConfig );
136
156
if (rtCookie != null ) {
@@ -144,7 +164,7 @@ public Uni<AuthorizationCodeTokens> getTokens(RoutingContext routingContext, Oid
144
164
}
145
165
}
146
166
}
147
- return Uni .createFrom ().item (new AuthorizationCodeTokens (idToken , accessToken , refreshToken ));
167
+ return Uni .createFrom ().item (new AuthorizationCodeTokens (idToken , accessToken , refreshToken , accessTokenExpiresIn ));
148
168
}
149
169
150
170
@ Override
0 commit comments