@ POST @ Path ( "refresh" ) @ Consumes ( MediaType . APPLICATION_JSON ) public Response refreshAccessToken ( RefreshTokenRequest refreshToken ) { // Perform all validation here to control the exact error message returned to comply with the Oauth2 standard if ( null == refreshToken . getRefresh_token ( ) || null == refreshToken . getGrant_type ( ) ) { throw new BadRequestRestException ( ImmutableMap . of ( "error" , "invalid_request" ) ) ; } if ( ! REFRESH_TOKEN_GRANT_TYPE . equals ( refreshToken . getGrant_type ( ) ) ) { // Unsupported grant type throw new BadRequestRestException ( ImmutableMap . of ( "error" , "unsupported_grant_type" ) ) ; } DConnection connection = connectionDao . findByRefreshToken ( refreshToken . getRefresh_token ( ) ) ; if ( null == connection ) { throw new BadRequestRestException ( ImmutableMap . of ( "error" , "invalid_grant" ) ) ; } // Invalidate the old cache key connectionDao . invalidateCacheKey ( connection . getAccessToken ( ) ) ; connection . setAccessToken ( accessTokenGenerator . generate ( ) ) ; connection . setExpireTime ( calculateExpirationDate ( tokenExpiresIn ) ) ; connectionDao . putWithCacheKey ( connection . getAccessToken ( ) , connection ) ; return Response . ok ( ImmutableMap . builder ( ) . put ( "access_token" , connection . getAccessToken ( ) ) . put ( "refresh_token" , connection . getRefreshToken ( ) ) . put ( "expires_in" , tokenExpiresIn ) . build ( ) ) . cookie ( createCookie ( connection . getAccessToken ( ) , tokenExpiresIn ) ) . build ( ) ; }
Refresh an access_token using the refresh token