当前位置: 首页>>代码示例>>Java>>正文


Java StoredCredential类代码示例

本文整理汇总了Java中com.google.api.client.auth.oauth2.StoredCredential的典型用法代码示例。如果您正苦于以下问题:Java StoredCredential类的具体用法?Java StoredCredential怎么用?Java StoredCredential使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StoredCredential类属于com.google.api.client.auth.oauth2包,在下文中一共展示了StoredCredential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authorize

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
/**
 * Authorizes the installed application to access user's protected data.
 *
 * @param scopes list of scopes needed to run youtube upload.
 * @param clientSecret the client secret from Google API console
 * @param credentialDatastore name of the credential datastore to cache OAuth tokens
 */
public static Credential authorize(
    Collection<String> scopes, String clientSecret, String credentialDatastore)
    throws IOException {
  // Load client secrets
  GoogleClientSecrets clientSecrets =
      GoogleClientSecrets.load(JSON_FACTORY, new StringReader(clientSecret));

  // This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
  FileDataStoreFactory fileDataStoreFactory =
      new FileDataStoreFactory(new File(getCredentialsDirectory()));
  DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

  GoogleAuthorizationCodeFlow flow =
      new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes)
          .setCredentialDataStore(datastore)
          .build();

  // authorize
  return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
 
开发者ID:youtube,项目名称:youtube-chat-for-minecraft,代码行数:28,代码来源:Auth.java

示例2: loadCredential

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
private static Credential loadCredential(String userId, DataStore<StoredCredential> credentialDataStore)
        throws IOException {
    Credential credential = newCredential(userId, credentialDataStore);
    if (credentialDataStore != null) {
        StoredCredential stored = credentialDataStore.get(userId);
        if (stored == null) {
            return null;
        }
        credential.setAccessToken(stored.getAccessToken());
        credential.setRefreshToken(stored.getRefreshToken());
        credential.setExpirationTimeMilliseconds(stored.getExpirationTimeMilliseconds());
        if (logger.isDebugEnabled()) {
            logger.debug("Loaded credential");
            logger.debug("device access token: {}", stored.getAccessToken());
            logger.debug("device refresh_token: {}", stored.getRefreshToken());
            logger.debug("device expires_in: {}", stored.getExpirationTimeMilliseconds());
        }
    }
    return credential;
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:21,代码来源:GCalGoogleOAuth.java

示例3: authorize

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {

        Reader clientSecretReader = new InputStreamReader(Auth.class.getResourceAsStream("/client_secrets.json"));
        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);

        if (clientSecrets.getDetails().getClientId().startsWith("Enter")
                || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
            System.out.println(
                    "Enter Client ID and Secret from https://console.developers.google.com/project/_/apiui/credential "
                            + "into src/main/resources/client_secrets.json");
            System.exit(1);
        }

        FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
        DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
                .build();

        LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

        return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
    }
 
开发者ID:prakamya-mishra,项目名称:Shield,代码行数:25,代码来源:Auth.java

示例4: deleteCredentials

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
public void deleteCredentials() throws IOException {
	if (getState() != State.disconnected) {
		throw new IOException("Cannot delete file store while connected");
	}
	synchronized (this) {
		this.userInfo = null;
	}
	File file = new File(dataStoreDir, StoredCredential.DEFAULT_DATA_STORE_ID);
	if (file.exists()) {
		java.nio.file.Files.delete(file.toPath());
	}
	File userInfoFile = new File(dataStoreDir, GDriveConnectionManager.USER_FILENAME);
	if (userInfoFile.exists()) {
		java.nio.file.Files.delete(userInfoFile.toPath());
	}
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:17,代码来源:GDriveConnectionManager.java

示例5: authorize

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
/**
 * Perform the authorisation for the youtube account
 *
 * @param scopes              {@linkplain List} of scopes to perform
 *                            authorization
 * @param credentailDataStore name of the credential datastore
 *
 * @return {@linkplain Credential} object which is used for Requests
 *
 * @throws IOException an error occurs during the authorisation.
 *
 * @since 1.0
 */
public static Credential authorize(List<String> scopes,
        String credentailDataStore)
        throws IOException {
    final Reader reader = new InputStreamReader(Auth.class.
            getResourceAsStream("/youtube.json"));
    final GoogleClientSecrets secrets = GoogleClientSecrets.load(
            JSON_FACTORY, reader);
    final FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(
            Paths.get(System
                    .getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY).
            toFile());
    final DataStore<StoredCredential> dataStore = dataStoreFactory.
            getDataStore(credentailDataStore);
    final GoogleAuthorizationCodeFlow flow
            = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT,
                    JSON_FACTORY,
                    secrets, scopes).setCredentialDataStore(dataStore).
            build();
    final LocalServerReceiver receiver = new LocalServerReceiver.Builder().
            setPort(8080).build();

    return new AuthorizationCodeInstalledApp(flow, receiver).authorize(
            config.userId());
}
 
开发者ID:LehmRob,项目名称:FeedMeYoutube,代码行数:38,代码来源:Auth.java

示例6: authorize

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {
	Reader clientSecretReader = new InputStreamReader(YTAuth.class.getResourceAsStream("/client_secrets.json"));
	GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);

	if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
		System.out.println("Enter Client ID and Secret from https://code.google.com/apis/console/?api=youtube into src/main/resources/client_secres.json");
		System.exit(1);
	}

	FileDataStoreFactory fileDataStoreFactory= new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
	DataStore<StoredCredential> dataStore = fileDataStoreFactory.getDataStore(credentialDatastore);

	GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(dataStore).build();
	LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

	return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}
 
开发者ID:MCUpdater,项目名称:RavenBot,代码行数:18,代码来源:YTAuth.java

示例7: authorize

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
static Credential authorize(String clientId, String clientSecret, String credentialsPath, String credentialStore,
                            HttpTransport httpTransport, JsonFactory jsonFactory) throws IOException {
    GoogleClientSecrets.Details installedDetails = new GoogleClientSecrets.Details();
    installedDetails.setClientId(clientId);
    installedDetails.setClientSecret(clientSecret);

    GoogleClientSecrets clientSecrets = new GoogleClientSecrets();
    clientSecrets.setInstalled(installedDetails);

    FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new java.io.File(credentialsPath));
    DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialStore);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory,
            clientSecrets, Collections.singleton(DriveScopes.DRIVE_FILE))
            .setCredentialDataStore(datastore)
            .build();

    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
 
开发者ID:donbeave,项目名称:grails-google-drive,代码行数:20,代码来源:GoogleDrive.java

示例8: storeOAuth2TokenData

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
/**
 * Stores the given OAuth 2 token response within a file data store.
 * The stored token response can then retrieved using the getOAuth2TokenDataFromStore method.
 *
 * @param storageId a string object that is used to store the token response
 * @param tokenResponse the token response containing the OAuth 2 token information.
 * @return If the token response was stored or not.
 */
public Boolean storeOAuth2TokenData(String storageId, TokenResponse tokenResponse) {
    Boolean wasStored = false;
    try {
        File oauth2StorageFolder = new File(this.context.getFilesDir(),"oauth2StorageFolder");
        oauth2StorageFolder.mkdirs();
        FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(oauth2StorageFolder);
        DataStore<StoredCredential> storedCredentialDataStore = fileDataStoreFactory.getDataStore(storageId);
        Credential oauth2Credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setFromTokenResponse(
                tokenResponse);
        StoredCredential storedOAuth2Credential = new StoredCredential(oauth2Credential);
        storedCredentialDataStore.set(storageId,storedOAuth2Credential);
        wasStored = true;
    } catch ( Exception exception ) {
        logInfo("Exception storing OAuth2TokenData :" + exception.getLocalizedMessage());
    }
    return wasStored;
}
 
开发者ID:apigee,项目名称:apigee-android-sdk,代码行数:26,代码来源:ApigeeDataClient.java

示例9: test_provideCredential

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
@Test
public void test_provideCredential() throws Exception {
  when(dataStore.get("UNITTEST-CLIENT-ID scope1")).thenReturn(
      new StoredCredential(FAKE_CREDENTIAL));
  Credential cred = getCredential();
  assertThat(cred.getAccessToken()).isEqualTo(FAKE_CREDENTIAL.getAccessToken());
  assertThat(cred.getRefreshToken()).isEqualTo(FAKE_CREDENTIAL.getRefreshToken());
  assertThat(cred.getExpirationTimeMilliseconds()).isEqualTo(
      FAKE_CREDENTIAL.getExpirationTimeMilliseconds());
}
 
开发者ID:google,项目名称:nomulus,代码行数:11,代码来源:AuthModuleTest.java

示例10: authorize

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
/**
 * Authorizes the installed application to access user's protected data.
 *
 * @param scopes              list of scopes needed to run youtube upload.
 * @param credentialDatastore name of the credential datastore to cache OAuth tokens
 */
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {

    // Load client secrets.
    Reader clientSecretReader = new InputStreamReader(Authorizer.class.getResourceAsStream("/client_secrets.json"));
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);

    // Checks that the defaults have been replaced (Default = "Enter X here").
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        System.out.println(
                "Enter Client ID and Secret from https://code.google.com/apis/console/?api=youtube"
                        + "into src/main/resources/client_secrets.json");
        System.exit(1);
    }

    // This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
    FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
    DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
            .build();

    // Build the local server and bind it to port 8080
    LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

    // Authorize.
    return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}
 
开发者ID:ashwinswaroop,项目名称:YouTubeBot,代码行数:36,代码来源:Authorizer.java

示例11: getStoredCredentialDataStore

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
private DataStore<StoredCredential> getStoredCredentialDataStore()
    throws IOException {
  File userHomeDir = getUserHomeDir();
  File mailimporter = new File(userHomeDir, ".mailimporter");
  FileDataStoreFactory dataStoreFactory =
      new FileDataStoreFactory(mailimporter);
  return dataStoreFactory.getDataStore("credentials");
}
 
开发者ID:google,项目名称:mail-importer,代码行数:9,代码来源:Authorizer.java

示例12: authorize

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
/**
 * Authorizes the installed application to access user's protected data.
 *
 * @param scopes              list of scopes needed to run youtube upload.
 * @param credentialDatastore name of the credential datastore to cache OAuth tokens
 */
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {

    // Load client secrets.
    Reader clientSecretReader = new InputStreamReader(Auth.class.getResourceAsStream("/client_secrets.json"));
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);

    // Checks that the defaults have been replaced (Default = "Enter X here").
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        System.out.println(
                "Enter Client ID and Secret from https://code.google.com/apis/console/?api=youtube"
                        + "into src/main/resources/client_secrets.json");
        System.exit(1);
    }

    // This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
    FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
    DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
            .build();

    // Build the local server and bind it to port 8080
    LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

    // Authorize.
    return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}
 
开发者ID:HearthStats,项目名称:HearthStats.net-Uploader,代码行数:36,代码来源:Auth.java

示例13: values

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
public Collection<StoredCredential> values() throws IOException {
  HashSet<StoredCredential> hash = new HashSet<StoredCredential>();
  if (token != null) {
    hash.add(get(UNUSED_ID));
  }
  return hash;
}
 
开发者ID:googleads,项目名称:googleads-shopping-samples,代码行数:8,代码来源:ConfigDataStoreFactory.java

示例14: set

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
public DataStore<StoredCredential> set(String key, StoredCredential value) throws IOException {
  if (key != UNUSED_ID) {
    throw new IOException("Unexpected real user ID");
  }
  token = Token.fromStoredCredential(value);
  writeToken();
  return this;
}
 
开发者ID:googleads,项目名称:googleads-shopping-samples,代码行数:9,代码来源:ConfigDataStoreFactory.java

示例15: fromStoredCredential

import com.google.api.client.auth.oauth2.StoredCredential; //导入依赖的package包/类
public static Token fromStoredCredential(StoredCredential credential) {
  Token token = new Token();
  token.setAccessToken(credential.getAccessToken());
  token.setRefreshToken(credential.getRefreshToken());
  token.setExpirationTimeMilliseconds(credential.getExpirationTimeMilliseconds());
  return token;
}
 
开发者ID:googleads,项目名称:googleads-shopping-samples,代码行数:8,代码来源:Token.java


注:本文中的com.google.api.client.auth.oauth2.StoredCredential类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。