Step 3: Implement Authorization Flow

Now it's time to implement the OAuth 2.0 authorization flow.

IMPORTANT: Authorization requirements depend on your client type:

  • Confidential Clients (Server-side): JAR (JWT-Secured Authorization Request) is REQUIRED

  • Public Clients (SPAs/Mobile): PKCE is REQUIRED, JAR is FORBIDDEN

📖 Need context? Check the Integration Flow Overview to see how this step fits into the complete process.

🎯 What You'll Learn

In this step, you will learn:

For Confidential Clients (Server-side applications):

  • Create JAR (JWT-Secured Authorization Request) - REQUIRED

  • Sign authorization parameters in JWT format

  • Handle state parameter for CSRF protection

  • Redirect users to Oten IDP with signed requests

For Public Clients (SPAs/Mobile apps):

  • Implement PKCE (Proof Key for Code Exchange) - REQUIRED

  • Generate secure code verifier and challenge

  • Handle state parameter for CSRF protection

  • Use direct authorization parameters (NO JAR)

📖 Public Client (SPA/Mobile)? For comprehensive PKCE implementation with complete code examples, see the PKCE Implementation Guidearrow-up-right or PKCE without JAR Guidearrow-up-right.

🔄 Authorization Flow Overview

Authorization Flow Overview

This diagram shows the authorization flow. The specific requirements depend on your client type:

  • Confidential Clients: Must use JAR (JWT-Secured Authorization Request)

  • Public Clients: Must use PKCE with direct parameters (JAR forbidden)

🔒 JAR (JWT-Secured Authorization Request) - For Confidential Clients

Confidential clients (server-side applications) MUST use JAR for enhanced security. Public clients MUST NOT use JAR.

Can't implement JAR? If your confidential client application cannot support JAR due to technical constraints, contact [email protected]envelope to discuss alternative solutions.

Why JAR is Required for Confidential Clients

JAR Parameters Explained

JAR (JWT Authorization Request) consists of two main parts: JWT Claims and OAuth Parameters. All OAuth parameters must be included in the JWT payload instead of URL query parameters.

Standard JWT Claims (Required)

Parameter
Description
Example
Notes

iss

Issuer - Your client ID

"your-client-id"

Must match client_id

aud

Audience - Oten IDP endpoint

"https://account.oten.com"

Fixed for Oten

iat

Issued At - JWT creation time (Unix timestamp)

1672531200

Current time

exp

Expiration - JWT expiry time (Unix timestamp)

1672531500

Max 5 minutes after iat

jti

JWT ID - Unique identifier for request

"uuid-v4-string"

Prevents replay attacks

🌐 OAuth Parameters (Required)

Parameter
Description
Value
Notes

client_id

Application client ID

"your-client-id"

Must match iss

redirect_uri

Callback URL after authorization

"https://yourapp.com/callback"

Must be pre-registered

response_type

Desired response type

"code"

Always "code" for Authorization Code flow

scope

Requested access permissions

"openid profile email"

Minimum requires "openid"

state

CSRF protection parameter

"random-string-32-chars"

Protects against CSRF

🔐 PKCE Parameters (REQUIRED for Public Clients)

Parameter
Description
Example
Notes

code_challenge

SHA256 hash of code_verifier

"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"

Base64URL encoded

code_challenge_method

Hash method

"S256"

Always "S256"

🎨 UI/UX Parameters (Optional)

Parameter
Description
Default Value
Examples

prompt

UI display behavior

"consent"

"none", "login", "consent", "select_account"

ui_locales

Interface language

"en-US"

"vi-VN", "en-US", "ja-JP"

login_hint

Email/username hint

-

max_age

Max time since last login (seconds)

3600

0 (force re-auth), 7200

🏢 Oten Specific Parameters (Optional)

Parameter
Description
Example
Notes

workspace_hint

Workspace ID hint

"workspace-123"

Auto-select workspace

nonce

Random value to link ID token

"random-nonce-value"

Additional security

📝 Complete JAR Payload Example

🎯 JAR Parameter Usage Examples

Prompt Parameter Values

UI Locales Support (coming soon)

Workspace Hint Usage (coming soon)

Advanced Security with Nonce

JAR Implementation (Confidential Clients Only)

Oten IDP supports two signing methods for confidential clients:

Method 1: HS256 (Client Secret) - Simpler

Method 2: EdDSA (Ed25519 Key Pair) - More Secure

🔑 JAR Key Management

For HS256 (Client Secret) - No Key Generation Needed

When using HS256, you use your existing client secret:

For EdDSA (Ed25519) - Key Generation Required

When using EdDSA, you need to generate Ed25519 key pairs:

🌐 Implementation Examples

Express.js Implementation

Option 1: Using HS256 (Client Secret)

Option 2: Using EdDSA (Ed25519 Key Pair)

React SPA Implementation

Note: For SPAs, you'll need a backend service to create JAR since private keys cannot be stored in browsers.

Python Flask Implementation

🎛️ Advanced JAR Parameters

Custom Parameters in JAR

JAR with Different Options

JAR Parameter Validation

Required Parameter Validation

JWT Claims Validation

🚨 Common JAR Parameter Errors

Error: "Invalid request parameter"

Error: "JWT signature verification failed"

Error: "Request JWT expired"

Error: "Invalid redirect_uri"

🧪 Testing JAR Implementation

Test JAR Creation

Test JWKS Endpoint

Validate JAR Authorization URL

Authorization Flow Checklist

Before proceeding to the callback handling, verify your implementation based on client type:

For Confidential Clients (Server-side) - JAR Required

HS256 (Client Secret)

EdDSA (Ed25519 Key Pair)

For Public Clients (SPAs/Mobile) - PKCE Required, JAR Forbidden

📚 JAR Parameters Best Practices

🔒 Security Best Practices

🎯 Parameter Selection Guide

Use Case
Recommended Parameters
Example

Basic Login

Standard OAuth + PKCE

scope: "openid profile email"

Force Re-auth

Add max_age=0 + prompt=login

max_age: 0, prompt: "login"

Silent Auth

prompt=none

prompt: "none" (will fail if not logged in)

Multi-language

ui_locales

ui_locales: "vi-VN en-US"

Workspace App

workspace_hint

workspace_hint: "workspace-123"

High Security

Short expiry + nonce

exp: now + 60, nonce: "random"

🔄 Parameter Lifecycle Management

JAR Parameter Monitoring

⚠️ Common Mistakes to Avoid

For Confidential Clients (JAR)

  • Don't send parameters in URL query - Oten will reject them for confidential clients

  • Don't use unsupported algorithms - Only HS256 and EdDSA are supported

  • Don't forget kid in JWT header for EdDSA - Must match your JWKS

  • Don't make JAR expire too long - 5 minutes maximum recommended

  • Don't store private keys in client-side code - Use backend for SPAs

  • Don't use RSA keys - Oten only supports HS256 and EdDSA

  • Don't reuse JTI values - Each JAR must have unique identifier

  • Don't include sensitive data - JAR is base64 encoded, not encrypted

For Public Clients (PKCE)

  • Don't use JAR - JAR is forbidden for public clients

  • Don't use weak code verifiers - Must be 128 characters with sufficient entropy

  • Don't store code verifier insecurely - Use sessionStorage (SPA) or Keychain/Keystore (mobile)

  • Don't skip state validation - Always validate state parameter to prevent CSRF

  • Don't use HTTP - HTTPS is required for all OAuth flows

  • Don't include client_secret - Public clients must not use client secrets


Next: Step 4: Handle Callback

Last updated