This sample shows how to implement an OAuth 2.0 flow using the Google OAuth Client Library for Java to access protected data stored on Google services. OAuth 2.0 is a standard specification for allowing end users to securely authorize a client application to access protected server-side resources.
- Make sure
gcloud
is installed and initialized:
gcloud init
- If this is the first time you are creating an App Engine project
gcloud app create
- Copy the sample apps to your local machine:
git clone https://github.com/GoogleCloudPlatform/java-docs-samples
- Add the appengine-simple-jetty-main Main class to your classpath:
cd java-docs-samples/appengine-java11/appengine-simple-jetty-main
mvn install
-
In the Cloud Developers Console > API Manager > Credentials, create a OAuth Client ID for a Web Application. You will need to provide an authorized redirect URI origin:
https://<PROJECT_ID>.appspot.com/oauth2callback
. -
Replace
CLIENT_ID
andCLIENT_SECRET
with these values in your app.yaml -
Move into the
appengine-java11/oauth2
directory and compile the app:
cd ../oauth2
mvn package
mvn clean package appengine:deploy
To view your app, use command:
gcloud app browse
Or navigate to https://<your-project-id>.appspot.com
.