REST API authentication using OAuth 2.0#
Insight’s REST API data source supports OAuth 2.0 as the authentication type. In this guide, we’ll learn how to use Google OAuth2 API to delegate authorization and authentication for your Insight² Application.
Before setting up the REST API data source in Insight, we need to configure the Google Cloud Platform to gather the API keys required for the authorization access.
Setting up Google Cloud Platform#
Google Cloud Platform provides access to more than 350 APIs and Services that can allow us to access data from our Google account and its services. Let's create an OAuth application that can be given permission to use our Google profile data such as Name and Profile picture.
- Sign in to your Google Cloud account, and from the console create a New Project.
- Navigate to the APIs and Services, and then open the OAuth consent screen section from the left sidebar.
- Enter the Application details and select the appropriate scopes for your application. We will select the profile and the email scopes.
- Once you have created the OAuth consent screen, Create new credentials for the OAuth client ID from the Credentials section in the left sidebar.
- Select the application type, enter the application name, and then add the following URIs under Authorised Redirect URIs:
https://app.tooljet.com/oauth2/authorize(if you’re using Insight² cloud)
http://localhost:8082/oauth2/authorize(if you’re using Insight² locally)
- Now save and then you’ll get the Client ID and Client secret for your application.
Configuring Insight² Application with Google's OAuth 2.0 API#
Let's follow the steps to authorize Insight² to access your Google profile data:
- Select add data source from the left sidebar, and choose REST API from the dialog window.
You can rename the data source by clicking on its default name
- In the URL field, enter the base URL
https://www.googleapis.com/oauth2/v1/userinfo; the base URL specifies the network address of the API service.
- Select authentication type as
- Keep the default values for Grant Type, Add Access Token To, and Header Prefix i.e.
Request Header, and
- Enter Access Token URL:
https://oauth2.googleapis.com/token; this token allows users to verify their identity, and in return, receive a unique access token.
- Enter the Client ID and Client Secret that we generated from the Google Console.
- In the Scope field, enter
https://www.googleapis.com/auth/userinfo.profile; Scope is a mechanism in OAuth 2.0 to limit an application's access to a user's account. Check the scopes available for Google OAuth2 API here.
- Enter Authorization URL:
https://accounts.google.com/o/oauth2/v2/auth; the Authorization URL requests authorization from the user and redirects to retrieve an authorization code from identity server.
Create three Custom Authentication Parameters:
params description response_type code (
coderefers to the Authorization Code)
client_id Client ID redirect_uri
http://localhost:8082/oauth2/authorizeif using Insight² locally or enter this
https://app.tooljet.com/oauth2/authorizeif using Insight² Cloud.
Keep the default selection for Client Authentication and Save the data source.
Create the query#
Let’s create a query to make a
GET request to the URL, it will pop a new window and ask the user to authenticate against the API.
- Add a new query and select the REST API datasource from the dropdown
- In the Method dropdown select
GETand in advance tab toggle
run query on page load?
- Save and Run the query.
A new window will pop for authentication and once auth is successful, you can run the query again to get the user data like Name and Profile Picture.