Contents

Obtaining access token from Google Authorization Server using Refresh Token

Icon

To use the Gmail API, a Gmail account is needed.

Icon

The Gmail API uses OAuth2 authentication with Tokens.

Creating Client ID and Client Secret

Perform the following actions to obtain tokens:

  1. Open the APIs and Services page in the Google Cloud console using the URL https://console.cloud.google.com.
  2. Follow the steps mentioned in https://ei.docs.wso2.com/en/latest/micro-integrator/references/connectors/gmail-connector/configuring-gmail-api to create a project and obtain client_id and client_secret.
  3. Add the mentioned redirected_uri in Oauth Client ID credentials and preferred scopes to access in OAuth consent screen.

Obtaining Refresh Token

  1. Open OAuth Playground using the URL https://developers.google.com/oauthplayground click the Settings icon on the upper-right side of the page.
  2. In the Oauth2.0 configuration dialog box, enable the Use your own OAuth credentials option and provide the client_id and client_secret generated for the project.

     

  3. Expand the Step1 Select & authorize APIs section, navigate to Gmail API v1 and select the scopes to be authorized and click the Authoize APIs button.

     

  4. Choose the Google account that is associated with the API project and provide user consent for the scopes to be authorized.

     

  5. Expand the Step 2 Exchange authorization code for tokens section where an authorization code will be auto populated. Click the Exchange authorization code for tokens button.

     

  6. Copy the refresh token that gets populated in the Refresh token text box.

Configuring the component

Managed Connection Factory configuration

  1. Select the IMAP option from the Protocol drop-down.
  2. Under Connection Configuration, provide the following property values:
    1.   MailserverURL: imap.gmail.com
    2.   MailServer Port: 993
  3. Provide the following additional properties:
    1.   mail.imap.starttls.enable = true
    2.   mail.imap.socketFactory.class = javax.net.ssl.SSLSocketFactory

Authentication Configuration

 

 Select OAUTH2 as Authentication Type and provide the credentials:

Testing the configuration

  1. Add the following Request Properties:
    1. grant_type = refresh_token
    2. client_id = Client ID value that is obtained from google console
    3. refresh_token = Replace with the refresh token obtained above
    4. client_secret = Replace with secret value obtained from google console 
  2. Test the connection using Test button in Managed Connection Factory.

 

Adaptavist ThemeBuilder EngineAtlassian Confluence