Application authentication
Add Kinde authentication to a React single-page application.
Kinde · Component
KindeProvider configures the Kinde React SDK and supplies authentication context to the application tree. Set the client, domain, redirect URIs, and optionally an API audience or scope.
KindeProvider initializes the Kinde React SDK and supplies its authentication context to descendant components. Configure it with the client, domain, and redirect values, then render the application inside it.
<KindeProvider clientId="..." domain="..." logoutUri="..." redirectUri="...">{children}</KindeProvider>| Name | Type | Description |
|---|---|---|
clientId | string | Kinde application client identifier. |
domain | string | Kinde environment domain. |
logoutUri | string | URI to which the user is sent after logout. |
redirectUri | string | URI to which the user is sent after authentication. |
audience | string | Optional registered API identifier requested as the token audience. |
scope | string | Optional OAuth scope override. |
A React provider that supplies Kinde authentication context to its descendants.
import { KindeProvider } from '@kinde-oss/kinde-auth-react';
export default function App() {
return (
<KindeProvider
clientId={import.meta.env.VITE_KINDE_CLIENT_ID}
domain={import.meta.env.VITE_KINDE_DOMAIN}
logoutUri={window.location.origin}
redirectUri={window.location.origin}
>
<Routes />
</KindeProvider>
);
}Wrap the application tree so the React SDK can provide authentication state and functionality through context.
Add Kinde authentication to a React single-page application.
Request tokens intended for a registered backend API.
Control the OAuth permissions requested during sign-in.
KindeProvider is a React Context Provider that maintains Kinde's internal state. It should wrap the application components that need access to the SDK's authentication capabilities.
Follow-up: Why must the provider be above consumers? React context values are available only to descendants, so placing it lower leaves other components without the Kinde context.
The provider accepts clientId, domain, logoutUri, and redirectUri to configure the client and its OAuth redirect behavior. The application is rendered as a child of the provider.
Follow-up: How would you request an API-specific access token? Register the API, then pass its identifier through the audience prop.
The audience identifies the intended recipient of an access token, such as an application's API. Pass the registered API identifier as the audience prop when initializing KindeProvider.
Follow-up: What if the requested permissions differ from the defaults? Supply the required complete value through the scope prop.
React SDKKinde Authaudiencescope