google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

Access token Generated by different app and using that token in another app

Open davdaravi opened this issue 9 years ago • 3 comments

I got google authentication access token from my first app for ex. myfirstapp and I am using that access token in my secondapp for ex. mysecondapp for getting user profile.. But technically that could not be possible but still I am getting the user profile from mysecondapp. Any idea regarding this issue?

davdaravi avatar Aug 19 '17 11:08 davdaravi

@davdaravi Thanks for reaching out. Can you elaborate on what you were trying to do, preferably with some code?

bantini avatar Sep 08 '17 22:09 bantini

@bantini Ya Sure..

I have google signin in my laravel project .. In that my google credentials are something like below.

GOOGLE_CLIENT_ID=370574894534-elbaq2u5jmet1mfa319un4i7dslsotcc.apps.googleusercontent.com

GOOGLE_CLIENT_SECRET=qzBrzx6bnUg2_-ms6ZV0zwDt

The above credentials are fake .. but in my laravel project If I do signin with google with original credetials then i got access token from google..

Now, In another project which runs on nodejs in backend with different credentials of google .. Which used only for api.. So I passed access token in api which was generated by laravel project and it will give me the profile of the user.. actually that is wrong.. If I signin in any app through social media and that access token if i passed in any another app then It should not give me the profile of the user but currently it gives me the user profile..

Here is the Code:

Node JS Code:

envConfig File : GOOGLE_CLIENT_ID : '982328512461-q3293k10ed135djabng1t7i56e3l5t1o.apps.googleusercontent.com',

GOOGLE_CLIENT_SECRET : 'E5mrqdzIDyGHW6ObNB1HsG3z',

GOOGLE_REDIRECT_URL : 'http://localhost:3000/google/callback'

Auth.js File Code:

var google = require('googleapis'); //google api var plus = google.plus('v1'); var OAuth2 = google.auth.OAuth2;

var oauth2Client = new OAuth2( envConfig.GOOGLE_CLIENT_ID, envConfig.GOOGLE_CLIENT_SECRET, envConfig.GOOGLE_REDIRECT_URL );

function gmailSignUp(req, res, next) { oauth2Client.setCredentials({access_token: req.body.actoken}); plus.people.get({ userId: 'me', auth: oauth2Client }, function (err, response) { // handle err and response if (err) { console.log(err); helpers.createResponse(res, constants.UNPROCESSED, messages.GOOGLE_LOGIN_ERROR, messages.GOOGLE_LOGIN_ERROR); } else { console.log(response); } }); }

davdaravi avatar Sep 09 '17 04:09 davdaravi

@davdaravi The client_id and secret are only used when there is no access token. In your case, since you have already passed the token from your first laravel project, your second app gets the scopes associated with the token in your first app as well. If you want to prevent that, do think about implementing the authentication separately for your second client instead of passing the token from the first one.

bantini avatar Nov 03 '17 20:11 bantini