Skip to content

User Authentication

User authentication is done using The Bridge Auth Service that supports OAuth 2.0 / OpenID Connect. Tokens are issued as JWTs.

At a glance, the authentication process looks like this:

  1. You initiate the login process by redirecting the user to the /authorize endpoint (or the simpler shorthand /login and /signup endpoints).
  2. The user is pulled through an authentication process provided by The Bridge with cloud views.
  3. Once the user is authenticated and has selected the tenant to access, the user is redirected back to your app with a code.
  4. You make a call to the /token endpoint with this code to exchange it for access tokens and user profile information (OpenID).
  5. You can verify that the tokens are valid and safe to trust by using the public keys available from the /.well-known endpoint.
  6. You can refresh the tokens using the /token endpoint to obtain up-to-date access and profile information.

Start the OAuth 2.0 user login flow by redirecting the user to the /authorize endpoint. The user will be able to choose a login method and after the authentication process get back to your app with an auth code that you can exchange for access and OpenID tokens.

GET https://api.thebridge.dev/auth/authorize

Query Parameters

ParameterTypeRequiredDescription
client_idstringRequiredYour app ID
response_typestringRequiredWhat kind of tokens will be generated. We support code
redirect_uristringRequiredA target URI where the authenticated user will be redirected to together with tokens. Must be a valid URI in your App redirectUris
scopestringRequiredAny or all of: openid, profile, email, address, phone, onboarding, tenant
statestringOptionalUsed to resume a state in your app. The state will be available in the response code
signupbooleanOptionalSet to true to initiate a signup instead of the default login flow
signup_planstringOptionalThe key to an existing plan. Allows the signup to end with the new tenant subscribing to a specific plan
force_federationstringOptionalForce a certain federated login flow: ms-azure-ad, google, or saml
federation_connectionstringOptionalSpecify the federation connection ID to use with force_federation

You should redirect the user agent to this endpoint. This is not an API-to-API call. No x-api-key header is required; use your App ID in the client_id query parameter.

Request example

Build the authorize URL with your app ID, redirect URI, and scope, then open it in a browser to start the login flow.

# Build the URL (replace YOUR_APP_ID and open in browser)
# Use URL encoding for redirect_uri and scope if they contain special characters
curl -G 'https://api.thebridge.dev/auth/authorize' \
--data-urlencode 'client_id=YOUR_APP_ID' \
--data-urlencode 'response_type=code' \
--data-urlencode 'redirect_uri=http://localhost:8080/auth/oauth-callback' \
--data-urlencode 'scope=openid profile email tenant' \
--data-urlencode 'state=optional-state'
# Or open: https://api.thebridge.dev/auth/authorize?client_id=YOUR_APP_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fauth%2Foauth-callback&scope=openid%20profile%20email%20tenant

Get new tokens using an authorization code from a user who just completed authentication, or by using a refresh token that was issued to a logged-in user before.

POST https://api.thebridge.dev/auth/token

Body Parameters

ParameterTypeRequiredDescription
client_idstringRequiredYour app ID
grant_typestringRequiredauthorization_code or refresh_token
codestringOptionalRequired for authorization_code grant. The code received from the authenticated user
redirect_uristringOptionalRequired for authorization_code grant. Must be a valid URI in your App redirectUris
refresh_tokenstringOptionalRequired for refresh_token grant. The refresh token issued previously

HTTP 200 — Returns access token, refresh token, and id_token.

Request example

# Exchange authorization code for tokens
curl --request POST 'https://api.thebridge.dev/auth/token' \
--header 'Content-Type: application/json' \
--data-raw '{
  "client_id": "YOUR_APP_ID",
  "grant_type": "authorization_code",
  "code": "XXXX",
  "redirect_uri": "http://localhost:8080/auth/oauth-callback"
}'

# Refresh tokens
curl --request POST 'https://api.thebridge.dev/auth/token' \
--header 'Content-Type: application/json' \
--data-raw '{
  "client_id": "YOUR_APP_ID",
  "grant_type": "refresh_token",
  "refresh_token": "XXXX"
}'

Response example:

{
"access_token": "XXXX",
"refresh_token": "XXXX",
"token_type": "Bearer",
"expires_in": "XXXX",
"id_token": "XXXX"
}
POST Try it out
POST https://api.thebridge.dev/auth/token

Use the simpler shorthand endpoint /url/login to initiate the login flow. The Bridge will collect your default config and issue the OAuth 2.0 flow.

GET https://api.thebridge.dev/auth/url/login/:YOUR_APP_ID

Query Parameters

ParameterTypeRequiredDescription
redirectUristringOptionalTarget URI for redirect after auth. Defaults to your App defaultCallbackUri
statestringOptionalResume a state in your app
responseTypestringOptionalcode or id_token
forceFederationstringOptionalms-azure-ad, google, or saml
federationConnectionstringOptionalFederation connection ID for SAML flows

You should redirect the user agent to this endpoint. This is not an API-to-API call. No x-api-key header is required; the App ID is in the URL path.

Try it

GET Try it out
GET https://api.thebridge.dev/auth/url/login/:YOUR_APP_ID
The ID of your app

Use the shorthand endpoint /url/signup to initiate the signup flow.

GET https://api.thebridge.dev/auth/url/signup/:YOUR_APP_ID

Query Parameters

ParameterTypeRequiredDescription
redirectUristringOptionalTarget URI for redirect after auth. Defaults to your App defaultCallbackUri
statestringOptionalResume a state in your app
signupPlanstringOptionalKey to an existing plan for the new tenant to subscribe to
signupCurrencystringOptionalCurrency matching one of the prices in the plan
signupRecurrenceIntervalstringOptionalInterval matching one of the prices in the plan

You should redirect the user agent to this endpoint. This is not an API-to-API call. No x-api-key header is required; the App ID is in the URL path.

Try it

GET Try it out
GET https://api.thebridge.dev/auth/url/signup/:YOUR_APP_ID
The ID of your app

Get new tokens using a simplified endpoint with fewer parameters.

POST https://api.thebridge.dev/auth/token/:grantType/:YOUR_APP_ID

Body Parameters

ParameterTypeRequiredDescription
codestringOptionalRequired for code grant. The authorization code
refreshTokenstringOptionalRequired for refresh grant. The refresh token
redirectUristringOptionalOptional for code grant. Defaults to your App defaultCallbackUri

HTTP 200 — Returns access token, refresh token, id_token, and user_profile.

Request example

# Exchange code for tokens
curl --request POST 'https://api.thebridge.dev/auth/token/code/YOUR_APP_ID' \
--header 'Content-Type: application/json' \
--data-raw '{ "code": "XXXX" }'

# Refresh tokens
curl --request POST 'https://api.thebridge.dev/auth/token/refresh/YOUR_APP_ID' \
--header 'Content-Type: application/json' \
--data-raw '{ "refreshToken": "XXXX" }'

Response example:

{
"access_token": "XXXX",
"refresh_token": "XXXX",
"token_type": "Bearer",
"expires_in": "XXXX",
"id_token": "XXXX",
"user_profile": {
"sub": "63d25a9e0796d40008680f9a",
"name": "John Doe",
"family_name": "Doe",
"given_name": "John",
"preferred_username": "john@example.com",
"locale": "en",
"email": "john@example.com",
"email_verified": true,
"onboarded": true,
"tenant_id": "63d25a9e0796d40008680f96",
"tenant_name": "Johns Family",
"tenant_locale": "en",
"tenant_logo": ""
}
}

Returns a handover code used when redirecting to or displaying The Bridge hosted views and user interactions. The code is short-lived and should be consumed immediately.

POST https://api.thebridge.dev/auth/handover/code/:YOUR_APP_ID

Body Parameters

ParameterTypeRequiredDescription
accessTokenstringRequiredA valid user access token

HTTP 200 — Returns a short-lived handover code.

Request example

curl --request POST 'https://api.thebridge.dev/auth/handover/code/YOUR_APP_ID' \
--header 'Content-Type: application/json' \
--data-raw '{ "accessToken": "XXXX" }'

Response example:

{
"code": "XXXX"
}
POST Try it out
POST https://api.thebridge.dev/auth/handover/code/YOUR_APP_ID
Stored in session memory only. Never persisted.
The ID of your app