This sample demonstrates using the Oauth2 apis to create an authenticaion filter.
See the Google App Engine standard environment documentation for more detailed instructions.
- In the Cloud Developers Console > API Manager > Credentials, create a Oauth Client ID for a Web Application. You will need to provide an authroized JavaScript origin. Typically, https://projectID.appspot.com.
- Edit
src/main/webapp/index.html
and changeYOUR_CLIENT_ID_HERE.apps.googleusercontent.com
to Client ID from the prior step.
NOTE: The app can be run locally, but the Oauth2 APIs do not work with the development server.
$ mvn appengine:devserver
$ mvn appengine:update -Dappengine.appId=YOUR-PROJECT-ID -Dappengine.version=SOME-VERSION
-
Using your browser, visit
https://YOUR-PROJECT-ID.appspot.com
, click Sign In. -
The Sign In process will then request some text from your app, and then display it, if the id matches the list in
src/main/java/com/example/appengine/Oauth2Filter.java
.
NOTE: Typically, you would use this for Service Accounts, but user accounts work as well.
-
Enable logging by uncommenting the context.log line in
src/main/java/com/example/appengine/Oauth2Filter.java
, redeploy, and visit the page -
Look at the logs in Cloud Developers Console > Logs.
-
Add the
tokenAudience
to theallowedClients
. -
Deploy and visit the page again.