Back

How to build a public Pipefy integration: Building the Auth Flow

Aug 13, 20246 minute read

Hey there, fellow developer! Ready to dive into the world of Pipefy integrations? Today, we're going to walk through building the authorization flow for a public Pipefy integration. It's easier than you might think, and I'll guide you through each step. Let's get started!

Introduction

Pipefy is a powerful workflow management tool, and integrating it with your own applications can unlock a whole new level of productivity. The key to a successful integration lies in a robust authorization flow. That's what we're focusing on today – building a secure, user-friendly auth flow for your Pipefy integration.

Prerequisites

Before we jump in, make sure you've got:

  • A Pipefy account with API access
  • Node.js and npm installed on your machine
  • A basic understanding of OAuth 2.0 (don't worry if you're rusty, we'll cover the essentials)

Got all that? Great! Let's move on.

Setting up the project

First things first, let's get our project set up:

mkdir pipefy-integration cd pipefy-integration npm init -y npm install express axios dotenv

Configuring Pipefy App

Head over to your Pipefy account and create a new app. You'll need to grab your client ID and client secret, and set up a redirect URI. Keep these handy – we'll need them soon!

Implementing the Authorization Flow

Now for the fun part – let's build our auth flow! Here's what we need to do:

  1. Create an authorization URL
  2. Handle the redirect and extract the authorization code
  3. Exchange the code for an access token
  4. Store and refresh the access token

Let's break it down:

const express = require('express'); const axios = require('axios'); require('dotenv').config(); const app = express(); const authorizationUrl = `https://app.pipefy.com/oauth/authorize?client_id=${process.env.CLIENT_ID}&redirect_uri=${process.env.REDIRECT_URI}&response_type=code`; app.get('/auth', (req, res) => { res.redirect(authorizationUrl); }); app.get('/callback', async (req, res) => { const { code } = req.query; try { const response = await axios.post('https://app.pipefy.com/oauth/token', { client_id: process.env.CLIENT_ID, client_secret: process.env.CLIENT_SECRET, code, grant_type: 'authorization_code', redirect_uri: process.env.REDIRECT_URI }); const { access_token, refresh_token } = response.data; // Store these tokens securely res.send('Authorization successful!'); } catch (error) { res.status(500).send('Authorization failed'); } }); app.listen(3000, () => console.log('Server running on port 3000'));

Securing the integration

Security is crucial, so let's implement PKCE (Proof Key for Code Exchange) and handle token storage and refresh:

const crypto = require('crypto'); function generateCodeVerifier() { return crypto.randomBytes(32).toString('hex'); } function generateCodeChallenge(verifier) { return crypto.createHash('sha256').update(verifier).digest('base64') .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=/g, ''); } // Use these functions in your auth flow

Testing the integration

Time to put our work to the test! Start your server and navigate to http://localhost:3000/auth. You should be redirected to Pipefy's authorization page. After granting permission, you'll be redirected back to your callback URL.

Next steps

Now that you've got your auth flow set up, the world is your oyster! You can use your access token to make API calls to Pipefy and build out the rest of your integration.

Conclusion

And there you have it! You've successfully built a secure authorization flow for your Pipefy integration. Remember, a robust OAuth implementation is crucial for public integrations, so always prioritize security.

Keep exploring, keep building, and most importantly, keep having fun with your integrations. You've got this!