Skip to content

Commit

Permalink
Update OIDC Redis TokenStateManager to keep access token expires_in
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Jan 14, 2025
1 parent 54619a8 commit 8e17754
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public void testCodeFlow() throws IOException {

textPage = loginForm.getButtonByName("login").click();

assertEquals("alice", textPage.getContent());
assertEquals("alice, access token: true, access_token_expires_in: true, refresh_token: true",
textPage.getContent());

assertTokenStateCount(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import org.eclipse.microprofile.jwt.JsonWebToken;

import io.quarkus.oidc.AuthorizationCodeTokens;
import io.quarkus.oidc.IdToken;
import io.quarkus.security.Authenticated;
import io.vertx.ext.web.RoutingContext;

@Path("/protected")
@Authenticated
Expand All @@ -17,9 +19,16 @@ public class ProtectedResource {
@IdToken
JsonWebToken idToken;

@Inject
RoutingContext context;

@GET
public String getName() {
return idToken.getName();
AuthorizationCodeTokens tokens = context.get(AuthorizationCodeTokens.class.getName());
return idToken.getName()
+ ", access token: " + (tokens.getAccessToken() != null)
+ ", access_token_expires_in: " + (tokens.getAccessTokenExpiresIn() != null)
+ ", refresh_token: " + (tokens.getRefreshToken() != null);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ private static Instant expiresAt(RoutingContext event) {
return Instant.now().plusSeconds(event.<Long> get(SESSION_MAX_AGE_PARAM));
}

record AuthorizationCodeTokensRecord(String idToken, String accessToken, String refreshToken) {
record AuthorizationCodeTokensRecord(String idToken, String accessToken, String refreshToken, Long accessTokenExpiresIn) {

private static AuthorizationCodeTokensRecord of(AuthorizationCodeTokens tokens) {
return new AuthorizationCodeTokensRecord(tokens.getIdToken(), tokens.getAccessToken(), tokens.getRefreshToken());
return new AuthorizationCodeTokensRecord(tokens.getIdToken(), tokens.getAccessToken(), tokens.getRefreshToken(),
tokens.getAccessTokenExpiresIn());
}

private AuthorizationCodeTokens toTokens() {
return new AuthorizationCodeTokens(idToken, accessToken, refreshToken);
return new AuthorizationCodeTokens(idToken, accessToken, refreshToken, accessTokenExpiresIn);
}
}
}

0 comments on commit 8e17754

Please sign in to comment.