Menu Search Me


Created by JimmyXu on 2020-08-10

Google OAuth


Enable APIs for your project

Find and enable Google Plus API

Create authorization credentials            

API Key: used for using a google service for public users. For example, calling google map service for public escaperoom users.

Client ID: used for using a google service for logged-in users. You need to create 3 client IDs: web, Android, and iOS

How to specify multiple scopes?

Specify multiple scopes by separating them with space

How to redirect browser to google oauth2 login?

$scope.login=function() {

      var client_id="";

      var scope="";

      var state="12345678";//better be a dynamical nonce

      var redirect_uri="";

      var response_type="token";

      var url=""+scope+"&client_id="+client_id+"&redirect_uri="+redirect_uri+




Processing google oauth2 response

The google oauth2 successful response will be something like below:

How to get a user’s email with google plus api?



Find and enable Google Plus API

Include in the oauth2 auth scope

Do the following GET request, and tBearer is the access token you got from google oauth2 login response:

var url="";

var req = {

      method: 'GET',

      url: url,

      headers: {'Content-Type': 'application/json', 'authorization': tBearer},

      data: ""



.then(function (response) {

      var s = JSON.stringify(;




.catch(function (data) {

      var s = JSON.stringify(;





The result ( is a Jason object like below:














How to verify user identity using access token on the server-side?

You can use your javascript code to redirect the user to google login and get the access token from the response.

You then may want to pass the access token to the server side so the server-side can get user profile information such as email from google plus and at the same time verify the access token (anything passed in from browser side will have to be double-checked).

How do you do that? You can just use the apache http client component to make a call to google plus API as in “How to get a user’s email with google plus api?” If you can get the Jason response back with the user profile, then that means the access-token is verified and you can process the user profile information or even make other google API calls on the user’s behalf.