本文整理汇总了Java中com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver类的典型用法代码示例。如果您正苦于以下问题:Java GooglePromptReceiver类的具体用法?Java GooglePromptReceiver怎么用?Java GooglePromptReceiver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GooglePromptReceiver类属于com.google.api.client.googleapis.extensions.java6.auth.oauth2包,在下文中一共展示了GooglePromptReceiver类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: authorize
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*/
public static Credential authorize() throws IOException {
// Load client secrets.
final byte[] bytes = Files.toByteArray(new File(clientSecretFile));
final GoogleClientSecrets clientSecrets = GoogleClientSecrets
.load(JSON_FACTORY, new InputStreamReader(new ByteArrayInputStream(bytes)));
if (clientSecrets.getDetails().getClientId() == null
|| clientSecrets.getDetails().getClientSecret() == null) {
throw new IllegalStateException("client_secrets not well formed.");
}
// Set up authorization code flow.
// Ask for only the permissions you need. Asking for more permissions will
// reduce the number of users who finish the process for giving you access
// to their accounts. It will also increase the amount of effort you will
// have to spend explaining to users what you are doing with their data.
// Here we are listing all of the available scopes. You should remove scopes
// that you are not actually using.
final Set<String> scopes = new HashSet<String>();
scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
scopes.add(StorageScopes.DEVSTORAGE_READ_ONLY);
scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE);
final GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets,
scopes).setDataStoreFactory(dataStoreFactory).build();
// Authorize.
final VerificationCodeReceiver receiver =
AUTH_LOCAL_WEBSERVER ? new LocalServerReceiver() : new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
开发者ID:DevOps-TangoMe,项目名称:gcloud-storage-speedtest,代码行数:35,代码来源:CredentialsManager.java
示例2: getCredentialFromFileCredentialStoreForInstalledApp
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的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
示例3: authorize
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的package包/类
/** Authorizes the installed application to access user's protected data. */
private static Credential authorize() throws Exception {
// Load client secrets.
GoogleClientSecrets clientSecrets = null;
try {
clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(StorageSample.class.getResourceAsStream(String.format("/%s",CLIENT_SECRET_FILENAME))));
if (clientSecrets.getDetails().getClientId() == null ||
clientSecrets.getDetails().getClientSecret() == null) {
throw new Exception("client_secrets not well formed.");
}
} catch (Exception e) {
System.out.println("Problem loading client_secrets.json file. Make sure it exists, you are " +
"loading it with the right path, and a client ID and client secret are " +
"defined in it.\n" + e.getMessage());
System.exit(1);
}
// Set up authorization code flow.
// Ask for only the permissions you need. Asking for more permissions will
// reduce the number of users who finish the process for giving you access
// to their accounts. It will also increase the amount of effort you will
// have to spend explaining to users what you are doing with their data.
// Here we are listing all of the available scopes. You should remove scopes
// that you are not actually using.
Set<String> scopes = new HashSet<String>();
scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
scopes.add(StorageScopes.DEVSTORAGE_READ_ONLY);
scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, JSON_FACTORY, clientSecrets, scopes)
.setDataStoreFactory(dataStoreFactory)
.build();
// Authorize.
VerificationCodeReceiver receiver =
AUTH_LOCAL_WEBSERVER ? new LocalServerReceiver() : new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-storage-docs-json-api-examples,代码行数:40,代码来源:StorageSample.java
示例4: authorizeUser
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*/
private Credential authorizeUser(GoogleClientSecrets clientSecrets) throws Exception
{
// set up file credential store
//CredentialStore credentialStore = new MemoryCredentialStore();
CredentialStore credentialStore = new FileCredentialStore(new java.io.File(CREDENTIAL_FILE), JSON_FACTORY);
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setCredentialStore(credentialStore).build();
// authorize
VerificationCodeReceiver receiver = new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
开发者ID:mkrause,项目名称:gx,代码行数:18,代码来源:GooglePromptAuthorizer.java
示例5: authorizeUser
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*/
private static Credential authorizeUser(GoogleClientSecrets clientSecrets) throws Exception
{
// set up file credential store
//CredentialStore credentialStore = new MemoryCredentialStore();
CredentialStore credentialStore = new FileCredentialStore(new java.io.File(CREDENTIAL_FILE), JSON_FACTORY);
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setCredentialStore(credentialStore).build();
// authorize
VerificationCodeReceiver receiver = new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
开发者ID:mkrause,项目名称:gx,代码行数:18,代码来源:BrowserChannelTest.java
注:本文中的com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论