[英]Remote API , ClientLogin to Oauth2.0
我正在使用RemoteAPI在app -engine上进行Google身份验证(不建议使用ClientLogin)。 我想将其更改为Oauth2.0。 我在Google上搜索了很多,但是没有找到太多解释。 任何帮助将不胜感激。
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 ---");
}
}
对于OAuth2身份验证,您在gcloud内部有两个主要解决方案。
gcloud
安装gcloud( https://cloud.google.com/sdk/ ),然后将其初始化( https://cloud.google.com/sdk/docs/initializing )。 之后,您应该运行“ gcloud auth login”,这将提示您身份验证窗口,用于在gmail上连接帐户。
您的其他解决方案是通过Google控制台创建一个新的服务帐户,为其提供json密钥,并将其作为凭据传递给功能参数,或者在GOOGLE_APPLICATION_CREDENTIALS环境变量中进行设置,或使用gcloud auth authatve-service-account --key-file“ PATH_TO_JSON”。
创建服务帐户的教程: https : //developers.google.com/identity/protocols/OAuth2ServiceAccount#overview
通过服务帐户(如下所述)进行gcloud默认身份验证的主要优点是,每个Google云产品都会在恒定位置检查application_credentials.json(well_known_file)文件。 另一个优点是可以在一个多小时的会话中刷新其令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.