I am using RemoteAPI for google authentication (using ClientLogin , which is deprecated) on app -engine. I want to change it to Oauth2.0 . I had googled a lot, but hadn't found much explanation. 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.
gcloud
Install gcloud (https://cloud.google.com/sdk/), and then init it (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.
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".
Tutorial to create service account: 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. The other advantage is that its token could be refreshed during more than an hour session.