我在应用程序-engine上使用RemoteAPI进行谷歌身份验证(使用ClientLogin,已被弃用)。我想将其更改为Oauth2.0。我在谷歌上搜索了很多,但没有找到太多的解释。任何形式的帮助都将不胜感激。
public abstract class RemoteApiClient {
protected void doOperationRemotely() throws IOException {
TestProperties testProperties = TestProperties.inst();
System.out.println("--- Starting remote operation ---");
System.out.println("Going to connect to:"
+ testProperties.PROJECT_REMOTEAPI_APP_DOMAIN + ":"
+ testProperties.PROJECT_REMOTEAPI_APP_PORT);
RemoteApiOptions options = new RemoteApiOptions().server(
testProperties.PROJECT_REMOTEAPI_APP_DOMAIN,
testProperties.PROJECT_REMOTEAPI_APP_PORT).credentials(
testProperties.TEST_ADMIN_ACCOUNT,
testProperties.TEST_ADMIN_PASSWORD);
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
doOperation();
} finally {
installer.uninstall();
}
System.out.println("--- Remote operation completed ---");
}
}发布于 2016-05-18 14:35:16
对于OAuth2身份验证,在gcloud中有两种主要的解决方案。
gcloud
安装gcloud (https://cloud.google.com/sdk/),然后初始化它(https://cloud.google.com/sdk/docs/initializing)。在那之后,你应该去运行"gcloud auth login“,它会提示你在gmail上连接账户的认证窗口。
你的另一个解决方案是通过谷歌控制台创建一个新的服务帐户,提供一个json密钥,并在函数参数中将其作为凭据传递,或在GOOGLE_APPLICATION_CREDENTIALS环境变量中设置它,或使用gcloud auth activatve- service -account -- key -file "PATH_TO_JSON“。
创建服务帐户教程:https://developers.google.com/identity/protocols/OAuth2ServiceAccount#overview
gcloud默认身份验证相对于服务帐户(如下所述)的主要优势是,每个google cloud产品都会在一个固定位置检查application_credentials.json(well_known_file)文件。另一个优点是它的令牌可以在超过一个小时的会话中刷新。
https://stackoverflow.com/questions/35465014
复制相似问题