OpenID Connect & OAuth 2.0 Integration
Zanthem Identity Services supports application integration through OpenID Connect and OAuth 2.0.
These protocols allow applications to authenticate users and obtain authorized access to protected resources without directly handling user passwords.
OpenID Connect and OAuth 2.0
Although closely related, OpenID Connect and OAuth 2.0 serve different purposes.
| Protocol | Purpose |
|---|---|
| OAuth 2.0 | Delegated authorization and access to protected resources. |
| OpenID Connect | User authentication and identity information built on OAuth 2.0. |
Applications requiring user authentication should use OpenID Connect rather than attempting to infer user identity from an OAuth 2.0 access token alone.
Required Configuration
Before integrating an application, obtain the assigned configuration from your Zanthem account manager.
| Configuration | Example |
|---|---|
| Issuer URL | https://auth.zanthem.cloud/realms/example-company |
| Client ID | example-app |
| Client secret | Required only for approved confidential clients. |
| Redirect URI | https://app.example.com/callback |
| Logout redirect URI | https://app.example.com/ |
| Scopes | openid profile email |
| Authentication flow | Authorization Code with PKCE |
The example values must be replaced with your assigned configuration.
Supported Authentication Flows
Authorization Code with PKCE
Authorization Code with Proof Key for Code Exchange is the recommended flow for interactive user authentication.
This flow is appropriate for:
- Browser-based applications
- Server-side web applications
- Mobile applications
- Desktop applications
Client Credentials
The Client Credentials flow provides machine-to-machine authentication for approved confidential service clients.
This flow does not authenticate an individual human user.
Refresh Token
The Refresh Token grant allows applications to obtain additional access tokens using a valid refresh token, where issued.
Authentication Workflow
A typical interactive authentication transaction proceeds as follows:
User
|
v
Client Application
|
| Authorization request
v
Zanthem Identity Services
|
| User authentication and MFA
|
| Authorization code
v
Application Callback
|
| Code exchange
v
Token Endpoint
|
| ID token and access token
v
Authenticated Application Session
The application must validate the authentication response before creating an authenticated session.
Step 1 — Configure Service Discovery
Configure your authentication library using your assigned issuer URL.
https://auth.zanthem.cloud/realms/example-company
The authentication library should obtain service metadata from:
https://auth.zanthem.cloud/realms/example-company/.well-known/openid-configuration
Service discovery provides the appropriate authorization, token, user information, signing key, and logout endpoints.
Validate that the discovered issuer matches the configured trusted issuer.
View service discovery specifications
Step 2 — Configure the Application Client
Configure the application client identifier, redirect URI, and required authentication scopes.
Example Configuration Object
const authConfig = {
authority:
'https://auth.zanthem.cloud/realms/example-company',
client_id: 'example-app',
redirect_uri:
'https://app.example.com/callback',
post_logout_redirect_uri:
'https://app.example.com/',
response_type: 'code',
scope: 'openid profile email',
};
The example uses common OpenID Connect client configuration property names.
Property names may differ between authentication libraries.
PKCE using S256 must be enabled according to the selected library's configuration requirements.
Step 3 — Initiate Authentication
When authentication is required, the application redirects the user to the authorization endpoint.
The authentication library should generate:
- Authentication state
- OpenID Connect nonce
- PKCE verifier
- PKCE challenge
These values must be generated securely for each authentication transaction.
The application should allow the authentication library to manage these transaction values.
View authorization endpoint specifications
Step 4 — Complete User Authentication
The user authenticates through the assigned Zanthem authentication interface.
Depending on the configured policies, the user may be required to complete:
- Username and password authentication
- Multi-factor authentication
- External identity provider authentication
- Account verification
- Required account setup actions
Applications should not collect or process the user's authentication password directly.
Authentication credentials are handled through the assigned authentication interface or approved external provider.
Step 5 — Handle the Authentication Callback
After successful authentication, the user is redirected to the registered application callback URI.
For example:
https://app.example.com/callback?code=AUTHORIZATION_CODE&state=GENERATED_STATE
The application must:
- Process the authentication response.
- Validate the returned authentication state.
- Confirm the expected issuer where supplied.
- Exchange the authorization code.
- Validate the returned identity token.
- Establish the local application session.
Use the authentication library's callback processing functionality.
Do not manually trust callback parameters without validation.
Step 6 — Exchange the Authorization Code
The authorization code is exchanged through the token endpoint.
The application supplies the required client configuration and original PKCE verifier.
Confidential clients additionally authenticate using their approved client authentication method.
View token endpoint specifications
Step 7 — Establish the Application Session
Following successful token validation, the application establishes its own authenticated session.
Applications should retain only the identity and authentication information necessary for their functionality.
An application session must not remain authorized indefinitely without accounting for authentication expiration and application security requirements.
Example Browser Integration
The following example demonstrates a browser-based integration using a standard OpenID Connect library.
Install the Library
npm install oidc-client-ts
Authentication Configuration
import {
UserManager,
WebStorageStateStore,
} from 'oidc-client-ts';
export const auth = new UserManager({
authority:
'https://auth.zanthem.cloud/realms/example-company',
client_id: 'example-app',
redirect_uri:
'https://app.example.com/callback',
post_logout_redirect_uri:
'https://app.example.com/',
response_type: 'code',
scope: 'openid profile email',
disablePKCE: false,
automaticSilentRenew: false,
userStore: new WebStorageStateStore({
store: window.sessionStorage,
}),
});
This configuration is intended for execution within a browser environment.
Do not initialize browser-specific authentication code during server-side rendering.
Sign In
import {auth} from './auth';
export async function signIn() {
await auth.signinRedirect();
}
Authentication Callback
import {auth} from './auth';
export async function handleCallback() {
const user = await auth.signinRedirectCallback();
window.history.replaceState(
{},
document.title,
'/'
);
return user;
}
Retrieve the Authenticated User
import {auth} from './auth';
export async function getCurrentUser() {
const user = await auth.getUser();
if (!user || user.expired) {
return null;
}
return user;
}
Sign Out
import {auth} from './auth';
export async function signOut() {
await auth.signoutRedirect();
}
Process the Logout Callback
import {auth} from './auth';
export async function handleLogoutCallback() {
await auth.signoutRedirectCallback();
window.history.replaceState(
{},
document.title,
'/'
);
}
Applications must integrate these functions with their own routing, session handling, and application authorization requirements.
The example intentionally omits automatic session renewal.
Applications must implement an appropriate renewal or reauthentication strategy for their requirements.
:::warning Browser token storage
Browser storage is accessible to JavaScript running within the application origin.
Session storage reduces persistence but does not protect tokens from malicious JavaScript or cross-site scripting.
Applications with higher security requirements should consider a server-side session or backend-for-frontend architecture that keeps authentication tokens outside the browser.
:::
Accessing Protected APIs
Applications use access tokens when requesting protected API resources.
const response = await fetch(
'https://api.example.com/resources',
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
);
The access token must be intended for the receiving resource server.
The protected API must independently validate the access token and enforce the required application permissions.
Token Validation
Applications and resource servers must validate tokens according to their intended purpose.
ID Token Validation
Validate the following where applicable:
- Cryptographic signature
- Expected issuer
- Expected client audience
- Expiration time
- Nonce
- Authorized party
- Approved signing algorithm
Access Token Validation
Validate the following where applicable:
- Cryptographic signature
- Expected issuer
- Expected resource audience
- Expiration time
- Not-before time
- Approved signing algorithm
- Required scopes
- Required permissions
Use maintained authentication and token validation libraries.
Decoding a JWT does not verify its authenticity.
Token Renewal
Applications may receive refresh tokens according to their assigned configuration.
When an access token expires, the application may request a new access token using a valid refresh token.
Applications should:
- Securely retain refresh tokens.
- Replace rotated refresh tokens.
- Prevent concurrent refresh operations.
- Handle refresh token expiration.
- Initiate authentication when required.
View token renewal specifications
Machine-to-Machine Integration
Approved service clients may request access tokens using the Client Credentials flow.
curl --request POST \
"https://auth.zanthem.cloud/realms/example-company/protocol/openid-connect/token" \
--user "${CLIENT_ID}:${CLIENT_SECRET}" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=client_credentials"
Machine-to-machine credentials must remain within trusted server-side environments.
The resulting access token represents the service client rather than an authenticated human user.
Logout
Applications should coordinate local session termination with centralized authentication logout where required.
Logout behavior depends on the configured session architecture.
View session management specifications
Integration Security
Applications should follow these security requirements:
- Use HTTPS for production authentication.
- Use Authorization Code with PKCE.
- Validate authentication state and nonce.
- Validate token signatures and claims.
- Restrict approved redirect URIs.
- Protect confidential client credentials.
- Implement application-level authorization.
- Prevent sensitive token logging.
- Handle expired sessions correctly.
- Maintain authentication dependencies.
Password-based token grants and implicit authentication flows are outside the integration methods described in this documentation.