Package com.google.api.client.auth.oauth2

Examples of com.google.api.client.auth.oauth2.ClientParametersAuthenticationTest


    store.migrateTo(newFactory);
    // check new store
    DataStore<StoredCredential> newStore =
        newFactory.getDataStore(StoredCredential.DEFAULT_DATA_STORE_ID);
    assertEquals(ImmutableSet.of(USER_ID), newStore.keySet());
    StoredCredential actual = newStore.get(USER_ID);
    assertEquals(expected.getAccessToken(), actual.getAccessToken());
    assertEquals(expected.getRefreshToken(), actual.getRefreshToken());
    assertEquals(expected.getExpirationTimeMilliseconds(), actual.getExpirationTimeMilliseconds());
  }
View Full Code Here


    refreshToken = credential.getRefreshToken();
    expirationTimeMillis = credential.getExpirationTimeMilliseconds();
  }

  StoredCredential toStoredCredential() {
    return new StoredCredential().setAccessToken(accessToken)
        .setRefreshToken(refreshToken).setExpirationTimeMilliseconds(expirationTimeMillis);
  }
View Full Code Here

   */
  public final void migrateTo(DataStore<StoredCredential> credentialDataStore) throws IOException {
    DatastoreService service = DatastoreServiceFactory.getDatastoreService();
    PreparedQuery queryResult = service.prepare(new Query(KIND));
    for (Entity entity : queryResult.asIterable()) {
      StoredCredential storedCredential = new StoredCredential().setAccessToken(
          (String) entity.getProperty("accessToken"))
          .setRefreshToken((String) entity.getProperty("refreshToken"))
          .setExpirationTimeMilliseconds((Long) entity.getProperty("expirationTimeMillis"));
      credentialDataStore.set(entity.getKey().getName(), storedCredential);
    }
View Full Code Here

        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setContentType("UTF-8");
          GenericData responseData;
          if (error) {
            TokenErrorResponse json = new TokenErrorResponse();
            json.setError("invalid_client");
            responseData = json;
            response.setStatusCode(400);
          } else {
            TokenResponse json = new TokenResponse();
            json.setAccessToken(NEW_ACCESS_TOKEN);
            json.setRefreshToken(NEW_REFRESH_TOKEN);
            json.setExpiresInSeconds(EXPIRES_IN);
            responseData = json;
          }
          response.setContent(JSON_FACTORY.toString(responseData));
          return response;
        }
View Full Code Here

        .setPrincipal(serviceAccountUser);
    payload.put("scope", serviceAccountScopes);
    try {
      String assertion =
          RsaSHA256Signer.sign(serviceAccountPrivateKey, getJsonFactory(), header, payload);
      TokenRequest request = new TokenRequest(getTransport(), getJsonFactory(), new GenericUrl(
          getTokenServerEncodedUrl()), "assertion");
      request.put("assertion_type", "http://oauth.net/grant_type/jwt/1.0/bearer");
      request.put("assertion", assertion);
      return request.execute();
    } catch (GeneralSecurityException exception) {
      IOException e = new IOException();
      e.initCause(exception);
      throw e;
    }
View Full Code Here

    payload.setSubject(serviceAccountUser);
    payload.put("scope", Joiner.on(' ').join(serviceAccountScopes));
    try {
      String assertion = JsonWebSignature.signUsingRsaSha256(
          serviceAccountPrivateKey, getJsonFactory(), header, payload);
      TokenRequest request = new TokenRequest(
          getTransport(), getJsonFactory(), new GenericUrl(getTokenServerEncodedUrl()),
          "urn:ietf:params:oauth:grant-type:jwt-bearer");
      request.put("assertion", assertion);
      return request.execute();
    } catch (GeneralSecurityException exception) {
      IOException e = new IOException();
      e.initCause(exception);
      throw e;
    }
View Full Code Here

    payload.setSubject(serviceAccountUser);
    payload.put("scope", Joiner.on(' ').join(serviceAccountScopes));
    try {
      String assertion = JsonWebSignature.signUsingRsaSha256(
          serviceAccountPrivateKey, getJsonFactory(), header, payload);
      TokenRequest request = new TokenRequest(
          getTransport(), getJsonFactory(), new GenericUrl(getTokenServerEncodedUrl()),
          "urn:ietf:params:oauth:grant-type:jwt-bearer");
      request.put("assertion", assertion);
      return request.execute();
    } catch (GeneralSecurityException exception) {
      IOException e = new IOException();
      e.initCause(exception);
      throw e;
    }
View Full Code Here

            TokenErrorResponse json = new TokenErrorResponse();
            json.setError("invalid_client");
            responseData = json;
            response.setStatusCode(400);
          } else {
            TokenResponse json = new TokenResponse();
            json.setAccessToken(NEW_ACCESS_TOKEN);
            json.setRefreshToken(NEW_REFRESH_TOKEN);
            json.setExpiresInSeconds(EXPIRES_IN);
            responseData = json;
          }
          response.setContent(JSON_FACTORY.toString(responseData));
          return response;
        }
View Full Code Here

      lock.lock();
      try {
        if (flow == null) {
          flow = initializeFlow();
        }
        TokenResponse response = flow.newTokenRequest(code).setRedirectUri(redirectUri).execute();
        String userId = getUserId(req);
        Credential credential = flow.createAndStoreCredential(response, userId);
        onSuccess(req, resp, credential);
      } finally {
        lock.unlock();
View Full Code Here

    }

    private Analytics initializeAnalytics() {
        if (analytics == null) {
            GoogleAnalyticsProvider provider = new GoogleAnalyticsProvider();
            TokenResponse tokenResponse = new TokenResponse().setRefreshToken(getConnectionCredentials().getOauthRefreshToken());
            GoogleCredential credential = new GoogleCredential.Builder()
                    .setJsonFactory(jsonFactory)
                    .setTransport(transport)
                    .setClientSecrets(provider.getClientId(), provider.getClientSecret())
                    .build()
View Full Code Here

TOP

Related Classes of com.google.api.client.auth.oauth2.ClientParametersAuthenticationTest

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.