Search in sources :

Example 1 with AccessRefreshToken

use of io.micronaut.security.token.jwt.render.AccessRefreshToken in project micronaut-graphql by micronaut-projects.

the class LoginDataFetcher method accessTokenCookie.

private Optional<Cookie> accessTokenCookie(Authentication authentication, HttpRequest<?> request) {
    Optional<AccessRefreshToken> accessRefreshTokenOptional = accessRefreshTokenGenerator.generate(authentication);
    if (accessRefreshTokenOptional.isPresent()) {
        Cookie cookie = Cookie.of(cookieConfiguration.getCookieName(), accessRefreshTokenOptional.get().getAccessToken());
        cookie.configure(cookieConfiguration, request.isSecure());
        Optional<TemporalAmount> cookieMaxAge = cookieConfiguration.getCookieMaxAge();
        if (cookieMaxAge.isPresent()) {
            cookie.maxAge(cookieMaxAge.get());
        } else {
            cookie.maxAge(accessTokenConfiguration.getExpiration());
        }
        return Optional.of(cookie);
    }
    return Optional.empty();
}
Also used : Cookie(io.micronaut.http.cookie.Cookie) TemporalAmount(java.time.temporal.TemporalAmount) AccessRefreshToken(io.micronaut.security.token.jwt.render.AccessRefreshToken)

Aggregations

Cookie (io.micronaut.http.cookie.Cookie)1 AccessRefreshToken (io.micronaut.security.token.jwt.render.AccessRefreshToken)1 TemporalAmount (java.time.temporal.TemporalAmount)1