當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。