Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- [Usage Example](#usage-example)
- [Token Management Best Practices](#token-management-best-practices)
- [Mitigating Token Expiration Race Conditions in Latency-Sensitive Operations](#mitigating-token-expiration-race-conditions-in-latency-sensitive-operations)
- [Silent authentication](#silent-authentication)
- [DPoP (Demonstrating Proof-of-Possession)](#dpop-demonstrating-proof-of-possession)
- [What is DPoP?](#what-is-dpop)
- [Basic DPoP Setup](#basic-dpop-setup)
Expand Down Expand Up @@ -1065,6 +1066,46 @@ This ensures that the token you send is guaranteed to be valid for at least the
> [!IMPORTANT]
> This strategy is **not** a solution for long-running operations that take longer than the token's total validity period (e.g., 10 minutes). In those cases, the token will still expire mid-operation. The correct approach for long-running tasks is to call `getAccessToken()` immediately before the operation that requires it, ensuring you have a fresh token. The buffer is only for mitigating latency-related failures in short-lived requests.

## Silent authentication

Silent authentication checks for an existing Auth0 session without user interaction. Use `prompt: 'none'` as an authorization parameter.

**Custom route:**

```typescript
// app/api/auth/silent/route.ts
import { auth0 } from '@/lib/auth0';
import { NextRequest } from 'next/server';

export const GET = async (req: NextRequest) => {
return auth0.startInteractiveLogin({
authorizationParameters: { prompt: 'none' },
returnTo: req.nextUrl.searchParams.get('returnTo') || '/'
});
};
```

**Built-in route with query param:**

```html
<a href="/auth/login?prompt=none">Silent Auth</a>
```

**Error handling:**

Auth0 returns `login_required` when no active session exists. Handle gracefully:

```typescript
try {
return await auth0.startInteractiveLogin({
authorizationParameters: { prompt: 'none' }
});
} catch (error) {
// Redirect to interactive login
return NextResponse.redirect('/auth/login');
}
```

## DPoP (Demonstrating Proof-of-Possession)

DPoP is an OAuth 2.0 extension that enhances security by binding access tokens to a client's private key. This prevents token theft and replay attacks by requiring cryptographic proof that the client possessing the token also possesses the private key used to request it.
Expand Down
3 changes: 3 additions & 0 deletions V4_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ export const auth0 = new Auth0Client({

Read more about [passing authorization parameters](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#passing-authorization-parameters).

> [!NOTE]
> In previous versions, `authParams` was used. In v4, use `authorizationParameters`. For example, for silent authentication: `authorizationParameters: { prompt: 'none' }`.

## ID token claims

In v3, any claims added to the ID token were automatically propagated to the `user` object in the session. This resulted in the large cookies that exceeded browser limits.
Expand Down