@asgardeo/react 0.2.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -6
- package/dist/AsgardeoReactClient.d.ts +38 -0
- package/dist/__temp__/api.d.ts +228 -0
- package/dist/__temp__/models.d.ts +97 -0
- package/dist/api/scim2/getMeProfile.d.ts +39 -0
- package/dist/api/scim2/getSchemas.d.ts +39 -0
- package/dist/api/scim2/updateMeProfile.d.ts +38 -0
- package/dist/cjs/index.js +17998 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/components/actions/SignInButton/BaseSignInButton.d.ts +66 -0
- package/dist/components/actions/SignInButton/SignInButton.d.ts +65 -0
- package/dist/components/actions/SignOutButton/BaseSignOutButton.d.ts +66 -0
- package/dist/components/actions/SignOutButton/SignOutButton.d.ts +65 -0
- package/dist/components/actions/SignUpButton/BaseSignUpButton.d.ts +66 -0
- package/dist/components/actions/SignUpButton/SignUpButton.d.ts +66 -0
- package/dist/components/control/SignedIn.d.ts +45 -0
- package/dist/components/control/SignedOut.d.ts +45 -0
- package/dist/components/factories/FieldFactory.d.ts +107 -0
- package/dist/components/presentation/SignIn/BaseSignIn.d.ts +125 -0
- package/dist/components/presentation/SignIn/SignIn.d.ts +62 -0
- package/dist/{esm/types/hooks/use-config.d.ts → components/presentation/SignIn/options/EmailOtp.d.ts} +7 -5
- package/dist/components/presentation/SignIn/options/FacebookButton.d.ts +25 -0
- package/dist/components/presentation/SignIn/options/GitHubButton.d.ts +25 -0
- package/dist/components/presentation/SignIn/options/GoogleButton.d.ts +25 -0
- package/dist/components/presentation/SignIn/options/IdentifierFirst.d.ts +25 -0
- package/dist/components/presentation/SignIn/options/LinkedInButton.d.ts +25 -0
- package/dist/{esm/types/components/SignIn/fragments/SmsOtp.d.ts → components/presentation/SignIn/options/MicrosoftButton.d.ts} +9 -5
- package/dist/components/presentation/SignIn/options/MultiOptionButton.d.ts +26 -0
- package/dist/components/presentation/SignIn/options/SignInOptionFactory.d.ts +76 -0
- package/dist/{esm/types/components/SignOutButton/SignOutButton.d.ts → components/presentation/SignIn/options/SignInWithEthereumButton.d.ts} +7 -9
- package/dist/{esm/types/contexts/branding-preference-context.d.ts → components/presentation/SignIn/options/SmsOtp.d.ts} +9 -5
- package/dist/components/presentation/SignIn/options/SocialButton.d.ts +25 -0
- package/dist/{esm/types/contexts/asgardeo-context.d.ts → components/presentation/SignIn/options/Totp.d.ts} +9 -5
- package/dist/components/presentation/SignIn/options/UsernamePassword.d.ts +25 -0
- package/dist/components/presentation/SignIn/types.d.ts +124 -0
- package/dist/components/presentation/User/BaseUser.d.ts +66 -0
- package/dist/components/presentation/User/User.d.ts +62 -0
- package/dist/components/presentation/UserDropdown/BaseUserDropdown.d.ts +76 -0
- package/dist/components/presentation/UserDropdown/UserDropdown.d.ts +49 -0
- package/dist/components/presentation/UserProfile/BaseUserProfile.d.ts +63 -0
- package/dist/components/presentation/UserProfile/UserProfile.d.ts +49 -0
- package/dist/components/primitives/Alert/Alert.d.ts +74 -0
- package/dist/{esm/types/components/SignIn/SignIn.d.ts → components/primitives/Avatar/Avatar.d.ts} +25 -14
- package/dist/components/primitives/Button/Button.d.ts +83 -0
- package/dist/components/primitives/Card/Card.d.ts +133 -0
- package/dist/{esm/types/oxygen-ui-react-auth-components/models/component.d.ts → components/primitives/Checkbox/Checkbox.d.ts} +22 -7
- package/dist/components/primitives/DatePicker/DatePicker.d.ts +50 -0
- package/dist/components/primitives/Divider/Divider.d.ts +58 -0
- package/dist/components/primitives/FormControl/FormControl.d.ts +50 -0
- package/dist/components/primitives/Icons/CircleAlert.d.ts +23 -0
- package/dist/components/primitives/Icons/CircleCheck.d.ts +23 -0
- package/dist/{esm/types/models/use-config.d.ts → components/primitives/Icons/Eye.d.ts} +7 -6
- package/dist/{esm/types/contexts/i18n-context.d.ts → components/primitives/Icons/EyeOff.d.ts} +7 -5
- package/dist/{esm/types/hooks/use-on.d.ts → components/primitives/Icons/Info.d.ts} +7 -4
- package/dist/components/primitives/Icons/TriangleAlert.d.ts +23 -0
- package/dist/components/primitives/InputLabel/InputLabel.d.ts +46 -0
- package/dist/components/primitives/OtpField/OtpField.d.ts +86 -0
- package/dist/{esm/types/components/SignInButton/SignInButton.d.ts → components/primitives/PasswordField/PasswordField.d.ts} +13 -11
- package/dist/components/primitives/Popover/Popover.d.ts +96 -0
- package/dist/components/primitives/Select/Select.d.ts +60 -0
- package/dist/components/primitives/Spinner/Spinner.d.ts +54 -0
- package/dist/components/primitives/TextField/TextField.d.ts +62 -0
- package/dist/components/primitives/Typography/Typography.d.ts +81 -0
- package/dist/contexts/Asgardeo/AsgardeoContext.d.ts +57 -0
- package/dist/{esm/types/components/public-components.d.ts → contexts/Asgardeo/AsgardeoProvider.d.ts} +9 -6
- package/dist/contexts/Asgardeo/useAsgardeo.d.ts +20 -0
- package/dist/contexts/Flow/FlowContext.d.ts +73 -0
- package/dist/contexts/Flow/FlowProvider.d.ts +46 -0
- package/dist/contexts/Flow/useFlow.d.ts +48 -0
- package/dist/contexts/I18n/I18nContext.d.ts +42 -0
- package/dist/{esm/types/components/SignedIn/SignedIn.d.ts → contexts/I18n/I18nProvider.d.ts} +12 -10
- package/dist/contexts/I18n/useI18n.d.ts +27 -0
- package/dist/{esm/types/models/asgardeo-provider-props.d.ts → contexts/Theme/ThemeContext.d.ts} +8 -7
- package/dist/{esm/types/models/branding-preference-provider-props.d.ts → contexts/Theme/ThemeProvider.d.ts} +8 -5
- package/dist/{esm/types/models/use-on.d.ts → contexts/Theme/types.d.ts} +22 -12
- package/dist/{esm/types/models/signed-props.d.ts → contexts/Theme/useTheme.d.ts} +4 -6
- package/dist/contexts/User/UserContext.d.ts +32 -0
- package/dist/contexts/User/UserProvider.d.ts +55 -0
- package/dist/contexts/User/useUser.d.ts +94 -0
- package/dist/hooks/useBrowserUrl.d.ts +47 -0
- package/dist/hooks/useForm.d.ts +192 -0
- package/dist/hooks/useTranslation.d.ts +52 -0
- package/dist/index.d.ts +121 -348
- package/dist/index.js +18064 -0
- package/dist/index.js.map +7 -0
- package/dist/{esm/types/models/public-models.d.ts → models/config.d.ts} +3 -3
- package/dist/utils/getMappedUserProfileValue.d.ts +51 -0
- package/package.json +55 -59
- package/dist/esm/index.js +0 -45278
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/types/components/SignIn/fragments/BasicAuth.d.ts +0 -35
- package/dist/esm/types/components/SignIn/fragments/EmailOtp.d.ts +0 -32
- package/dist/esm/types/components/SignIn/fragments/IdentifierFirst.d.ts +0 -35
- package/dist/esm/types/components/SignIn/fragments/LoginOptionsBox.d.ts +0 -30
- package/dist/esm/types/components/SignIn/fragments/Totp.d.ts +0 -33
- package/dist/esm/types/components/SignedOut/SignedOut.d.ts +0 -29
- package/dist/esm/types/hooks/use-authentication.d.ts +0 -27
- package/dist/esm/types/hooks/use-translations.d.ts +0 -33
- package/dist/esm/types/index.d.ts +0 -22
- package/dist/esm/types/models/auth-context.d.ts +0 -43
- package/dist/esm/types/models/basic-auth-props.d.ts +0 -29
- package/dist/esm/types/models/email-otp-props.d.ts +0 -26
- package/dist/esm/types/models/i18n.d.ts +0 -34
- package/dist/esm/types/models/jwt-verify-options.d.ts +0 -25
- package/dist/esm/types/models/login-options-box-props.d.ts +0 -24
- package/dist/esm/types/models/sign-in.d.ts +0 -49
- package/dist/esm/types/models/totp-props.d.ts +0 -26
- package/dist/esm/types/models/use-authentication.d.ts +0 -29
- package/dist/esm/types/models/use-translations.d.ts +0 -22
- package/dist/esm/types/oxygen-ui-react-auth-components/SignIn/SignIn.d.ts +0 -79
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInAlert/SignInAlert.d.ts +0 -37
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInButton/SignInButton.d.ts +0 -27
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInDivider/SignInDivider.d.ts +0 -26
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInFooter/SignInFooter.d.ts +0 -29
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInImage/SignInImage.d.ts +0 -23
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInLink/SignInLink.d.ts +0 -25
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInPaper/SignInPaper.d.ts +0 -26
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInPinInput/SignInPinInput.d.ts +0 -30
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInTextField/SignInTextField.d.ts +0 -26
- package/dist/esm/types/oxygen-ui-react-auth-components/SignInTypography/SignInTypography.d.ts +0 -32
- package/dist/esm/types/oxygen-ui-react-auth-components/index.d.ts +0 -19
- package/dist/esm/types/providers/AsgardeoProvider.d.ts +0 -34
- package/dist/esm/types/providers/BrandingPreferenceProvider.d.ts +0 -32
- package/dist/esm/types/providers/I18nProvider.d.ts +0 -33
- package/dist/esm/types/theme/generate-theme-sign-in.d.ts +0 -28
- package/dist/esm/types/theme/generate-theme.d.ts +0 -30
- package/dist/esm/types/utils/crypto-utils.d.ts +0 -52
- package/dist/esm/types/utils/session-store.d.ts +0 -25
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<p align="center" style="color: #343a40">
|
|
2
2
|
<h1 align="center">@asgardeo/react</h1>
|
|
3
3
|
</p>
|
|
4
|
-
<p align="center" style="font-size: 1.2rem;">React
|
|
4
|
+
<p align="center" style="font-size: 1.2rem;">React SDK for Asgardeo</p>
|
|
5
5
|
<div align="center">
|
|
6
6
|
<img alt="npm (scoped)" src="https://img.shields.io/npm/v/@asgardeo/react">
|
|
7
7
|
<img alt="npm" src="https://img.shields.io/npm/dw/@asgardeo/react">
|
|
@@ -11,17 +11,123 @@
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
#
|
|
14
|
+
# Using npm
|
|
15
15
|
npm install @asgardeo/react
|
|
16
16
|
|
|
17
|
-
#
|
|
17
|
+
# or using pnpm
|
|
18
18
|
pnpm add @asgardeo/react
|
|
19
19
|
|
|
20
|
-
#
|
|
20
|
+
# or using yarn
|
|
21
21
|
yarn add @asgardeo/react
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
1. Add `<AsgardeoProvider />` to your app
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { StrictMode } from 'react'
|
|
30
|
+
import { createRoot } from 'react-dom/client'
|
|
31
|
+
import './index.css'
|
|
32
|
+
import App from './App.tsx'
|
|
33
|
+
import { AsgardeoProvider } from '@asgardeo/react'
|
|
34
|
+
|
|
35
|
+
createRoot(document.getElementById('root')).render(
|
|
36
|
+
<StrictMode>
|
|
37
|
+
<AsgardeoProvider
|
|
38
|
+
baseUrl: '<your-organization-name>'
|
|
39
|
+
clientId: '<your-app-client-id>'
|
|
40
|
+
>
|
|
41
|
+
<App />
|
|
42
|
+
</AsgardeoProvider>
|
|
43
|
+
</StrictMode>
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
2. Add signed-in and signed-out to your app
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { SignedIn, SignedOut, SignInButton, SignOutButton } from '@asgardeo/react'
|
|
51
|
+
import './App.css'
|
|
52
|
+
|
|
53
|
+
function App() {
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<SignedIn>
|
|
57
|
+
<SignOutButton />
|
|
58
|
+
</SignedIn>
|
|
59
|
+
<SignedOut>
|
|
60
|
+
<SignInButton />
|
|
61
|
+
</SignedOut>
|
|
62
|
+
</>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default App
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
3. Start using other drop-in components like `User`, `UserProfile`, etc.
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import { User, UserProfile } from '@asgardeo/react'
|
|
73
|
+
import './App.css'
|
|
74
|
+
|
|
75
|
+
function App() {
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
<User>
|
|
79
|
+
{({ user }) => (
|
|
80
|
+
<div>
|
|
81
|
+
<h1>Welcome, {user.username}</h1>
|
|
82
|
+
<UserProfile />
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
</User>
|
|
86
|
+
|
|
87
|
+
<UserProfile />
|
|
88
|
+
</>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
export default App
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Using the `useAsgardeo` Hook (For Programmatic Control)
|
|
95
|
+
|
|
96
|
+
For more granular control, you can use the useAsgardeo hook. This hook provides direct access to SDK's functions and state:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import { useAsgardeo } from '@asgardeo/react'
|
|
100
|
+
import './App.css'
|
|
101
|
+
|
|
102
|
+
function App() {
|
|
103
|
+
const { user, signIn, signOut, isSignedIn, isLoading } = useAsgardeo()
|
|
104
|
+
|
|
105
|
+
if (isLoading) {
|
|
106
|
+
return <div>Loading...</div>
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
{isSignedIn ? (
|
|
112
|
+
<div>
|
|
113
|
+
<div>
|
|
114
|
+
<img src={user.photourl} alt={user.username} />
|
|
115
|
+
<p>Welcome back, {user.givenname}</p>
|
|
116
|
+
</div>
|
|
117
|
+
<button onClick={() => signOut()}>Sign Out</button>
|
|
118
|
+
</div>
|
|
119
|
+
) : (
|
|
120
|
+
<button onClick={() => signIn()}>Sign In</button>
|
|
121
|
+
)}
|
|
122
|
+
</div>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Documentation
|
|
128
|
+
|
|
129
|
+
For complete API documentation including all components, hooks, and customization options, see [API.md](./API.md).
|
|
130
|
+
|
|
24
131
|
## License
|
|
25
132
|
|
|
26
|
-
Licenses this source under the Apache License, Version 2.0 [LICENSE](
|
|
27
|
-
compliance with the License.
|
|
133
|
+
Licenses this source under the Apache License, Version 2.0 [LICENSE](../../LICENSE), You may not use this file except in compliance with the License.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
|
|
3
|
+
*
|
|
4
|
+
* WSO2 LLC. licenses this file to you under the Apache License,
|
|
5
|
+
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing,
|
|
12
|
+
* software distributed under the License is distributed on an
|
|
13
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
* KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations
|
|
16
|
+
* under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { AsgardeoBrowserClient, UserProfile, SignInOptions, SignOutOptions, User } from '@asgardeo/browser';
|
|
19
|
+
import { AsgardeoReactConfig } from './models/config';
|
|
20
|
+
/**
|
|
21
|
+
* Client for mplementing Asgardeo in React applications.
|
|
22
|
+
* This class provides the core functionality for managing user authentication and sessions.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam T - Configuration type that extends AsgardeoReactConfig.
|
|
25
|
+
*/
|
|
26
|
+
declare class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> extends AsgardeoBrowserClient<T> {
|
|
27
|
+
private asgardeo;
|
|
28
|
+
constructor();
|
|
29
|
+
initialize(config: T): Promise<boolean>;
|
|
30
|
+
getUser(): Promise<User>;
|
|
31
|
+
getUserProfile(): Promise<UserProfile>;
|
|
32
|
+
isLoading(): boolean;
|
|
33
|
+
isSignedIn(): Promise<boolean>;
|
|
34
|
+
signIn(options?: SignInOptions): Promise<User>;
|
|
35
|
+
signOut(options?: SignOutOptions, afterSignOut?: (redirectUrl: string) => void): Promise<string>;
|
|
36
|
+
signOut(options?: SignOutOptions, sessionId?: string, afterSignOut?: (redirectUrl: string) => void): Promise<string>;
|
|
37
|
+
}
|
|
38
|
+
export default AsgardeoReactClient;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
5
|
+
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing,
|
|
12
|
+
* software distributed under the License is distributed on an
|
|
13
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
* KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations
|
|
16
|
+
* under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { AsgardeoSPAClient, AuthClientConfig, User, LegacyConfig as Config, IdTokenPayload, Hooks, HttpClientInstance, HttpRequestConfig, HttpResponse, OIDCEndpoints, SignInConfig, SPACustomGrantConfig } from '@asgardeo/browser';
|
|
19
|
+
import { AuthStateInterface } from './models';
|
|
20
|
+
declare class AuthAPI {
|
|
21
|
+
static DEFAULT_STATE: AuthStateInterface;
|
|
22
|
+
private _authState;
|
|
23
|
+
private _client;
|
|
24
|
+
private _isLoading;
|
|
25
|
+
constructor(spaClient?: AsgardeoSPAClient);
|
|
26
|
+
_setIsLoading(isLoading: boolean): void;
|
|
27
|
+
_getIsLoading(): boolean;
|
|
28
|
+
isLoading(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Method to return Auth Client instance authentication state.
|
|
31
|
+
*
|
|
32
|
+
* @return {AuthStateInterface} Authentication State.
|
|
33
|
+
*/
|
|
34
|
+
getState(): AuthStateInterface;
|
|
35
|
+
/**
|
|
36
|
+
* Method to initialize the AuthClient instance.
|
|
37
|
+
*
|
|
38
|
+
* @param {Config} config - `dispatch` function from React Auth Context.
|
|
39
|
+
*/
|
|
40
|
+
init(config: AuthClientConfig<Config>): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Method to get the configuration data.
|
|
43
|
+
*
|
|
44
|
+
* @returns {Promise<AuthClientConfig<Config>>} - A promise that resolves with the configuration data.
|
|
45
|
+
*/
|
|
46
|
+
getConfigData(): Promise<AuthClientConfig<Config>>;
|
|
47
|
+
/**
|
|
48
|
+
* Method to handle user Sign In requests.
|
|
49
|
+
*
|
|
50
|
+
* @param {any} dispatch - `dispatch` function from React Auth Context.
|
|
51
|
+
* @param {AuthStateInterface} state - Current authentication state in React Auth Context.
|
|
52
|
+
* @param {any} callback - Action to trigger on successful sign in.
|
|
53
|
+
*/
|
|
54
|
+
signIn(config: SignInConfig, authorizationCode?: string, sessionState?: string, authState?: string, callback?: (response: User) => void, tokenRequestConfig?: {
|
|
55
|
+
params: Record<string, unknown>;
|
|
56
|
+
}): Promise<any>;
|
|
57
|
+
/**
|
|
58
|
+
* Method to handle user Sign Out requests.
|
|
59
|
+
*
|
|
60
|
+
* @param {any} dispatch - `dispatch` function from React Auth Context.
|
|
61
|
+
* @param {AuthStateInterface} state - Current authentication state in React Auth Context.
|
|
62
|
+
* @param {any} callback - Action to trigger on successful sign out.
|
|
63
|
+
*/
|
|
64
|
+
signOut(callback?: (response?: boolean) => void): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Method to update Auth Client instance authentication state.
|
|
67
|
+
*
|
|
68
|
+
* @param {AuthStateInterface} state - State values to update in authentication state.
|
|
69
|
+
*/
|
|
70
|
+
updateState(state: AuthStateInterface): void;
|
|
71
|
+
/**
|
|
72
|
+
* This method returns a Promise that resolves with the basic user information obtained from the ID token.
|
|
73
|
+
*
|
|
74
|
+
* @return {Promise<User>} - A promise that resolves with the user information.
|
|
75
|
+
*/
|
|
76
|
+
getUser(): Promise<User>;
|
|
77
|
+
/**
|
|
78
|
+
* This method sends an API request to a protected endpoint.
|
|
79
|
+
* The access token is automatically attached to the header of the request.
|
|
80
|
+
* This is the only way by which protected endpoints can be accessed
|
|
81
|
+
* when the web worker is used to store session information.
|
|
82
|
+
*
|
|
83
|
+
* @param {HttpRequestConfig} config - The config object containing attributes necessary to send a request.
|
|
84
|
+
*
|
|
85
|
+
* @return {Promise<Response>} - Returns a Promise that resolves with the response to the request.
|
|
86
|
+
*/
|
|
87
|
+
httpRequest(config: HttpRequestConfig): Promise<HttpResponse<any>>;
|
|
88
|
+
/**
|
|
89
|
+
* This method sends multiple API requests to a protected endpoint.
|
|
90
|
+
* The access token is automatically attached to the header of the request.
|
|
91
|
+
* This is the only way by which multiple requests can be sent to protected endpoints
|
|
92
|
+
* when the web worker is used to store session information.
|
|
93
|
+
*
|
|
94
|
+
* @param {HttpRequestConfig[]} config - The config object containing attributes necessary to send a request.
|
|
95
|
+
*
|
|
96
|
+
* @return {Promise<Response>} - Returns a Promise that resolves with the responses to the requests.
|
|
97
|
+
*/
|
|
98
|
+
httpRequestAll(configs: HttpRequestConfig[]): Promise<HttpResponse<any>[]>;
|
|
99
|
+
/**
|
|
100
|
+
* This method allows you to send a request with a custom grant.
|
|
101
|
+
*
|
|
102
|
+
* @param {CustomGrantRequestParams} config - The request parameters.
|
|
103
|
+
*
|
|
104
|
+
* @return {Promise<Response | SignInResponse>} - A Promise that resolves with
|
|
105
|
+
* the value returned by the custom grant request.
|
|
106
|
+
*/
|
|
107
|
+
exchangeToken(config: SPACustomGrantConfig, callback: (response: User | Response) => void, dispatch: (state: AuthStateInterface) => void): Promise<User | Response>;
|
|
108
|
+
/**
|
|
109
|
+
* This method ends a user session. The access token is revoked and the session information is destroyed.
|
|
110
|
+
*
|
|
111
|
+
* @return {Promise<boolean>} - A promise that resolves with `true` if the process is successful.
|
|
112
|
+
*/
|
|
113
|
+
revokeAccessToken(dispatch: (state: AuthStateInterface) => void): Promise<boolean>;
|
|
114
|
+
/**
|
|
115
|
+
* This method returns a Promise that resolves with an object containing the service endpoints.
|
|
116
|
+
*
|
|
117
|
+
* @return {Promise<ServiceResourcesType} - A Promise that resolves with an object containing the service endpoints.
|
|
118
|
+
*/
|
|
119
|
+
getOpenIDProviderEndpoints(): Promise<OIDCEndpoints>;
|
|
120
|
+
/**
|
|
121
|
+
* This methods returns the Axios http client.
|
|
122
|
+
*
|
|
123
|
+
* @return {HttpClientInstance} - The Axios HTTP client.
|
|
124
|
+
*/
|
|
125
|
+
getHttpClient(): Promise<HttpClientInstance>;
|
|
126
|
+
/**
|
|
127
|
+
* This method decodes the payload of the id token and returns it.
|
|
128
|
+
*
|
|
129
|
+
* @return {Promise<DecodedIDTokenPayloadInterface>} - A Promise that resolves with
|
|
130
|
+
* the decoded payload of the id token.
|
|
131
|
+
*/
|
|
132
|
+
getDecodedIdToken(): Promise<IdTokenPayload>;
|
|
133
|
+
/**
|
|
134
|
+
* This method decodes the payload of the idp id token and returns it.
|
|
135
|
+
*
|
|
136
|
+
* @return {Promise<DecodedIDTokenPayloadInterface>} - A Promise that resolves with
|
|
137
|
+
* the decoded payload of the idp id token.
|
|
138
|
+
*/
|
|
139
|
+
getDecodedIDPIDToken(): Promise<IdTokenPayload>;
|
|
140
|
+
/**
|
|
141
|
+
* This method returns the ID token.
|
|
142
|
+
*
|
|
143
|
+
* @return {Promise<string>} - A Promise that resolves with the id token.
|
|
144
|
+
*/
|
|
145
|
+
getIdToken(): Promise<string>;
|
|
146
|
+
/**
|
|
147
|
+
* This method return a Promise that resolves with the access token.
|
|
148
|
+
*
|
|
149
|
+
* **This method will not return the access token if the storage type is set to `webWorker`.**
|
|
150
|
+
*
|
|
151
|
+
* @return {Promise<string>} - A Promise that resolves with the access token.
|
|
152
|
+
*/
|
|
153
|
+
getAccessToken(): Promise<string>;
|
|
154
|
+
/**
|
|
155
|
+
* This method return a Promise that resolves with the idp access token.
|
|
156
|
+
*
|
|
157
|
+
* **This method will not return the idp access token if the storage type is set to `webWorker`.**
|
|
158
|
+
* **This can be used to access the IDP access token when custom auth grant functionalities are used**
|
|
159
|
+
*
|
|
160
|
+
* @return {Promise<string>} - A Promise that resolves with the idp access token.
|
|
161
|
+
*/
|
|
162
|
+
getIDPAccessToken(): Promise<string>;
|
|
163
|
+
/**
|
|
164
|
+
* This method refreshes the access token.
|
|
165
|
+
*
|
|
166
|
+
* @return {TokenResponseInterface} - A Promise that resolves with an object containing
|
|
167
|
+
* information about the refreshed access token.
|
|
168
|
+
*/
|
|
169
|
+
refreshAccessToken(): Promise<User>;
|
|
170
|
+
/**
|
|
171
|
+
* This method specifies if the user is authenticated or not.
|
|
172
|
+
*
|
|
173
|
+
* @return {Promise<boolean>} - A Promise that resolves with `true` if teh user is authenticated.
|
|
174
|
+
*/
|
|
175
|
+
isSignedIn(): Promise<boolean>;
|
|
176
|
+
/**
|
|
177
|
+
* This method specifies if the session is active or not.
|
|
178
|
+
*
|
|
179
|
+
* @return {Promise<boolean>} - A Promise that resolves with `true` if there is an active session.
|
|
180
|
+
*/
|
|
181
|
+
isSessionActive(): Promise<boolean>;
|
|
182
|
+
/**
|
|
183
|
+
* This method enables callback functions attached to the http client.
|
|
184
|
+
*
|
|
185
|
+
* @return {Promise<boolean>} - A promise that resolves with True.
|
|
186
|
+
*
|
|
187
|
+
*/
|
|
188
|
+
enableHttpHandler(): Promise<boolean>;
|
|
189
|
+
/**
|
|
190
|
+
* This method disables callback functions attached to the http client.
|
|
191
|
+
*
|
|
192
|
+
* @return {Promise<boolean>} - A promise that resolves with True.
|
|
193
|
+
*/
|
|
194
|
+
disableHttpHandler(): Promise<boolean>;
|
|
195
|
+
/**
|
|
196
|
+
* This method updates the configuration that was passed into the constructor when instantiating this class.
|
|
197
|
+
*
|
|
198
|
+
* @param {Partial<AuthClientConfig<T>>} config - A config object to update the SDK configurations with.
|
|
199
|
+
*/
|
|
200
|
+
reInitialize(config: Partial<AuthClientConfig<Config>>): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* This method attaches a callback function to an event hook that fires the callback when the event happens.
|
|
203
|
+
*
|
|
204
|
+
* @param {Hooks.CustomGrant} hook - The name of the hook.
|
|
205
|
+
* @param {(response?: any) => void} callback - The callback function.
|
|
206
|
+
* @param {string} id (optional) - The id of the hook. This is used when multiple custom grants are used.
|
|
207
|
+
*
|
|
208
|
+
*/
|
|
209
|
+
on(hook: Hooks.CustomGrant, callback: (response?: any) => void, id: string): Promise<void>;
|
|
210
|
+
on(hook: Exclude<Hooks, Hooks.CustomGrant>, callback: (response?: any) => void): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* This method allows you to sign in silently.
|
|
213
|
+
* First, this method sends a prompt none request to see if there is an active user session in the identity server.
|
|
214
|
+
* If there is one, then it requests the access token and stores it. Else, it returns false.
|
|
215
|
+
*
|
|
216
|
+
* @return {Promise<User | boolean>} - A Promise that resolves with the user information after signing in
|
|
217
|
+
* or with `false` if the user is not signed in.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
*```
|
|
221
|
+
* client.trySignInSilently()
|
|
222
|
+
*```
|
|
223
|
+
*/
|
|
224
|
+
trySignInSilently(state: AuthStateInterface, dispatch: (state: AuthStateInterface) => void, additionalParams?: Record<string, string | boolean>, tokenRequestConfig?: {
|
|
225
|
+
params: Record<string, unknown>;
|
|
226
|
+
}): Promise<User | boolean | undefined>;
|
|
227
|
+
}
|
|
228
|
+
export default AuthAPI;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
5
|
+
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing,
|
|
12
|
+
* software distributed under the License is distributed on an
|
|
13
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
* KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations
|
|
16
|
+
* under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { AsgardeoAuthException, AuthClientConfig, AuthSPAClientConfig, Config, TokenExchangeRequestConfig, IdTokenPayload, Hooks, HttpClientInstance, HttpRequestConfig, HttpResponse, OIDCEndpoints, SignInConfig, User } from '@asgardeo/browser';
|
|
19
|
+
export interface ReactConfig {
|
|
20
|
+
/**
|
|
21
|
+
* The SDK's `AuthProvider` by default is listening to the URL changes to see
|
|
22
|
+
* if `code` & `session_state` search params are available so that it could perform
|
|
23
|
+
* token exchange. This option could be used to override that behaviour.
|
|
24
|
+
*/
|
|
25
|
+
skipRedirectCallback?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The `AuthProvider`, by default, looks for an active session in the server and updates the session information
|
|
28
|
+
* with the latest session information from the server. This option could be used to disable that behaviour.
|
|
29
|
+
*/
|
|
30
|
+
disableTrySignInSilently?: boolean;
|
|
31
|
+
disableAutoSignIn?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export type AuthReactConfig = AuthSPAClientConfig & ReactConfig;
|
|
34
|
+
/**
|
|
35
|
+
* Interface for the Authenticated state of the user which is exposed
|
|
36
|
+
* via `state` object from `useAuthContext` hook.
|
|
37
|
+
*/
|
|
38
|
+
export interface AuthStateInterface {
|
|
39
|
+
/**
|
|
40
|
+
* The display name of the user.
|
|
41
|
+
*/
|
|
42
|
+
displayName?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The email address of the user.
|
|
45
|
+
*/
|
|
46
|
+
email?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Specifies if the user is authenticated or not.
|
|
49
|
+
*/
|
|
50
|
+
isSignedIn: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Are the Auth requests loading.
|
|
53
|
+
*/
|
|
54
|
+
isLoading: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The username of the user.
|
|
57
|
+
*/
|
|
58
|
+
username?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface AuthContextInterface {
|
|
61
|
+
signIn: (config?: SignInConfig, authorizationCode?: string, sessionState?: string, state?: string, callback?: (response: User) => void, tokenRequestConfig?: {
|
|
62
|
+
params: Record<string, unknown>;
|
|
63
|
+
}) => Promise<User>;
|
|
64
|
+
signOut: (callback?: (response: boolean) => void) => Promise<boolean>;
|
|
65
|
+
getUser(): Promise<User>;
|
|
66
|
+
httpRequest(config: HttpRequestConfig): Promise<HttpResponse<any>>;
|
|
67
|
+
httpRequestAll(configs: HttpRequestConfig[]): Promise<HttpResponse<any>[]>;
|
|
68
|
+
exchangeToken(config: TokenExchangeRequestConfig, callback?: (response: User | Response) => void): void;
|
|
69
|
+
revokeAccessToken(): Promise<boolean>;
|
|
70
|
+
getOpenIDProviderEndpoints(): Promise<OIDCEndpoints>;
|
|
71
|
+
getHttpClient(): Promise<HttpClientInstance>;
|
|
72
|
+
getDecodedIDPIDToken(): Promise<IdTokenPayload>;
|
|
73
|
+
getDecodedIdToken(): Promise<IdTokenPayload>;
|
|
74
|
+
getIdToken(): Promise<string>;
|
|
75
|
+
getAccessToken(): Promise<string>;
|
|
76
|
+
refreshAccessToken(): Promise<User>;
|
|
77
|
+
isSignedIn(): Promise<boolean>;
|
|
78
|
+
enableHttpHandler(): Promise<boolean>;
|
|
79
|
+
disableHttpHandler(): Promise<boolean>;
|
|
80
|
+
reInitialize(config: Partial<AuthClientConfig<Config>>): Promise<void>;
|
|
81
|
+
trySignInSilently: (additionalParams?: Record<string, string | boolean>, tokenRequestConfig?: {
|
|
82
|
+
params: Record<string, unknown>;
|
|
83
|
+
}) => Promise<boolean | User>;
|
|
84
|
+
on(hook: Hooks.CustomGrant, callback: (response?: any) => void, id: string): void;
|
|
85
|
+
on(hook: Exclude<Hooks, Hooks.CustomGrant>, callback: (response?: any) => void): void;
|
|
86
|
+
on(hook: Hooks, callback: (response?: any) => void, id?: string): void;
|
|
87
|
+
state: AuthStateInterface;
|
|
88
|
+
error: AsgardeoAuthException;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The model of the object returned by the `getAuthParams` prop method of the `AuthProvider`.
|
|
92
|
+
*/
|
|
93
|
+
export interface AuthParams {
|
|
94
|
+
authorizationCode?: string;
|
|
95
|
+
sessionState?: string;
|
|
96
|
+
state?: string;
|
|
97
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
|
|
3
|
+
*
|
|
4
|
+
* WSO2 LLC. licenses this file to you under the Apache License,
|
|
5
|
+
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing,
|
|
12
|
+
* software distributed under the License is distributed on an
|
|
13
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
* KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations
|
|
16
|
+
* under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { User } from '@asgardeo/browser';
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the user profile information from the specified selfcare profile endpoint.
|
|
21
|
+
*
|
|
22
|
+
* @param requestConfig - Request configuration object.
|
|
23
|
+
* @returns A promise that resolves with the user profile information.
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* try {
|
|
27
|
+
* const userProfile = await getUserProfile({
|
|
28
|
+
* url: "https://api.asgardeo.io/t/<ORGANIZATION>/scim2/Me",
|
|
29
|
+
* });
|
|
30
|
+
* console.log(userProfile);
|
|
31
|
+
* } catch (error) {
|
|
32
|
+
* if (error instanceof AsgardeoAPIError) {
|
|
33
|
+
* console.error('Failed to get user profile:', error.message);
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare const getMeProfile: ({ url, ...requestConfig }: Partial<Request>) => Promise<User>;
|
|
39
|
+
export default getMeProfile;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
|
|
3
|
+
*
|
|
4
|
+
* WSO2 LLC. licenses this file to you under the Apache License,
|
|
5
|
+
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing,
|
|
12
|
+
* software distributed under the License is distributed on an
|
|
13
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
* KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations
|
|
16
|
+
* under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { Schema } from '@asgardeo/browser';
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the SCIM2 schemas from the specified endpoint.
|
|
21
|
+
*
|
|
22
|
+
* @param requestConfig - Request configuration object.
|
|
23
|
+
* @returns A promise that resolves with the SCIM2 schemas information.
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* try {
|
|
27
|
+
* const schemas = await getSchemas({
|
|
28
|
+
* url: "https://api.asgardeo.io/t/<ORGANIZATION>/scim2/Schemas",
|
|
29
|
+
* });
|
|
30
|
+
* console.log(schemas);
|
|
31
|
+
* } catch (error) {
|
|
32
|
+
* if (error instanceof AsgardeoAPIError) {
|
|
33
|
+
* console.error('Failed to get schemas:', error.message);
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare const getSchemas: ({ url }: Partial<Request>) => Promise<Schema[]>;
|
|
39
|
+
export default getSchemas;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
|
|
3
|
+
*
|
|
4
|
+
* WSO2 LLC. licenses this file to you under the Apache License,
|
|
5
|
+
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing,
|
|
12
|
+
* software distributed under the License is distributed on an
|
|
13
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
* KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations
|
|
16
|
+
* under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { User } from '@asgardeo/browser';
|
|
19
|
+
/**
|
|
20
|
+
* Updates the user profile information at the specified SCIM2 Me endpoint.
|
|
21
|
+
*
|
|
22
|
+
* @param url - The SCIM2 Me endpoint URL.
|
|
23
|
+
* @param value - The value object to patch (SCIM2 PATCH value).
|
|
24
|
+
* @param requestConfig - Additional request config if needed.
|
|
25
|
+
* @returns A promise that resolves with the updated user profile information.
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* await updateMeProfile({
|
|
29
|
+
* url: "https://api.asgardeo.io/t/<ORG>/scim2/Me",
|
|
30
|
+
* value: { "urn:scim:wso2:schema": { mobileNumbers: ["0777933830"] } }
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare const updateMeProfile: ({ url, payload, ...requestConfig }: {
|
|
35
|
+
url: string;
|
|
36
|
+
payload: any;
|
|
37
|
+
} & Partial<Request>) => Promise<User>;
|
|
38
|
+
export default updateMeProfile;
|