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

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

Introduction

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

Prototype


public String getAccessToken() 

Source Link

Document

The access 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 ww w  .  j  a  va2s  .  co  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 av a 2  s  .  c o m*/
 *
 * @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);
}