I need to get access_token without google login form

2,369 views
Skip to first unread message

freshcode...@gmail.com

unread,
Sep 18, 2018, 5:13:06 AM9/18/18
to AdWords API and Google Ads API Forum
Hello.
I have used node adwords api to manage adwords with nodejs.
So to get authenticated user first, I have done like this.
This is my code:

...
app = express();

let auth = new AdwordsAuth({
         client_id: *****,
         client_secret: *****,
);

app.get('/account_auth'. (req, res) => {
   auth.getAccessTokenFromAuthorizationCode(req.query.code, (err. tokens) => {
      if(err) {
      } else {
          if(tokens) {
             var user = new AdwordsUser({
                           .....
                           access_token: tokens.access_token,
                           refresh_token: tokens.refresh_token
                  });
           }
  }
});
});

So now to get access token, in browser I need to input url as auth,generateAuthenticationUrl() and then select google account even I had already logined.
So redirect  'http://localhost:3000/account_auth'  and I can get access_token.
But I want to get this access_token without user's hand authorization.
I have tried to authenticate with oauth2 using passport, but still select google account in the login form.
Can you help me?
Thanks.

Milind Sankeshware (AdWords API Team)

unread,
Sep 18, 2018, 2:58:39 PM9/18/18
to AdWords API and Google Ads API Forum
Hi,

Are you saying that you would like to generate the OAuth tokens (access and refresh tokens) without the user manually accepting the prompt/authorizing the call? If so, please note that it is required to manually accept the prompt at-least once. Once you are able to generate the refresh token, you can store that for making the future API calls. The refresh token along with the client credentials should be enough to make the future API calls. As an alternative, you could also explore the option of setting up the OAuth using the Service account mode. Please check here for more details. Please note that there are a few prerequisites for this type. Because of the complexity of setting up service account access for the AdWords API, we recommend a simpler alternative that achieves the same goal, which is to use the OAuth2 installed application flow and persist the refresh token. This way, your app will always be able to request a new access token when necessary.

Please note that we don't have a client library for nodejs at the moment. The client libraries that are available can be found here. Please let me now if you have any additional questions.

Thanks,
Milind, AdWords API Team.

Reply all
Reply to author
Forward
0 new messages