Protect Your API

Learn how to secure your API endpoints using Authority's token validation.

Prerequisites

What You'll Learn

  • Validate access tokens server-side

  • Implement scope-based access control

  • Handle token expiration gracefully

Token Validation Approaches

There are two ways to validate tokens:

  1. Local validation - Verify JWT signature using Authority's public keys

  2. Token introspection - Ask Authority if the token is valid

When to Use Each

Approach
Use When

Local validation

Low latency required, stateless validation

Token introspection

Need real-time revocation checks, opaque tokens

Approach 1: Local JWT Validation

Step 1: Fetch the JWKS

Authority publishes its public keys at /.well-known/jwks.json:

Step 2: Validate the Token

Node.js Example:

Python Example:

Step 3: Create Middleware

Express.js Middleware:

Approach 2: Token Introspection

For real-time validation, use the introspection endpoint.

Step 1: Configure Client Credentials

Token introspection requires client authentication:

Step 2: Introspect the Token

The response:

If the token is invalid or revoked:

Scope-Based Access Control

Define Scopes

Configure scopes in Authority's admin dashboard:

Scope
Description

read

Read-only access

write

Create and update resources

admin

Administrative operations

Check Scopes in Middleware

Handling Token Expiration

Client-Side: Refresh Before Expiry

Server-Side: Return Clear Errors

Next Steps

Last updated

Was this helpful?