How to Connect to any OAuth2 API in Airtable

Jul 22, 2024Zayyad Muhammad Sani

In this tutorial, you'll learn how to get data from an OAuth 2.0 API in Airtable using Data Fetcher. Although we'll use GitHub's OAuth 2.0 API in this tutorial, you can apply the steps you'll learn to connect to any OAuth 2.0 API in Airtable.

What is OAuth 2.0?

OAuth 2.0 is an authorization standard that allows users to give third-party web services and applications access to their data and perform actions on their behalf. When you use the "Sign in with Google" option on a website or give a Facebook game access to your profile, that's OAuth 2.0 in action.

In this case, we'll give Data Fetcher access to import user profile data from GitHub's OAuth 2.0 API into an Airtable base.

Set up the GitHub profiles Table

Create a new table and name it "GitHub profiles". Then, rename the primary field to "Username" and delete the other fields.

github-profiles-table.png

Creating an OAuth app in GitHub

We'll have to create an OAuth app in GitHub before we can use the API in Data Fetcher.

Follow these steps to create an OAuth app in GitHub:

1. Login to your GitHub account.

2. Click your profile image in the top-right corner of the screen, then click Settings.

click-settings-github.png

3. Scroll down the left sidebar and click <> Developer settings.

developer-settings-github.png

4. Select OAuth apps from the left sidebar.

select-oauth-apps.png

Make sure not to select GitHub apps. You can read about their differences in GitHub's documentation.

5. Click Register a new application.

register-new-application-oauth.png

Now, we'll fill in the details of the OAuth app.

1. Name the application "Data Fetcher".

2. Copy and paste https://oauth.datafetcher.com into Homepage URL.

3. Under Application description, enter "Allows users to import GitHub profile data into Airtable".

oauth-app-form-details.png

4. Copy and paste https://oauth.datafetcher.com/auth/callback into Authorization callback URL.

oauth-app-form-auth-callback.png

GitHub will redirect you to the callback URL when you authorize the OAuth app to make API requests.

5. Click Register application.

Before we move on to Data Fetcher, we'll generate a client secret, which is like a password we'll use alongside the client ID to use the OAuth app in Data Fetcher.

1. Click Generate a new client secret.

generate-client-secret-github.png

2. If you have two-factor authentication turned on, GitHub will ask for a 6-digit authentication code before generating the client secret. Copy and paste the code from your authenticator app, and GitHub will create the client secret.

3. Copy and paste the client secret somewhere safe, or leave the browser tab open so you can copy it when we use it in Data Fetcher. You can always generate a new secret if you forget to copy it.

client-secret-generated.png

We're all set to install Data Fetcher and create a request to connect to the OAuth app.

Add Data Fetcher to Airtable

1. Add the Data Fetcher extension to your Airtable base.

2. Once you’ve added the extension, sign in to Data Fetcher or sign up if you don’t have an account.

sign up for data fetcher.png

3. Once you've logged in to Data Fetcher, click Create your first request.

create your first request logo 2 smaller.png

Connect to an OAuth app in Airtable

Follow these steps to set up the request:

1. Under Application, select Custom.

select custom request.png

2. Name the request "Fetch GitHub profile data".

name-github-oauth-request.png

3. Click the Authorization tab and select OAuth under Type.

select-oauth-authorization-tab.png

4. Click + New to create a new OAuth connection

new-oauth-connection.png

5. Click Create custom OAuth connection at the bottom of the modal.

create-custom-oauth-connection.png

We'll now fill in the details of the OAuth connection.

1. Enter "GitHub" under Name.

2. Set Auth type to OAuth 2.

3. Copy and paste the URL https://github.com/login/oauth/authorize into Authorization URL.

custom-oauth-connection-first-details.png

4. Scroll down, then copy and paste the URL https://github.com/login/oauth/access_token into Token URL.

5. Copy and paste your client ID and client secret from the OAuth app's page on GitHub.

client-secret-data-fetcher.png

6. Enter "user,repo_deployment" under Scopes. These scopes tell GitHub the parts of the API we want to access. You can read more about OAuth app scopes in GitHub's documentation.

7. Copy and paste https://api.github.com into the Base URL.

Base URl custom OAuth.png

8. Leave the request headers as they are, then click Create connection.

A dialog will open asking you to authorize the OAuth app. Click Authorize and you'll be redirected to Data Fetcher.

authorize-oauth-app.png

Now that we're authenticated, we can make an API request.

Fetching GitHub Profile Data

We'll use GitHub API's user endpoint to get the username and profile URL of the GitHub account that created the OAuth app. Follow these steps to make the request:

1. Enter https://api.github.com/user under URL. Make sure the request's method is GET.

github-user-endpoint.png

2. Click the Headers tab, then click + Add.

add-header-github-oauth.png

3. Add a User-Agent header with "Data Fetcher" as the value. GitHub requires this header to identify who is making the request.

add-user-agent-header-github-oauth.png

4. Click Save and Run in the bottom right corner.

Mapping Response Fields

Once you've completed the previous steps, Data Fetcher will take you to Response field mapping. On this page, you'll select the fields you want to import from the response data.

response-field-mapping-github-oauth.png

In this case, we only want the username and GitHub profile URL.

  • Click Deselect All.
deselect-all-github-oauth.png
  • Select the following fields and use the mapping below:
    • Login -> Existing field Username
    • Html url -> New field Profile URL
fields-selected-github-oauth.png
  • Click Save and Run in the bottom right corner.

Check your table to see the results.

results-in-table-github-oauth.png

That's all for this tutorial. We can summarize the steps for connecting to an OAuth 2.0 API in Airtable as follows:

  • Create an OAuth app by following the instructions of the API's owners.
  • Set up the table you want to use for the request in your Airtable base.
  • Install Data Fetcher in Airtable.
  • Create a custom OAuth connection in Data Fetcher.
  • Make the API request.

Check out our blog to see what other things you can do with Data Fetcher and Airtable.

Related Posts

How to Import Data into Airtable Without Duplicates

How to Import Data into Airtable Without Duplicates

Oct 7, 2024

Zayyad Muhammad Sani

Custom RequestsData Fetcher
How to Connect to an OAuth 1.0 API in Airtable

How to Connect to an OAuth 1.0 API in Airtable

Sep 20, 2024

Zayyad Muhammad Sani

Custom Requests
How to Make an HTTP POST Request in Airtable

How to Make an HTTP POST Request in Airtable

Aug 20, 2024

Zayyad Muhammad Sani

Custom Requests