Skip to main content

<AsgardeoProvider />

You're reading Identity & Access Management 7.2.0. The newest release is 7.3.0, and Cloud has the newest features. Go to the newest release

The AsgardeoProvider is the root context provider component that configures the @asgardeo/nextjs and provides authentication context to your entire Next.js application. It must wrap your application to enable authentication features.

Overview​

The AsgardeoProvider initializes the WSO2 Identity Platform authentication client, manages authentication state, and provides context to child components through React Context. It handles token management, user sessions, organization switching, and branding preferences automatically.

Usage​

The AsgardeoProvider must be used at the root of your Next.js application to ensure that all components have access to authentication features.

Basic Usage​

A minimal setup involves wrapping your root component with the AsgardeoProvider and providing the necessary clientId, clientSecret, and baseUrl.

app/layout.tsx
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import {AsgardeoProvider} from '@asgardeo/nextjs/server';
import "./globals.css";

const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});

const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
<AsgardeoProvider>{children}</AsgardeoProvider>
</body>
</html>
);
}
.env
NEXT_PUBLIC_ASGARDEO_BASE_URL="https://localhost:9443"
NEXT_PUBLIC_ASGARDEO_CLIENT_ID="<your-app-client-id>"
ASGARDEO_CLIENT_SECRET="<your-app-client-secret>"
# Secret used for signing JWT session cookies (change this in production!)
ASGARDEO_SECRET='<your-super-secret-key-for-jwt-signing-change-this-in-production>'
Note

It is possible to pass the clientId, clientSecret, and baseUrl as props to the AsgardeoProvider component, but it is recommended to use environment variables for better security and flexibility.

Advanced Usage​

For more advanced configurations, you can provide additional props such as:

  • scopes: Specifies the OpenID Connect scopes to request during sign-in.
  • afterSignInUrl: URL to redirect to after successful sign-in.
  • afterSignOutUrl: URL to redirect to after sign-out.
  • preferences: Customization options for UI behavior, theming, and internationalization (i18n).
  • etc.

For a complete list of props, refer to the Props section below.

app/layout.tsx
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import {AsgardeoProvider} from '@asgardeo/nextjs/server';
import "./globals.css";

const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});

const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
<AsgardeoProvider

preferences={{
theme: {
inheritFromBranding: false,
mode: 'dark',
overrides: {
colors: {
primary: '#ff0000',
},
},
},
i18n: {
language: 'fr-FR',
fallbackLanguage: 'en-US',
bundles: {
'fr-FR': {
'signin.title': 'Connexion',
'user.profile.title': 'Profil utilisateur',
'user.profile.update.generic.error': "Une erreur s'est produite lors de la mise à jour du profil. Veuillez réessayer.",
},
'es-ES': {
'signin.title': 'Iniciar sesión',
'user.profile.title': 'Perfil de usuario',
'user.profile.update.generic.error': 'Ocurrió un error al actualizar el perfil. Por favor, inténtalo de nuevo.',
},
},
},
}}
>
{children}
</AsgardeoProvider>
</body>
</html>
);
}
.env
NEXT_PUBLIC_ASGARDEO_BASE_URL="https://localhost:9443"
NEXT_PUBLIC_ASGARDEO_CLIENT_ID="<your-app-client-id>"
ASGARDEO_CLIENT_SECRET="<your-app-client-secret>"
ASGARDEO_SECRET='<your-super-secret-key-for-jwt-signing-change-this-in-production>'
NEXT_PUBLIC_ASGARDEO_AFTER_SIGN_IN_URL='http://localhost:3000/dashboard'
NEXT_PUBLIC_ASGARDEO_SIGN_IN_URL='/signin'
NEXT_PUBLIC_ASGARDEO_SIGN_UP_URL='/signup'
NEXT_PUBLIC_ASGARDEO_SCOPES='internal_organization_create internal_organization_view internal_organization_update internal_organization_delete'

Props​

The AsgardeoProvider component accepts the following props:

PropTypeRequiredDescriptionEnvironment Variable
clientIdstring✅Client ID of your applicationNEXT_PUBLIC_ASGARDEO_CLIENT_ID
baseUrlstring✅The base URL of the WSO2 Identity Platform tenant (e.g., https://api.asgardeo.io/t/abc-org)NEXT_PUBLIC_ASGARDEO_BASE_URL
clientSecretstring✅Client secret of your applicationASGARDEO_CLIENT_SECRET
scopesstring | string[]❌OpenID Connect Scopes to request during the sign-in. Defaults to 'openid profile internal_login' if not provided.NEXT_PUBLIC_ASGARDEO_SCOPES
storagesessionStorage | localStorage | webWorker❌Storage mechanism to use for session management. Defaults to sessionStorage if not provided.
afterSignInUrlstring❌URL to redirect to after sign-in process is completed.NEXT_PUBLIC_ASGARDEO_AFTER_SIGN_IN_URL
afterSignUpUrlstring❌URL to redirect to after sign-up process is completed.NEXT_PUBLIC_ASGARDEO_SIGN_UP_URL
afterSignOutUrlstring❌URL to redirect to after sign-out process is completed.NEXT_PUBLIC_ASGARDEO_AFTER_SIGN_OUT_URL
tokenValidationTokenValidation❌Configuration for token validation.
preferencesPreferences❌Customization options for UI behavior, internationalization (i18n) and styling.

TokenValidation

The tokenValidation prop allows you to configure how ID tokens are validated.

PropertyTypeDefaultDescription
idTokenIdTokenValidation{}Configuration for ID token validation
IdTokenValidation
PropertyTypeDefaultDescription
validatebooleantrueWhether to validate the ID token
validateIssuerbooleantrueWhether to validate the issuer
clockTolerancenumber300Allowed clock skew in seconds

Preferences

The preferences prop allows you to customize the UI components provided by the SDK.

Theme Preferences (preferences.theme)
PropertyTypeDefaultDescription
inheritFromBrandingbooleantrueWhether to inherit theme from WSO2 Identity Platform organization/application branding
modelight | dark | system'system'Theme mode. 'system' follows user's OS preference
overridesThemeConfig{}Custom theme overrides for colors, typography, spacing, etc.
Internationalization Preferences (preferences.i18n)
PropertyTypeDefaultDescription
languagestringBrowser defaultLanguage code for UI text (e.g., 'en-US', 'es-ES')
fallbackLanguagestring'en-US'Fallback language when translations aren't available
bundlesobject{}Custom translation bundles to override default text

Was this page helpful?