简体   繁体   English

远程API,ClientLogin到Oauth2.0

[英]Remote API , ClientLogin to Oauth2.0

I am using RemoteAPI for google authentication (using ClientLogin , which is deprecated) on app -engine. 我正在使用RemoteAPI在app -engine上进行Google身份验证(不建议使用ClientLogin)。 I want to change it to Oauth2.0 . 我想将其更改为Oauth2.0。 I had googled a lot, but hadn't found much explanation. 我在Google上搜索了很多,但是没有找到太多解释。 Any kind of help will be appreciated. 任何帮助将不胜感激。

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 ---");
    }

}

For OAuth2 authentication you have two main solutions inside of gcloud. 对于OAuth2身份验证,您在gcloud内部有两个主要解决方案。

gcloud gcloud

Install gcloud ( https://cloud.google.com/sdk/ ), and then init it ( https://cloud.google.com/sdk/docs/initializing ). 安装gcloud( https://cloud.google.com/sdk/ ),然后将其初始化( https://cloud.google.com/sdk/docs/initializing )。 After that, you should go and run "gcloud auth login" which will prompt you an authentication window for connected accounts on gmail. 之后,您应该运行“ gcloud auth login”,这将提示您身份验证窗口,用于在gmail上连接帐户。

Your other soulution is creating a new service account through googles console, furnish it a json key and pass it as a credential in a function parameter or set it in GOOGLE_APPLICATION_CREDENTIALS environment variable or use gcloud auth activatve-service-account --key-file "PATH_TO_JSON". 您的其他解决方案是通过Google控制台创建一个新的服务帐户,为其提供json密钥,并将其作为凭据传递给功能参数,或者在GOOGLE_APPLICATION_CREDENTIALS环境变量中进行设置,或使用gcloud auth authatve-service-account --key-file“ PATH_TO_JSON”。

Tutorial to create service account: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#overview 创建服务帐户的教程: https : //developers.google.com/identity/protocols/OAuth2ServiceAccount#overview

The main advantage of gcloud default authentication over service account(described below) is that every google cloud product will check for the application_credentials.json(well_known_file) file in a constant location. 通过服务帐户(如下所述)进行gcloud默认身份验证的主要优点是,每个Google云产品都会在恒定位置检查application_credentials.json(well_known_file)文件。 The other advantage is that its token could be refreshed during more than an hour session. 另一个优点是可以在一个多小时的会话中刷新其令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM