4

I need to authenticate to an API using OAUTH2, however, it has to be made programmatically, no user typing stuff in a browser is permitted.

This seems like such a simple use case, but I haven't found anything online, the only thing close to it was this post, and the only answer is "yeah, you don't want to use a web browser, but what if you do?"... This doesn't help.

So, please, opening a web browser is not an option, I just want to know if Google provides any way to authenticate purely through code.

Thank you!

Lucas Abbade
  • 757
  • 9
  • 19
  • Although I'm not sure about the Google APIs you want to use and your final goal, for example, how about using Service account? When the Service account is used, the access token can be retrieved without using the browser. [Ref](https://developers.google.com/identity/protocols/OAuth2ServiceAccount) But if this was also not the direction you want, I apologize. – Tanaike Dec 12 '19 at 23:14
  • Generally, client credential grant is for that https://oauth.net/2/grant-types/client-credentials/ or password grant https://oauth.net/2/grant-types/password/ if you need it on behalf of the user – Jan Garaj Dec 13 '19 at 00:32
  • What is your environment? Is this machine to machine or is a user involved? – jwilleke Dec 13 '19 at 10:03
  • @Tanaike I believe that actually solves my problem, I'll look into it, thanks! You can post your answer below so I can accept it – Lucas Abbade Dec 13 '19 at 18:32
  • @Lucas Abbade Thank you for replying. I posted it as an answer by including the information. Could you please confirm it? – Tanaike Dec 13 '19 at 23:35
  • 1
    @Tanaike Yes, that's great, thanks! – Lucas Abbade Dec 15 '19 at 16:13

1 Answers1

1

In order to achieve your goal, I would like to propose to use the Service account. When the Service account is used, the access token can be retrieved without using the browser.

As the points for using the Service account, please check the following points.

  • The Service account is not your own Google account.
  • For example, as one of several situations, if you want to manage a file in your Google Drive using the Service account, please share the file with the Service account. By this, the Service account can access to the file in your Google Drive.

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165