Example usage for com.amazonaws.services.cognitoidp.model AuthenticationResultType getRefreshToken

List of usage examples for com.amazonaws.services.cognitoidp.model AuthenticationResultType getRefreshToken

Introduction

In this page you can find the example usage for com.amazonaws.services.cognitoidp.model AuthenticationResultType getRefreshToken.

Prototype


public String getRefreshToken() 

Source Link

Document

The refresh token.

Usage

From source file:com.kdgregory.example.cognito.servlets.AbstractCognitoServlet.java

License:Apache License

/**
 *  Updates the access and refresh tokens, stored in cookies in the response.
 *  Note that refresh token is optional -- on a refresh, we just get a new
 *  access token./*from  w w  w .j a  v a  2s .c o  m*/
 *  <p>
 *  Note: also updates the token cache.
 */
protected void updateCredentialCookies(HttpServletResponse response, AuthenticationResultType authResult) {
    tokenCache.addToken(authResult.getAccessToken());

    Cookie accessTokenCookie = new Cookie(Constants.CookieNames.ACCESS_TOKEN, authResult.getAccessToken());
    response.addCookie(accessTokenCookie);

    if (!StringUtil.isBlank(authResult.getRefreshToken())) {
        Cookie refreshTokenCookie = new Cookie(Constants.CookieNames.REFRESH_TOKEN,
                authResult.getRefreshToken());
        response.addCookie(refreshTokenCookie);
    }
}

From source file:io.fineo.client.auth.cognito.CognitoUser.java

License:Open Source License

/**
 * Creates a user session with the tokens from authentication and overrider the refresh token
 * with the value passed./* w ww .  j ava 2  s .  com*/
 *
 * @param authResult                        REQUIRED: Authentication result which contains the
 *                                          tokens.
 * @param refreshTokenOverride              REQUIRED: This will be used to create a new session
 *                                          object if it is not null.
 * @return {@link CognitoUserSession} with the latest tokens.
 */
private CognitoUserSession getCognitoUserSession(AuthenticationResultType authResult,
        CognitoRefreshToken refreshTokenOverride) {
    String idtoken = authResult.getIdToken();
    CognitoIdToken idToken = new CognitoIdToken(idtoken);

    String acctoken = authResult.getAccessToken();
    CognitoAccessToken accessToken = new CognitoAccessToken(acctoken);

    CognitoRefreshToken refreshToken;

    if (refreshTokenOverride != null) {
        refreshToken = refreshTokenOverride;
    } else {
        String reftoken = authResult.getRefreshToken();
        refreshToken = new CognitoRefreshToken(reftoken);
    }
    return new CognitoUserSession(idToken, accessToken, refreshToken);
}