Examples of Credential


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

  }

  public void testMigrateTo() throws Exception {
    // create old store
    AppEngineCredentialStore store = new AppEngineCredentialStore();
    Credential expected = createCredential();
    store.store(USER_ID, expected);
    // migrate to new store
    AppEngineDataStoreFactory newFactory = new AppEngineDataStoreFactory();
    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

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

  }

  public void testLoadCredentials_empty() throws Exception {
    File file = createTempFile();
    FileCredentialStore store = new FileCredentialStore(file, JSON_FACTORY);
    Credential actual = createEmptyCredential();
    boolean loaded = store.load(USER_ID, actual);
    assertFalse(loaded);
    assertNull(actual.getAccessToken());
    assertNull(actual.getRefreshToken());
    assertNull(actual.getExpirationTimeMilliseconds());
  }
View Full Code Here

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

    assertNull(actual.getRefreshToken());
    assertNull(actual.getExpirationTimeMilliseconds());
  }

  public void testStoreCredentials() throws Exception {
    Credential expected = createCredential();
    File file = createTempFile();
    file.delete();
    FileCredentialStore store = new FileCredentialStore(file, JSON_FACTORY);
    store = new FileCredentialStore(file, JSON_FACTORY);
    store.store(USER_ID, expected);

    store = new FileCredentialStore(file, JSON_FACTORY);
    Credential actual = createEmptyCredential();
    boolean loaded = store.load(USER_ID, actual);
    assertTrue(loaded);
    assertEquals(ACCESS_TOKEN, actual.getAccessToken());
    assertEquals(REFRESH_TOKEN, actual.getRefreshToken());
    assertEquals(EXPIRES_IN, actual.getExpirationTimeMilliseconds().longValue());
  }
View Full Code Here

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

    assertEquals(REFRESH_TOKEN, actual.getRefreshToken());
    assertEquals(EXPIRES_IN, actual.getExpirationTimeMilliseconds().longValue());
  }

  public void testNotLoadCredentials() throws Exception {
    Credential expected = createCredential();
    FileCredentialStore store = new FileCredentialStore(createTempFile(), JSON_FACTORY);
    store.store(USER_ID, expected);
    try {
      store.load(USER_ID, null);
      fail("expected " + NullPointerException.class);
View Full Code Here

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

    FileCredentialStore store = new FileCredentialStore(createTempFile(), JSON_FACTORY);
    store.delete(USER_ID, createCredential());
  }

  private Credential createCredential() {
    Credential access = new Credential.Builder(
        BearerToken.queryParameterAccessMethod()).setTransport(new AccessTokenTransport())
        .setJsonFactory(JSON_FACTORY)
        .setTokenServerUrl(TOKEN_SERVER_URL)
        .setClientAuthentication(new BasicAuthentication(CLIENT_ID, CLIENT_SECRET))
        .build()
View Full Code Here

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

        .setExpirationTimeMilliseconds(EXPIRES_IN);
    return access;
  }

  private Credential createEmptyCredential() {
    Credential access = new Credential.Builder(
        BearerToken.queryParameterAccessMethod()).setTransport(new AccessTokenTransport())
        .setJsonFactory(JSON_FACTORY)
        .setTokenServerUrl(TOKEN_SERVER_URL)
        .setClientAuthentication(new BasicAuthentication(CLIENT_ID, CLIENT_SECRET))
        .build();
View Full Code Here

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

  public void testMigrateTo() throws Exception {
    // create old store
    File file = createTempFile();
    FileCredentialStore store = new FileCredentialStore(file, JSON_FACTORY);
    Credential expected = createCredential();
    store.store(USER_ID, expected);
    // migrate to new store
    File dataDir = Files.createTempDir();
    dataDir.deleteOnExit();
    FileDataStoreFactory newFactory = new FileDataStoreFactory(dataDir);
    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

Examples of com.google.api.client.extensions.auth.helpers.Credential

    ThreeLeggedFlow oauthFlow = newFlow(userId);
    oauthFlow.setJsonFactory(getJsonFactory());
    oauthFlow.setHttpTransport(getHttpTransport());

    try {
      Credential cred = oauthFlow.loadCredential(pm);

      if (cred != null && cred.isInvalid()) {
        pm.deletePersistent(cred);
        cred = null;
      }

      if (cred != null) {
        req.setAttribute(AUTH_CREDENTIAL, cred);
        try {
          // Invoke the user code
          super.service(req, resp);
        } catch (HttpResponseException e) {
          // Determine if we failed due to auth, or just failed
          if (cred.isInvalid()) {
            pm.deletePersistent(cred);
            startAuthFlow(resp, pm, oauthFlow);
          } else {
            throw e;
          }
View Full Code Here

Examples of com.google.appengine.repackaged.com.google.api.client.auth.oauth2.Credential

        String oauth2ClientId = null;
        String oauth2ClientSecret = null;
        String oauth2RefreshToken = null;
        OAuth2Native client = new OAuth2Native(useCookies, oauth2ClientId,
            oauth2ClientSecret, oauth2RefreshToken);
        Credential credential = client.authorize();

        if (credential == null || credential.getAccessToken() == null) {
            String errMsg = "Tokens expired? " + runOauth2Msg;
            throw new ConfigurationException(errMsg);
        }
        return credential.getAccessToken();
    }
View Full Code Here

Examples of com.google.gsa.Credential


        //First read the u/p the credentails store, in this case using the same as the root login
        logger.debug("HttpBasic: trying to get creds from repository ID: " +
                     id);
        Credential httpBasicCred = null;
        try {
            httpBasicCred = creds.getCredential(id);
        } catch (NullPointerException npe) {
            logger.error("NPE while reading credentials of ID: " + id);
        }
        if (httpBasicCred != null) {
            credentials =
                    new UsernamePasswordCredentials(httpBasicCred.getUsername(),
                                                    httpBasicCred.getPassword());
        } else {
            logger.debug("HttpBasic: trying to get creds from repository \"root\"");
            httpBasicCred = creds.getCredential("root");
            if (httpBasicCred != null) {
                logger.info("Trying with root credentails");
                credentials =
                        new UsernamePasswordCredentials(httpBasicCred.getUsername(),
                                                        httpBasicCred.getPassword());
            }
        }

        logger.debug("Authenticating");
        Header[] headers = null;
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.