Examples of GoogleTokenResponse


Examples of com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse

            return null;
        }

        String decodedRefreshToken = codec.decodeString(userProfile.getAttribute(OAuthConstants.PROFILE_GOOGLE_REFRESH_TOKEN));
        String decodedScope = codec.decodeString(userProfile.getAttribute(OAuthConstants.PROFILE_GOOGLE_SCOPE));
        GoogleTokenResponse grc = new GoogleTokenResponse();
        grc.setAccessToken(decodedAccessToken);
        grc.setRefreshToken(decodedRefreshToken);
        grc.setTokenType("Bearer");
        grc.setExpiresInSeconds(1000L);
        grc.setIdToken("someTokenId");
        return new GoogleAccessTokenContext(grc, decodedScope);
    }
View Full Code Here

Examples of com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse

        }
    }

    @Override
    public void refreshToken(GoogleAccessTokenContext accessTokenContext) {
        GoogleTokenResponse tokenData = accessTokenContext.getTokenData();
        if (tokenData.getRefreshToken() == null) {
            throw new OAuthException(OAuthExceptionCode.GOOGLE_ERROR, "Given GoogleTokenResponse does not contain refreshToken");
        }

        try {
            GoogleRefreshTokenRequest refreshTokenRequest = new GoogleRefreshTokenRequest(TRANSPORT, JSON_FACTORY, tokenData.getRefreshToken(),
                    this.clientID, this.clientSecret);
            GoogleTokenResponse refreshed = refreshTokenRequest.execute();

            // Update only 'accessToken' with new value
            tokenData.setAccessToken(refreshed.getAccessToken());

            if (log.isTraceEnabled()) {
                log.trace("AccessToken refreshed successfully with value " + refreshed.getAccessToken());
            }
        } catch (IOException ioe) {
            throw new OAuthException(OAuthExceptionCode.GOOGLE_ERROR, ioe);
        }
    }
View Full Code Here

Examples of com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse

        .println("Please open the following URL in your browser then type the authorization code:");
    System.out.println("  " + url);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String code = br.readLine();

    GoogleTokenResponse response =
        flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI)
            .execute();

    flow.createAndStoreCredential(response, null);

    java.io.File accessTokenFile = new java.io.File("src/main/resources/access_token");
    Files.write(response.getAccessToken(), accessTokenFile, Charset.forName("UTF-8"));
    System.out.println("'src/main/resources/access_token' created/updated");
    System.out.println(response.getAccessToken());
    System.out.println();

    java.io.File refreshTokenFile = new java.io.File("src/main/resources/refresh_token");
    Files.write(response.getRefreshToken(), refreshTokenFile, Charset.forName("UTF-8"));
    System.out.println("'src/main/resources/refresh_token' created/updated");
    System.out.println(response.getRefreshToken());
  }
View Full Code Here

Examples of com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse

      // Authorize the OAuth2 token.
      GoogleAuthorizationCodeTokenRequest tokenRequest =
          authorizationFlow.newTokenRequest(authorizationCode);
      tokenRequest.setRedirectUri(CALLBACK_URL);
      GoogleTokenResponse tokenResponse = tokenRequest.execute();

      //  Create the credential.
      Credential credential = new GoogleCredential.Builder().setClientSecrets(clientId, clientSecret)
          .setJsonFactory(new JacksonFactory()).setTransport(new NetHttpTransport()).build().setFromTokenResponse(tokenResponse);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.