Google API Key OAuth2

From sgcWebSockets 4.3.4, OAuth2 is supported. Google provides access to these APIs using OAuth2 authentication, so you first must get the OAuth2 Client ID and Client Secret before you can connect to Google Services.

sgcWebSockets make use of standard web browser to request a new Authorization Code. If a refresh token is provided, it will update Access Token automatically.


Get OAuth2 Credentials

To get the OAuth2 Client Id and Client Secret:

  1. Go to https://console.cloud.google.com/apis/dashboard
  2. Select an existing project or create a new one.
  3. Once created, select Apis and Services / Credentials.
  4. On credentials page, press Create Credentials / OAuth Client ID.
  5. Once the OAuth2 Credentials are created, a dialog page is shown with Client Id and Client Secret. These values will be needed by TsgcHTTP_OAuth2 component.

In OAuth Consent screen menu you can configure how OAuth protocol will work. For testing purposes there is no need to modify default configuration, only keep in mind that you will get a warning from google, advising your application has not been verified. 

Configuration Example

If you want access to GMail application using our TsgcHTTP_OAuth2 component, just check OAuth2 sample program located in Demo/OAuth2 folder.

You only must create a new API and use Client Id and Client Secret returned by google to get an Access Token which can be used later to connect to GMail API

Once Google API key has been released, copy Client Id and Client Secret, and paste on ClientId and Secret of demo sample program. After that, press New Access Token and a new web browser page will be be shown requesting user to approve GMail Access. If successful, a new Access Token will be returned as shown in next screenshot. 

×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Indy Components and OpenSSL 1.1.1
OAuth2 Delphi WebSockets

Related Posts