Back

How to build a public UKG Ready integration: Building the Auth Flow

Aug 11, 20246 minute read

Hey there, fellow JavaScript wizards! Ready to dive into the world of UKG Ready integrations? Today, we're going to tackle one of the most crucial aspects of building a public integration: the authorization flow. Buckle up, because we're about to make authentication a breeze!

Setting the Stage

Before we jump in, make sure you've got your UKG Ready API credentials handy. You'll need them to make this magic happen. Also, ensure you've got your favorite JavaScript environment set up – whether that's Node.js or a browser-based setup.

The OAuth 2.0 Tango

UKG Ready uses OAuth 2.0 for authentication, specifically the authorization code grant type. It's like a secret handshake between your app and UKG Ready. You'll need three key ingredients:

  1. Client ID
  2. Client Secret
  3. Redirect URI

These are the VIP passes to the UKG Ready party. Keep them safe!

Kicking Off the Auth Dance

Let's start by constructing the authorization URL. It'll look something like this:

const authUrl = `https://ukg-ready-auth.com/oauth/authorize? client_id=${clientId}& redirect_uri=${encodeURIComponent(redirectUri)}& response_type=code& scope=api`;

Now, redirect your user to this URL. They'll log in to UKG Ready and grant permissions to your app. Easy peasy!

Catching the Callback

Once the user grants permission, UKG Ready will redirect them back to your redirect_uri with an authorization code. It's like a hot potato – catch it quick!

app.get('/callback', (req, res) => { const code = req.query.code; // Time to exchange this code for tokens! });

Token Time!

Now for the fun part. Let's exchange that code for access and refresh tokens:

const tokenResponse = await fetch('https://ukg-ready-auth.com/oauth/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ grant_type: 'authorization_code', code, client_id: clientId, client_secret: clientSecret, redirect_uri: redirectUri, }), }); const { access_token, refresh_token } = await tokenResponse.json();

Boom! You've got your tokens. Store them securely – they're your keys to the UKG Ready kingdom.

Keeping It Fresh

Access tokens don't last forever. When they expire, use your refresh token to get a new one:

const refreshTokens = async (refreshToken) => { // Similar to the token exchange, but use grant_type: 'refresh_token' // and include the refresh_token in the body };

Making It Rain (API Requests)

Now you're ready to make authenticated requests to UKG Ready:

const apiRequest = await fetch('https://ukg-ready-api.com/endpoint', { headers: { 'Authorization': `Bearer ${access_token}`, }, });

Staying Safe Out There

Remember, with great power comes great responsibility. Keep those tokens secure, implement PKCE for extra security, and always be prepared to handle token revocation.

Take It for a Spin

Before you release your integration into the wild, give it a thorough test drive. Set up a test environment and simulate the full auth flow. Iron out any kinks now, and you'll thank yourself later!

You Did It!

And there you have it, folks! You've just built a rock-solid authorization flow for your UKG Ready integration. Pat yourself on the back – you've earned it!

Remember, this is just the beginning. From here, you can expand your integration to do all sorts of cool things with UKG Ready. The sky's the limit!

Now go forth and integrate with confidence. You've got this! 🚀