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


Java GoogleClientSecrets.Details方法代码示例

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


在下文中一共展示了GoogleClientSecrets.Details方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //导入方法依赖的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

示例2: getClientSecrets

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //导入方法依赖的package包/类
public GoogleClientSecrets getClientSecrets() {
  GoogleClientSecrets secrets = new GoogleClientSecrets();
  Details details = new GoogleClientSecrets.Details();
  details.setClientId(clientId);
  details.setClientSecret(clientSecret);
  secrets.setWeb(details);
  return secrets;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:9,代码来源:GoogleAuthentication.java

示例3: TestApp

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //导入方法依赖的package包/类
public TestApp() {
	try
	{

		HttpTransport httpTransport = new NetHttpTransport();
		JacksonFactory jsonFactory = new JacksonFactory();

		GoogleClientSecrets clientSecrets =  new GoogleClientSecrets();
		GoogleClientSecrets.Details det = new GoogleClientSecrets.Details();
		det.setClientId("YOUR_CLIENT_ID");
		det.setClientSecret("YOUR_CLIENT_SECRET");
		det.setRedirectUris(Arrays.asList("urn:ietf:wg:oauth:2.0:oob"));
		clientSecrets.setInstalled(det);

		GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
		    httpTransport, jsonFactory, clientSecrets,
		    Arrays.asList(Oauth2Scopes.USERINFO_EMAIL)).build();
		Credential credential = new AuthorizationCodeInstalledApp(flow,
		    new LocalServerReceiver()).authorize("user");

		Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
		    .setApplicationName("oauth client").build();

		Userinfoplus ui = service.userinfo().get().execute();
		System.out.println(ui.getEmail());
	} 
	catch (Exception ex) {
		System.out.println("Error:  " + ex);
	}
}
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:31,代码来源:TestApp.java

示例4: getCredentialFromFileCredentialStoreForInstalledApp

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //导入方法依赖的package包/类
/**
 * Initialized OAuth2 credential for the "installed application" flow; where the credential
 * typically represents an actual end user (instead of a service account), and is stored as a
 * refresh token in a local FileCredentialStore.
 *
 * @param clientId OAuth2 client ID identifying the 'installed app'
 * @param clientSecret OAuth2 client secret
 * @param filePath full path to a ".json" file for storing the credential
 * @param scopes list of well-formed scopes desired in the credential
 * @param transport The HttpTransport used for authorization
 * @return credential with desired scopes, possibly obtained from loading {@code filePath}.
 * @throws IOException on IO error
 */
public Credential getCredentialFromFileCredentialStoreForInstalledApp(
    String clientId,
    String clientSecret,
    String filePath,
    List<String> scopes,
    HttpTransport transport)
    throws IOException, GeneralSecurityException {
  LOG.debug("getCredentialFromFileCredentialStoreForInstalledApp({}, {}, {}, {})",
      clientId, clientSecret, filePath, scopes);
  Preconditions.checkArgument(!Strings.isNullOrEmpty(clientId),
      "clientId must not be null or empty");
  Preconditions.checkArgument(!Strings.isNullOrEmpty(clientSecret),
      "clientSecret must not be null or empty");
  Preconditions.checkArgument(!Strings.isNullOrEmpty(filePath),
      "filePath must not be null or empty");
  Preconditions.checkArgument(scopes != null,
      "scopes must not be null or empty");

  // Initialize client secrets.
  GoogleClientSecrets.Details details = new GoogleClientSecrets.Details();
  details.setClientId(clientId);
  details.setClientSecret(clientSecret);
  GoogleClientSecrets clientSecrets = new GoogleClientSecrets();
  clientSecrets.setInstalled(details);

  // Set up file credential store.
  FileCredentialStore credentialStore =
      new FileCredentialStore(new File(filePath), JSON_FACTORY);

  // Set up authorization code flow.
  GoogleAuthorizationCodeFlow flow =
      new GoogleAuthorizationCodeFlow.Builder(transport, JSON_FACTORY, clientSecrets, scopes)
          .setCredentialStore(credentialStore)
          .setRequestInitializer(new CredentialHttpRetryInitializer())
          .build();

  // Authorize access.
  return new AuthorizationCodeInstalledApp(flow, new GooglePromptReceiver()).authorize("user");
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:53,代码来源:CredentialFactory.java

示例5: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //导入方法依赖的package包/类
/**
 * Authorizes the installed application to access user's protected data. if
 * possible, gets the credential from xml file at PathForXmlStore
 *
 * @param transport   HTTP transport
 * @param jsonFactory JSON factory
 * @param receiver    verification code receiver
 * @param scopes      OAuth 2.0 scopes
 */
public static Credential authorize(HttpTransport transport,
                                   JsonFactory jsonFactory, VerificationCodeReceiver receiver,
                                   List<String> scopes, String clientid, String clientsecret)
        throws Exception {

    BQXMLCredentialStore Store = new BQXMLCredentialStore(
            Oauth2Bigquery.PathForXmlStore);

    GoogleClientSecrets.Details details = new Details();
    details.setClientId(clientid);
    details.setClientSecret(clientsecret);
    details.set("Factory", CmdlineUtils.getJsonFactory());
    details.setAuthUri("https://accounts.google.com/o/oauth2/auth");
    details.setTokenUri("https://accounts.google.com/o/oauth2/token");
    GoogleClientSecrets secr = new GoogleClientSecrets()
            .setInstalled(details);
    GoogleCredential CredentialForReturn = new GoogleCredential.Builder()
            .setJsonFactory(CmdlineUtils.getJsonFactory())
            .setTransport(CmdlineUtils.getHttpTransport())
            .setClientSecrets(secr).build();
    if (Store.load(clientid + ":" + clientsecret, CredentialForReturn) == true) {
        return CredentialForReturn;
    }
    try {
        String redirectUri = receiver.getRedirectUri();
        GoogleClientSecrets clientSecrets = Oauth2Bigquery
                .loadClientSecrets(jsonFactory, clientid, clientsecret);
        Oauth2Bigquery.codeflow = new GoogleAuthorizationCodeFlow.Builder(
                transport, jsonFactory, clientSecrets, scopes)
                .setAccessType("offline").setApprovalPrompt("auto")
                .setCredentialStore(Store).build();
        Oauth2Bigquery.browse(Oauth2Bigquery.codeflow.newAuthorizationUrl()
                .setRedirectUri(redirectUri).build());
        // receive authorization code and exchange it for an access token
        String code = receiver.waitForCode();
        GoogleTokenResponse response = Oauth2Bigquery.codeflow
                .newTokenRequest(code).setRedirectUri(redirectUri)
                .execute();
        // store credential and return it
        // Also ads a RefreshListener, so the token will be always
        // automatically refreshed.
        return Oauth2Bigquery.codeflow.createAndStoreCredential(response,
                clientid + ":" + clientsecret);
    } finally {
        receiver.stop();
    }
}
 
开发者ID:jonathanswenson,项目名称:starschema-bigquery-jdbc,代码行数:57,代码来源:Oauth2Bigquery.java


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