Skip to content

Commit 49dfc47

Browse files
added programmatic PAR implementation
1 parent b631938 commit 49dfc47

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

EXAMPLES.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,3 +752,41 @@ const sessionCookieValue = await generateSessionCookie(
752752
}
753753
)
754754
```
755+
756+
757+
## Programmatic Pushed Authentication Requests (PAR)
758+
759+
The method `startInteractiveLogin` can be called with authorizationParams to initiate an interactive login flow.
760+
It's similar to the `handleLogin` method but `authorizationParams` are explicitly provided here.
761+
The code collects authorization parameters on the server side rather than constructing them directly in the browser.
762+
763+
```typescript
764+
// app/api/auth/login/route.ts
765+
import { getAuth0 } from '@auth0/nextjs-auth0';
766+
import { NextRequest } from 'next/server';
767+
import { auth0Config } from '@/auth0-config';
768+
769+
export const GET = async (req: NextRequest) => {
770+
const auth0 = getAuth0(auth0Config);
771+
772+
try {
773+
// Extract custom parameters from request URL if needed
774+
const searchParams = Object.fromEntries(req.nextUrl.searchParams.entries());
775+
776+
// Call startInteractiveLogin with optional parameters
777+
return auth0.startInteractiveLogin({
778+
returnTo: searchParams.returnTo || '/dashboard',
779+
authorizationParameters: {
780+
// Add any custom auth parameters
781+
prompt: searchParams.prompt,
782+
login_hint: searchParams.login_hint,
783+
// You can specify a different audience for specific resources
784+
audience: searchParams.audience || auth0Config.authorizationParams.audience
785+
}
786+
});
787+
} catch (error) {
788+
console.error('Login error:', error);
789+
return new Response('Login failed', { status: 500 });
790+
}
791+
};
792+
```

0 commit comments

Comments
 (0)