Example code for authorizing a user an Airtable OAuth integration.
The script stores access token and refresh token in redis
You can then use https://github.com/amirlogic/airtable-to-redis
Setup instructions
- Install nodejs (this repo is tested with node16).
- From the project root directory run
npm i
to install the dependencies. - Go to https://airtable.com/create/oauth and register a new integration. Set the redirect URL to http://localhost:4000/airtable-oauth (if you choose a different path or port you will need to edit the code).
- run
touch ./.config.js
to create a.config.js
file, then copy paste the following contents into it:const config = { // Uses the PORT variable declared here, the path is defined in code port: 4000, redirectUri: 'http://localhost:4000/airtable-oauth', clientId: INSERT_YOUR_CLIENT_ID, // If you're not using a client secret, set to the empty string: "" clientSecret: INSERT_YOUR_CLIENT_SECRET, airtableUrl: 'https://www.airtable.com', // space delimited list of Airtable scopes, update to the list of scopes you want for your integration scope: 'data.records:read data.records:write', // if the server requires a secure conection (SSL/TLS), use rediss:// instead redisUrl:'redis://user:pass@redis.server:port', redisKey:'airtable.auth', }; module.exports = config;
- within
./.config.js
(the file you created) fill in yourclient_id
, desiredscopes
, andclient_secret
(if applicable). You also have to provide the connection string for the redis serverredisUrl
. - From the project root directory run
npm start
to begin running the service. You should see "Example app listening on port 4000" in your console. Note that if you change the values in./.config.js
you'll need to restart this process, any other changes to the code should be hot-reloaded when saving.
Creating a token:
- Ensure the process is running and configured with your credentials in
./.config.js
- Visit
http://localhost:4000/
and click the link to authorize your integration - Add your desired resources, then click authorize.
- The response, including your access token and refresh token, should be visible
Refreshing a token:
- Ensure the process is running and configured with your credentials in
./.config.js
- Ensure you have a refresh token (obtainable by creating a token, see above)
- Visit
http://localhost:4000/
and enter your refresh token to the input field and click "submit" - The response, including your new access token and refresh token, should be visible
You can read more in the docs.
If the script is not working, it could be because of redis server connection
If you set USE_REDIS
to false, the script will not attempt to connect to a redis server
You should still be able to generate a authorization token and refresh it, but it will not be stored in redis.