OAuth 2.0 with GMAIL API using

145 views Asked by At

I am trying to create a sample program for Install Application to access google mail api using oAuthentication. But I have a query before start working on it. I read on most of doc and following this link https://developers.google.com/identity/protocols/OAuth2InstalledApp

First we need to request for token by providing ClientID and SecretKey That will return Token in response that Token is pass to other google service which we want to access. During this process code open the browser (Single time) to get token id. It can not happen without browser.

Can't we do http request to google then get respond from it without using browser, like access any rest api we do?

1

There are 1 answers

0
Tholle On

From Google's Using OAuth 2.0 to Access Google APIs:

The authorization sequence begins when your application redirects a browser to a Google URL; the URL includes query parameters that indicate the type of access being requested. Google handles the user authentication, session selection, and user consent. The result is an authorization code, which the application can exchange for an access token and a refresh token.

The application should store the refresh token for future use and use the access token to access a Google API. Once the access token expires, the application uses the refresh token to obtain a new one.

enter image description here

You have no choice but to redirect the user to Google the first time the user is using your application. However, you can ask for a refresh token that you can use to refresh the access token after this first login, which usually expires after one hour.