import { AuthProvider } from 'authsafe-react';
function App() {
return (
<AuthProvider
config={{
clientId: 'your-client-id',
redirectUri: 'http://localhost:3000/callback',
}}
>
<YourApp />
</AuthProvider>
);
}| Property | Type | Required | Description |
|---|---|---|---|
config | AuthConfig | Yes | Configuration object containing clientId, redirectUri, scopes, and optional settings |
children | React.ReactNode | Yes | Your application components |
queryClient | QueryClient | No | Optional TanStack Query client for advanced data fetching and caching |
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
clientId | string | Yes | - | Unique identifier for your OAuth2 client from AuthSafe dashboard |
redirectUri | string | Yes | - | URI to redirect to after authentication (callback URL) |
scope | Array<AuthScope> | No | ['openid', 'profile'] | Array of requested OAuth scopes. Options: 'openid', 'profile', 'email', 'offline_access' |
env | 'development' | 'production' | No | 'production' | Environment to use this provider (affects logging and error handling) |
authority | string | No | 'https://authsafe.in' | Optional custom authority URL for the OAuth server |
popupRedirectUri | string | No | - | Optional URI for popup authentication callback |
automaticSilentRenew | boolean | No | false | Optional flag to enable automatic token renewal before expiration |
import { AuthProvider } from 'authsafe-react';
function App() {
return (
<AuthProvider
config={{
clientId: 'your-client-id',
redirectUri: 'http://localhost:3000/callback',
scope: ['openid', 'profile', 'email', 'offline_access'],
env: 'production',
authority: 'https://authsafe.in',
popupRedirectUri: 'http://localhost:3000/popup-callback',
automaticSilentRenew: true,
}}
>
<YourApp />
</AuthProvider>
);
}queryClient instance:
import { AuthProvider } from 'authsafe-react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
function App() {
return (
<QueryClientProvider client={queryClient}>
<AuthProvider
config={{
clientId: 'your-client-id',
redirectUri: 'http://localhost:3000/callback',
scope: ['openid', 'profile', 'email'],
}}
queryClient={queryClient}
>
<YourApp />
</AuthProvider>
</QueryClientProvider>
);
}/**
* User profile from OIDC userinfo endpoint
*/
export interface User {
sub: string;
email?: string;
name?: string;
email_verified?: boolean;
[key: string]: any;
}
/**
* OAuth2 scopes supported by AuthSafe.
*/
export type AuthScope = "openid" | "profile" | "email" | "offline_access";
/**
* Configuration for initializing the AuthSafe SDK.
*/
export interface AuthConfig {
clientId: string;
redirectUri: string;
scope?: Array<AuthScope>;
env?: "development" | "production";
authority?: string;
popupRedirectUri?: string;
automaticSilentRenew?: boolean;
}
export interface AuthProviderProps {
config: AuthConfig;
children: React.ReactNode;
queryClient?: QueryClient;
}