use of io.micronaut.security.token.event.AccessTokenGeneratedEvent in project micronaut-security by micronaut-projects.
the class DefaultAccessRefreshTokenGenerator method generate.
/**
* Generate an {@link AccessRefreshToken} response for the given
* refresh token and claims.
*
* @param refreshToken The refresh token
* @param oldClaims The claims to generate the access token
* @return The http response
*/
@NonNull
public Optional<AccessRefreshToken> generate(@Nullable String refreshToken, @NonNull Map<String, ?> oldClaims) {
Map<String, Object> claims = claimsGenerator.generateClaimsSet(oldClaims, accessTokenExpiration(oldClaims));
Optional<String> optionalAccessToken = tokenGenerator.generateToken(claims);
if (!optionalAccessToken.isPresent()) {
debug(LOG, "tokenGenerator failed to generate access token claims: {}", claims.entrySet().stream().map(entry -> entry.getKey() + "=>" + entry.getValue().toString()).collect(Collectors.joining(", ")));
return Optional.empty();
}
String accessToken = optionalAccessToken.get();
eventPublisher.publishEvent(new AccessTokenGeneratedEvent(accessToken));
return Optional.of(tokenRenderer.render(accessTokenExpiration(oldClaims), accessToken, refreshToken));
}
use of io.micronaut.security.token.event.AccessTokenGeneratedEvent in project micronaut-security by micronaut-projects.
the class DefaultAccessRefreshTokenGenerator method generate.
/**
* Generate a new access refresh token.
*
* @param refreshToken The refresh token
* @param authentication The user details to create a new access token
* @return The optional access refresh token
*/
@NonNull
@Override
public Optional<AccessRefreshToken> generate(@Nullable String refreshToken, @NonNull Authentication authentication) {
Optional<String> optionalAccessToken = tokenGenerator.generateToken(authentication, accessTokenExpiration(authentication));
if (!optionalAccessToken.isPresent()) {
debug(LOG, "Failed to generate access token for user {}", authentication.getName());
return Optional.empty();
}
String accessToken = optionalAccessToken.get();
eventPublisher.publishEvent(new AccessTokenGeneratedEvent(accessToken));
return Optional.of(tokenRenderer.render(authentication, accessTokenExpiration(authentication), accessToken, refreshToken));
}
Aggregations