Package com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest

Examples of com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant


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

    // Store the credential for the user.
    authorizationFlow.createAndStoreCredential(tokenResponse, userId);
  }
View Full Code Here


  public OAuthRequestHelper(
      @Flag(FlagName.OAUTH_CLIENT_ID) String clientId,
      @Flag(FlagName.OAUTH_CLIENT_SECRET) String clientSecret,
      UserContext userContext) {
    this.userContext = userContext;
    this.accessThing = new GoogleAccessProtectedResource(
        getCredentials().getAccessToken(),
        new UrlFetchTransport(), new JacksonFactory(), clientId, clientSecret,
        getCredentials().getRefreshToken());
  }
View Full Code Here

  private final UserContext userContext;
  private final GoogleAccessProtectedResource accessThing;

  public OAuthRequestHelper(String clientId, String clientSecret, UserContext userContext) {
    this.userContext = userContext;
    this.accessThing = new GoogleAccessProtectedResource(
        getCredentials().getAccessToken(),
        new ApacheHttpTransport(), new JacksonFactory(), clientId, clientSecret,
        getCredentials().getRefreshToken());
  }
View Full Code Here

    AccessTokenResponse authResponse = authRequest.execute();

    accessToken = authResponse.accessToken;
    refreshToken = authResponse.refreshToken;

    GoogleAccessProtectedResource access = new GoogleAccessProtectedResource(accessToken, transport,
        factory, clientId, clientSecret, refreshToken);
    access.refreshToken();
  }
View Full Code Here

    String code = requireParameter(req, "code");
    log.info("code=" + code);

    log.info("clientId=" + clientId + ", clientSecret=" + clientSecret + ", code=" + code
        + ", callbackUrl=" + callbackUrl);
    GoogleAuthorizationCodeGrant authRequest = new GoogleAuthorizationCodeGrant(
        new UrlFetchTransport(), new JacksonFactory(), clientId, clientSecret, code, callbackUrl);

    AccessTokenResponse authResponse;
    try {
      authResponse = authRequest.execute();
    } catch (IOException e) {
      log.log(Level.WARNING, "Failed attempt, trying again", e);
      if (e instanceof HttpResponseException) {
        HttpResponseException f = (HttpResponseException) e;
        ByteArrayOutputStream o = new ByteArrayOutputStream();
View Full Code Here

    logger.info("Oauth response code is: " + code);
    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();
    ModelAndView mv = new ModelAndView();
    try {
      AccessTokenResponse googleResponse = new GoogleAuthorizationCodeGrant(
          httpTransport, jsonFactory, clientId, clientSecret, code,
          redirectUrl).execute();
      String accessToken = googleResponse.accessToken;
      String refreshToken = googleResponse.refreshToken;
View Full Code Here

    HttpTransport transport = new NetHttpTransport();
    JsonFactory factory = new JacksonFactory();

    // Exchange for an access and refresh token
    GoogleAuthorizationCodeGrant authRequest = new GoogleAuthorizationCodeGrant(transport,
        factory, clientId, clientSecret, authorizationCode, AUTH_REDIRECT_URI);
    authRequest.useBasicAuthorization = false;
    AccessTokenResponse authResponse = authRequest.execute();

    accessToken = authResponse.accessToken;
    refreshToken = authResponse.refreshToken;

    GoogleAccessProtectedResource access = new GoogleAccessProtectedResource(accessToken, transport,
View Full Code Here

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String userEmail = user.getEmail();
    String originalRequest = requireParameter(req, "originalRequest");
    String authorizeUrl =
        new GoogleAuthorizationRequestUrl(clientId, callbackPath, oAuthScopes).build()
        // TODO(ohler): Find out if GoogleAuthorizationRequestUrl offers an API
        // to do this rather than appending the literal string.  Also consider
        // using server-side auto-approval rather than offline access ("perform
        // these operations when I'm not using the application") since that's
        // scary -- but import is meant to be able to run in the background over
View Full Code Here

  protected final Log logger = LogFactory.getLog(getClass());

  @RequestMapping(method = RequestMethod.GET)
  public void redirectToGoogle(HttpServletResponse response) {
    logger.info(redirectUrl + " - " + scope + " - " + clientId);
    String authorizationUrl = new GoogleAuthorizationRequestUrl(clientId,
        redirectUrl, scope).build();
    try {
      response.sendRedirect(authorizationUrl);
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

   * manual http://code.google.com/apis/accounts/docs/OAuth2InstalledApp.html
   * example http://code.google.com/p/google-api-java-client/wiki/OAuth2Draft10
   */
  public void authorizeToGoogle() throws IOException {
    // Generate the URL to which we will direct users
    GoogleAuthorizationRequestUrl authUrl = new GoogleAuthorizationRequestUrl(
        clientId, AUTH_REDIRECT_URI, AUTH_RPC);
    String authorizeUrl = authUrl.build();
    System.out.println("Paste this URL in your browser:\n" + authorizeUrl);

    // Wait for the authorization code
    System.out.println("Type the code you received here: ");
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
View Full Code Here

TOP

Related Classes of com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant

Copyright © 2018 www.massapicom. 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.