import { ADUser, ADGroup, ADTokens, ADAuthError, ADUserAttributes, TokenAcquisitionRequest, ADProviderType } from './types'; import { Role, Permission } from '../types'; /** * Return type for the useActiveDirectory hook. */ export interface UseActiveDirectoryReturn { /** Current authenticated AD user */ user: ADUser | null; /** Whether user is authenticated */ isAuthenticated: boolean; /** Whether authentication is in progress */ isAuthenticating: boolean; /** Whether token refresh is in progress */ isRefreshing: boolean; /** Current authentication error */ error: ADAuthError | null; /** Current AD provider type */ provider: ADProviderType | null; /** Current tokens (use with caution) */ tokens: ADTokens | null; /** Whether an SSO session exists */ hasSsoSession: boolean; /** Initialize AD authentication */ initialize: () => Promise; /** Trigger interactive login */ login: (options?: TokenAcquisitionRequest) => Promise; /** Perform silent SSO login */ loginSilent: (options?: TokenAcquisitionRequest) => Promise; /** Logout and clear session */ logout: () => Promise; /** Acquire token for specific scopes */ acquireToken: (request: TokenAcquisitionRequest) => Promise; /** Refresh current tokens */ refreshTokens: () => Promise; /** Clear authentication error */ clearError: () => void; /** Force re-authentication */ forceReauth: () => Promise; /** User's AD groups */ groups: ADGroup[]; /** Check if user belongs to a group */ isInGroup: (groupId: string) => boolean; /** Check if user belongs to any of the groups */ isInAnyGroup: (groupIds: string[]) => boolean; /** Check if user belongs to all groups */ isInAllGroups: (groupIds: string[]) => boolean; /** Get user's mapped roles */ roles: Role[]; /** Check if user has a role */ hasRole: (role: Role) => boolean; /** Check if user has any of the roles */ hasAnyRole: (roles: Role[]) => boolean; /** Check if user has all roles */ hasAllRoles: (roles: Role[]) => boolean; /** Get user's effective permissions */ permissions: Permission[]; /** Check if user has a permission */ hasPermission: (permission: Permission) => boolean; /** Check if user has any of the permissions */ hasAnyPermission: (permissions: Permission[]) => boolean; /** Check if user has all permissions */ hasAllPermissions: (permissions: Permission[]) => boolean; /** Get AD attribute value */ getAttribute: (key: K) => ADUserAttributes[K] | undefined; /** Check if user has specific attribute value */ hasAttribute: (key: keyof ADUserAttributes, value: unknown) => boolean; /** Get user's UPN */ upn: string | null; /** Get user's display name */ displayName: string | null; /** Get user's department */ department: string | null; /** Get user's job title */ jobTitle: string | null; /** Whether user is a guest/external user */ isGuest: boolean; } /** * React hook for Active Directory authentication. * * Provides comprehensive AD authentication functionality including * login/logout, token management, group membership checking, and * attribute access. * * @example * ```tsx * function MyComponent() { * const { * user, * isAuthenticated, * login, * logout, * isInGroup, * hasPermission, * } = useActiveDirectory(); * * if (!isAuthenticated) { * return ; * } * * return ( *
*

Welcome, {user?.displayName}

* {isInGroup('sg-app-admins') && ( * * )} * {hasPermission('reports:view') && ( * * )} * *
* ); * } * ``` * * @returns AD authentication state and methods * @throws Error if used outside of ADProvider */ export declare function useActiveDirectory(): UseActiveDirectoryReturn; /** * Hook for checking AD group memberships. * * @example * ```tsx * function AdminPanel() { * const { isInGroup, isInAnyGroup, groups } = useADGroups(); * * if (!isInAnyGroup(['sg-app-admins', 'sg-app-superusers'])) { * return ; * } * * return
Admin content...
; * } * ``` */ export declare function useADGroups(): { groups: ADGroup[]; isInGroup: (groupId: string) => boolean; isInAnyGroup: (groupIds: string[]) => boolean; isInAllGroups: (groupIds: string[]) => boolean; }; /** * Hook for checking AD-based roles. * * @example * ```tsx * function ManagerDashboard() { * const { hasRole, hasAnyRole, roles } = useADRoles(); * * if (!hasAnyRole(['admin', 'manager'])) { * return ; * } * * return
Manager dashboard...
; * } * ``` */ export declare function useADRoles(): { roles: Role[]; hasRole: (role: Role) => boolean; hasAnyRole: (roles: Role[]) => boolean; hasAllRoles: (roles: Role[]) => boolean; }; /** * Hook for checking AD-based permissions. * * @example * ```tsx * function ReportsPage() { * const { hasPermission, hasAllPermissions } = useADPermissions(); * * const canViewReports = hasPermission('reports:view'); * const canExportReports = hasPermission('reports:export'); * * return ( *
* {canViewReports && } * {canExportReports && } *
* ); * } * ``` */ export declare function useADPermissions(): { permissions: Permission[]; hasPermission: (permission: Permission) => boolean; hasAnyPermission: (permissions: Permission[]) => boolean; hasAllPermissions: (permissions: Permission[]) => boolean; }; /** * Hook for accessing AD user attributes. * * @example * ```tsx * function UserProfile() { * const { getAttribute, upn, department, jobTitle } = useADAttributes(); * * const employeeId = getAttribute('employeeId'); * * return ( *
*

UPN: {upn}

*

Department: {department}

*

Job Title: {jobTitle}

*

Employee ID: {employeeId}

*
* ); * } * ``` */ export declare function useADAttributes(): { attributes: ADUserAttributes | null; getAttribute: (key: K) => ADUserAttributes[K] | undefined; hasAttribute: (key: keyof ADUserAttributes, value: unknown) => boolean; upn: string | null; displayName: string | null; department: string | null; jobTitle: string | null; isGuest: boolean; }; /** * Hook for AD authentication actions only. * * @example * ```tsx * function LoginButton() { * const { login, isAuthenticating, error } = useADAuth(); * * return ( * * ); * } * ``` */ export declare function useADAuth(): { isAuthenticated: boolean; isAuthenticating: boolean; error: ADAuthError | null; initialize: () => Promise; login: (options?: TokenAcquisitionRequest) => Promise; loginSilent: (options?: TokenAcquisitionRequest) => Promise; logout: () => Promise; acquireToken: (request: TokenAcquisitionRequest) => Promise; refreshTokens: () => Promise; clearError: () => void; forceReauth: () => Promise; }; /** * Hook for accessing raw AD tokens (use with caution). * * @example * ```tsx * function ApiClient() { * const { accessToken, isExpired, refreshTokens } = useADTokens(); * * const makeApiCall = async () => { * if (isExpired) { * await refreshTokens(); * } * * const response = await fetch('/api/data', { * headers: { Authorization: `Bearer ${accessToken}` }, * }); * // ... * }; * * return ; * } * ``` */ export declare function useADTokens(): { accessToken: string | null; idToken: string | null; expiresAt: number | null; scopes: string[]; getIsExpired: () => boolean; getTimeUntilExpiry: () => number; isRefreshing: boolean; refreshTokens: () => Promise; };