Skip to content

Sign in with Okta

Your organization's people sign in to your app with their Okta account. As with Google and Apple, your app receives an ID token, from your own Okta org this time, and exchanges it for an ObjectsGrid access token. ObjectsGrid creates the person's User Account on their first sign-in.

The sign-in itself happens between your app and Okta. ObjectsGrid never sees a password and isn't an identity provider: it only checks the ID tokens your Okta org issues, with the keys your Okta org publishes.

This guide takes you through it in four steps:

  1. Create an app integration in Okta and find your issuer.
  2. Sign people in with Okta in your app.
  3. Register your Okta issuer and client ID with your Organization Account.
  4. Exchange the ID token for an access token.
sequenceDiagram
    participant User
    participant App as Your app
    participant Okta as Your Okta org
    participant OG as ObjectsGrid
    User->>App: Clicks "Sign in"
    App->>Okta: Authorization code flow with PKCE
    Okta-->>App: ID token (and Okta's own access token)
    App->>OG: POST /oauth2/token with the ID token
    OG->>Okta: Okta's public keys, fetched once and cached
    OG-->>App: Access token and refresh token
    App->>OG: API requests with Authorization: Bearer <access token>

1. Create an app integration in Okta

In the Okta Admin Console, go to Applications, Applications, and click Create App Integration:

  1. Choose OIDC - OpenID Connect, then the type of your app: Single-Page Application for an app in the browser, Native Application for a mobile or desktop app, Web Application for an app with its own server.
  2. If Okta asks how the client is defined, keep the option where Okta assigns and manages the client ID.
  3. Keep the Authorization Code grant, and add Refresh Token so Okta's SDK can renew the person's Okta tokens without sending them back to the sign-in page.
  4. Under Sign-in redirect URIs, add the page of your app that receives the sign-in, such as https://shop.example.com/login/callback.
  5. Under Assignments, choose who may sign in, such as a group of your organization's people.

Save, and note the app's Client ID, such as 0oa1b2c3d4EXAMPLE. ObjectsGrid needs no client secret.

Your issuer is the URL your Okta ID tokens carry as iss. It is one of:

  • https://<your Okta domain>, such as https://acme.okta.com, for Okta's org authorization server, which every Okta org has;
  • https://<your Okta domain>/oauth2/<authorization server id>, such as https://acme.okta.com/oauth2/default, if your app uses a custom authorization server.

If your Okta org uses a custom URL domain, such as login.acme.com, the issuer carries that domain instead. To check, open <issuer>/.well-known/openid-configuration in a browser: its issuer field must be exactly the URL you register in step 3.

2. Sign people in with Okta

Use Okta's SDK for your platform. In the browser, Okta Auth JS runs the authorization code flow with PKCE and gives you the ID token:

import { OktaAuth } from "@okta/okta-auth-js";

const oktaAuth = new OktaAuth({
  issuer: "https://acme.okta.com/oauth2/default",    // your issuer
  clientId: "0oa1b2c3d4EXAMPLE",                     // your app integration's client ID
  redirectUri: "https://shop.example.com/login/callback",
  scopes: ["openid", "email", "profile", "offline_access"],
  pkce: true,
});

// on your sign-in button
await oktaAuth.signInWithRedirect();

// on the callback page
await oktaAuth.handleLoginRedirect();
const idToken = oktaAuth.getIdToken();

Ask for the email scope: ObjectsGrid needs the person's email to create their User Account. offline_access lets Okta's SDK renew the person's Okta tokens in the background.

3. Register your Okta issuer with ObjectsGrid

ObjectsGrid accepts an ID token only if it was issued to an app your Organization Account lists in its identityProviders. As an administrator, read your Organization Account and add an entry with your issuer and your app's client ID, then replace it:

curl -X PUT https://apis.objectsgrid.com/organizationaccounts/<organization account id> \
  -H 'Content-Type: application/json' \
  -H 'X-ObjectsGrid-AccessPoint: EU' \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        "name": "Northpeak Outdoor",
        "accessPoint": "EU",
        "identityProviders": [
          {"issuer": "https://accounts.google.com", "clientIds": ["<your Google client id>"]},
          {"issuer": "https://acme.okta.com/oauth2/default", "clientIds": ["0oa1b2c3d4EXAMPLE"]}
        ]
      }'

Send the whole account you read, with your change, and keep the apps already listed unless you want to stop them from signing in.

ObjectsGrid checks your issuer when you add it, so a mistake shows straight away rather than at the first sign-in. The request is refused with 400, saying why, when:

  • the issuer isn't an https URL, or has a port, a query, a fragment or a trailing /;
  • its discovery document, <issuer>/.well-known/openid-configuration, can't be read within 5 seconds, redirects, or is on an address that isn't public;
  • the document names another issuer: write the issuer exactly as your ID tokens carry it;
  • the document doesn't publish its keys on https, or doesn't list RS256, which Okta always uses.

An Organization Account can list up to 3 issuers of its own, besides Google and Apple. Creating an Organization Account and binding its administrator still take a Google or Apple sign-in.

4. Exchange the ID token for an access token

The exchange is the same as for Google and Apple:

async function exchangeForAccessToken(idToken) {
  const response = await fetch("https://apis.objectsgrid.com/oauth2/token", {
    method: "POST",
    headers: {"Content-Type": "application/json", "X-ObjectsGrid-AccessPoint": "EU"},
    body: JSON.stringify({
      grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
      subject_token: idToken,
      subject_token_type: "urn:ietf:params:oauth:token-type:id_token",
      client_id: "<organization account id>",
    }),
  });
  const { access_token, expires_in, refresh_token } = await response.json();
}

The response is 200 with an access token for one hour and a refresh token. A 400 with "error": "invalid_grant" means the issuer or client ID isn't in your identityProviders, the ID token has expired, or its nonce isn't the one you sent.

Email verification. Okta leaves email_verified out of an ID token it issues together with an access token, which is how apps get them. For an issuer of your own, ObjectsGrid accepts an ID token without email_verified: you chose to trust your Okta directory. An ID token that says email_verified is false is still refused. ObjectsGrid finds a person's User Account by issuer and subject, never by email.

How long a sign-in lasts

When someone leaves your organization and you remove them in Okta, Okta stops signing them in, but ObjectsGrid doesn't hear about it: their ObjectsGrid refresh token keeps working until it runs out. Set how long a sign-in lasts with your Organization Account's refreshTokenLifetimeHours, from 1 to 2400 hours (100 days):

curl -X PUT https://apis.objectsgrid.com/organizationaccounts/<organization account id> \
  -H 'Content-Type: application/json' \
  -H 'X-ObjectsGrid-AccessPoint: EU' \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"name": "Northpeak Outdoor", "accessPoint": "EU", "refreshTokenLifetimeHours": 12}'

With 12, a person signed in at 09:00 can refresh until 21:00; then a refresh is refused with invalid_grant, and your app has them sign in with Okta again. Okta's SDK usually does that without a prompt while their Okta session lasts, and refuses once they have been removed. The lifetime counts from the sign-in, however often your app refreshes, and applies to every sign-in of your Organization Account, Google and Apple included. Without it, a refresh token lasts 100 days from when it was issued, as before.

To cut someone off at once, an administrator disables their User Account: their access stops within the hour, when their access token expires.

Before you change your issuer

ObjectsGrid finds a person's User Account by their issuer and subject. If your issuer changes, for example when your Okta org moves to a custom URL domain, people signing in with the new issuer get new, empty User Accounts. ObjectsGrid doesn't move accounts from one issuer to another: plan the change before you have User Accounts that matter, or contact us.

Troubleshooting

What you see Why
400 when you add the issuer, "its discovery document names another issuer" The issuer isn't written exactly as your ID tokens carry it: check iss in a decoded ID token
400 when you add the issuer, "the issuer was asked less than a minute ago" ObjectsGrid fetches an issuer's documents at most once a minute; wait a minute and try again
invalid_grant on the exchange, the token issued to an app not registered The app's client ID isn't under your issuer in identityProviders
400 on a first sign-in, "the token's 'email' claim is missing" Your app didn't ask Okta for the email scope
invalid_grant on a refresh, "this sign-in has ended" The sign-in is older than refreshTokenLifetimeHours: sign in with Okta again