@asgardeo/auth-react 0.2.15 → 1.1.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 +34 -33
- package/dist/main.js +105 -45
- package/dist/src/api.d.ts +7 -7
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/authenticate.d.ts.map +1 -1
- package/dist/src/models.d.ts +5 -4
- package/dist/src/models.d.ts.map +1 -1
- package/dist/src/secure-app.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +162 -74
- package/package.json +2 -2
- package/src/api.ts +10 -16
- package/src/authenticate.tsx +16 -7
- package/src/models.ts +5 -10
- package/src/secure-app.tsx +1 -1
package/README.md
CHANGED
|
@@ -73,18 +73,18 @@ Create an organization in Asgardeo if you don't already have one. The organizati
|
|
|
73
73
|
Before trying out the sample apps, you need to create an application in **Asgardeo**.
|
|
74
74
|
|
|
75
75
|
1. Navigate to [**Asgardeo Console**](https://console.asgardeo.io/login) and click on **Applications** under **Develop** tab
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
2. Click on **New Application** and then **Single Page Application**.
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
3. Enter **Sample** as the name of the app and add the redirect URL(s). You can find the relevant redirect URL(s) of each sample app in the [Running the sample apps](#2-running-the-sample-apps) section.
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
4. Click on Register. You will be navigated to management page of the **sample** application.
|
|
82
82
|
|
|
83
|
-
5. Add `https://localhost:
|
|
83
|
+
5. Add `https://localhost:3000` (or whichever the URL your app is hosted on) to **Allowed Origins** under **Access** tab and check **Public client** option.
|
|
84
84
|
|
|
85
85
|
6. Click on **Update** at the bottom.
|
|
86
|
-
|
|
87
|
-
7. Copy the configuration from the Asgardeo React Quickstart guide to your React application as shown in the above code snippet.
|
|
86
|
+
|
|
87
|
+
7. Copy the configuration from the Asgardeo React Quickstart guide to your React application as shown in the above code snippet.
|
|
88
88
|
|
|
89
89
|
### 2. Running the sample apps
|
|
90
90
|
|
|
@@ -99,9 +99,9 @@ Read more about the SDK configurations [here](#configuration) .
|
|
|
99
99
|
```json
|
|
100
100
|
{
|
|
101
101
|
"clientID": "",
|
|
102
|
-
"
|
|
103
|
-
"signInRedirectURL": "https://localhost:
|
|
104
|
-
"signOutRedirectURL": "https://localhost:
|
|
102
|
+
"baseUrl": "https://api.asgardeo.io/t/<org_name>",
|
|
103
|
+
"signInRedirectURL": "https://localhost:3000",
|
|
104
|
+
"signOutRedirectURL": "https://localhost:3000"
|
|
105
105
|
}
|
|
106
106
|
```
|
|
107
107
|
|
|
@@ -111,7 +111,7 @@ Read more about the SDK configurations [here](#configuration) .
|
|
|
111
111
|
npm install && npm start
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
4. Navigate to [`https://localhost:
|
|
114
|
+
4. Navigate to [`https://localhost:3000`](https://localhost:3000) (or whichever the URL you have hosted the sample app).
|
|
115
115
|
|
|
116
116
|
#### Basic React Sample
|
|
117
117
|
|
|
@@ -120,7 +120,7 @@ npm install && npm start
|
|
|
120
120
|
- Find More Info: [README](/samples/asgardeo-react-app/README.md)
|
|
121
121
|
|
|
122
122
|
- **Redirect URL(s):**
|
|
123
|
-
- `https://localhost:
|
|
123
|
+
- `https://localhost:3000`
|
|
124
124
|
|
|
125
125
|
## Getting Started
|
|
126
126
|
|
|
@@ -142,10 +142,10 @@ import { AuthProvider, useAuthContext } from "@asgardeo/auth-react";
|
|
|
142
142
|
|
|
143
143
|
// The config data.
|
|
144
144
|
const config = {
|
|
145
|
-
signInRedirectURL: "https://localhost:
|
|
146
|
-
signOutRedirectURL: "https://localhost:
|
|
145
|
+
signInRedirectURL: "https://localhost:3000/sign-in",
|
|
146
|
+
signOutRedirectURL: "https://localhost:3000/dashboard",
|
|
147
147
|
clientID: "client ID",
|
|
148
|
-
|
|
148
|
+
baseUrl: "https://api.asgardeo.io/t/<org_name>"
|
|
149
149
|
};
|
|
150
150
|
|
|
151
151
|
// Encapsulate your components with the `AuthProvider`.
|
|
@@ -314,21 +314,22 @@ getBasicUserInfo().then((response) => {
|
|
|
314
314
|
### signIn
|
|
315
315
|
|
|
316
316
|
```typescript
|
|
317
|
-
signIn(
|
|
317
|
+
signIn(config?: SignInConfig, authorizationCode?: string, sessionState?: string, authState?: string, callback?: (response: BasicUserInfo) => void);
|
|
318
318
|
```
|
|
319
319
|
|
|
320
320
|
#### Arguments
|
|
321
321
|
|
|
322
|
-
1.
|
|
323
|
-
A callback function that fires when sign-in is successful. The callback function takes an object of type [`BasicUserInfo`](#BasicUserInfo) as an argument.
|
|
324
|
-
2. config?: [`SignInConfig`](#SignInConfig) (optional)
|
|
322
|
+
1. config?: [`SignInConfig`](#SignInConfig) (optional)
|
|
325
323
|
An object that contains attributes that allows you to configure sign in. The `forceInit` attribute of this object, allows you to force a request to the `.well-known` endpoint even if a request has previously been sent. You can also pass key-value pairs that you want to be appended as path parameters to the authorization URL to this object. To learn more, refer to [`SignInConfig`](#SignInConfig). This object is needed only during the authorization-url-generation phase.
|
|
326
324
|
|
|
327
|
-
|
|
325
|
+
2. authorizationCode?: `string` (optional)
|
|
328
326
|
The `signIn` method can be passed the authorization code as an argument, which will be used to obtain the token during the token-request phase of the method. This allows developers to use different response modes such as `form_post`. To learn more about the `form_post` method refer to the [Using the `form_post` response mode](#Using-the-form_post-response-mode) section. If you're using the `query` method, then the `signIn` method automatically obtains the authorization code from the URL.
|
|
329
|
-
|
|
327
|
+
3. sessionState?: `string` (optional)
|
|
330
328
|
The `signIn` method can be passed the session state as an argument, which will be used to obtain the token during the token-request phase of the method. This allows developers to use different response modes such as `form_post`. To learn more about the `form_post` method refer to the [Using the `form_post` response mode](#Using-the-form_post-response-mode) section. If you're using the `query` method, then the `signIn` method automatically obtains the session state from the URL.
|
|
331
|
-
|
|
329
|
+
4. authState?: `string` (optional)
|
|
330
|
+
The `signIn` method can be passed the state parameter as an argument, which will be used to obtain the token during the token-request phase of the method.
|
|
331
|
+
5. callback?: (response: [`BasicUserInfo`](#BasicUserInfo)) => `void`
|
|
332
|
+
A callback function that fires when sign-in is successful. The callback function takes an object of type [`BasicUserInfo`](#BasicUserInfo) as an argument.
|
|
332
333
|
#### Description
|
|
333
334
|
|
|
334
335
|
As the name implies, this method is used to sign-in users. This method will have to be called twice to implement the two phases of the authentication process. The first phase generates generates the authorization URl and takes the user to the single-sign-on page of the identity server, while second phase triggers the token request to complete the authentication process. So, this method should be called when initiating authentication and when the user is redirected back to the app after authentication themselves with the server.
|
|
@@ -821,7 +822,7 @@ This method can be used to update the configurations passed into the constructor
|
|
|
821
822
|
|
|
822
823
|
```TypeScript
|
|
823
824
|
updateConfig({
|
|
824
|
-
signOutRedirectURL: "https://localhost:
|
|
825
|
+
signOutRedirectURL: "https://localhost:3000/sign-out"
|
|
825
826
|
});
|
|
826
827
|
```
|
|
827
828
|
|
|
@@ -892,26 +893,26 @@ initialize(config);
|
|
|
892
893
|
|
|
893
894
|
| Attribute | Required/Optional | Type | Default Value | Description |
|
|
894
895
|
| --------- | ----------------- | ---- | ------------- | ----------- |
|
|
895
|
-
| `signInRedirectURL` | Required | `string` | "" | The URL to redirect to after the user authorizes the client app. eg: `https//localhost:
|
|
896
|
-
| `signOutRedirectURL` | Optional | `string` | The `signInRedirectURL` URL will be used if this value is not provided. | The URL to redirect to after the user | signs out. eg: `https://localhost:
|
|
897
|
-
| `clientHost` | Optional | `string` | The origin of the client app obtained using `window.origin` | The hostname of the client app. eg: `https://localhost:
|
|
896
|
+
| `signInRedirectURL` | Required | `string` | "" | The URL to redirect to after the user authorizes the client app. eg: `https//localhost:3000/sign-in` |
|
|
897
|
+
| `signOutRedirectURL` | Optional | `string` | The `signInRedirectURL` URL will be used if this value is not provided. | The URL to redirect to after the user | signs out. eg: `https://localhost:3000/dashboard` |
|
|
898
|
+
| `clientHost` | Optional | `string` | The origin of the client app obtained using `window.origin` | The hostname of the client app. eg: `https://localhost:3000` |
|
|
898
899
|
| `clientID` | Required | `string` | "" | The client ID of the OIDC application hosted in the Asgardeo. |
|
|
899
900
|
| `clientSecret` | Optional | `string` | "" | The client secret of the OIDC application |
|
|
900
901
|
| `enablePKCE` | Optional | `boolean` | `true` | Specifies if a PKCE should be sent with the request for the authorization code. |
|
|
901
902
|
| `prompt` | Optional | `string` | "" | Specifies the prompt type of an OIDC request |
|
|
902
903
|
| `responseMode` | Optional | `ResponseMode` | `"query"` | Specifies the response mode. The value can either be `query` or `form_post` |
|
|
903
904
|
| `scope` | Optional | `string[]` | `["openid"]` | Specifies the requested scopes. |
|
|
904
|
-
| `
|
|
905
|
-
| `endpoints` | Optional | `OIDCEndpoints` | [OIDC Endpoints Default Values](#oidc-endpoints) | The OIDC endpoint URLs. The SDK will try to obtain the endpoint URLS | using the `.well-known` endpoint. If this fails, the SDK will use these endpoint URLs. If this attribute is not set, then the default endpoint URLs will be | used. However, if the `overrideWellEndpointConfig` is set to `true`, then this will override the endpoints obtained from the `.well-known` endpoint. |
|
|
905
|
+
| `baseUrl` | Required (If `wellKnownEndpoint` or `endpoints` is not provided) | `string` | "" | The origin of the Identity Provider. eg: `https://www.asgardeo.io/t/<org_name>` |
|
|
906
|
+
| `endpoints` | Optional (Required to provide all endpoints, if `wellKnownEndpoint` or `baseUrl` is not provided) | `OIDCEndpoints` | [OIDC Endpoints Default Values](#oidc-endpoints) | The OIDC endpoint URLs. The SDK will try to obtain the endpoint URLS | using the `.well-known` endpoint. If this fails, the SDK will use these endpoint URLs. If this attribute is not set, then the default endpoint URLs will be | used. However, if the `overrideWellEndpointConfig` is set to `true`, then this will override the endpoints obtained from the `.well-known` endpoint. |
|
|
907
|
+
`wellKnownEndpoint` | Optional | `string` | `"/oauth2/token/.well-known/openid-configuration"` | The URL of the `.well-known` endpoint. |
|
|
906
908
|
| `overrideWellEndpointConfig` | Optional | `boolean` | `false` | If this option is set to `true`, then the `endpoints` object will override endpoints obtained | from the `.well-known` endpoint. If this is set to `false`, then this will be used as a fallback if the request to the `.well-known` endpoint fails. |
|
|
907
|
-
| `wellKnownEndpoint` | Optional | `string` | `"/oauth2/token/.well-known/openid-configuration"` | The URL of the `.well-known` endpoint. |
|
|
908
909
|
| `validateIDToken` | Optional | `boolean` | `true` | Allows you to enable/disable JWT ID token validation after obtaining the ID token. |
|
|
909
910
|
| `clockTolerance` | Optional | `number` | `60` | Allows you to configure the leeway when validating the id_token. |
|
|
910
911
|
| `skipRedirectCallback` | Optional | `boolean` | `false` | Stop listening to Auth param changes i.e `code` & `session_state` to trigger auto login. |
|
|
911
912
|
| [`storage`](#storage) | Optional | `"sessionStorage"`, `"webWorker"`, `"localStorage"` | `"sessionStorage"` | The storage medium where the session information such as the access token should be stored.| |
|
|
912
913
|
| `resourceServerURLs` |Required if the `storage` is set to `webWorker` | `string[]` | `[]` | The URLs of the API endpoints. This is needed only if the storage method is set to `webWorker`. When API calls are made through the [`httpRequest`](#httprequest) or the [`httpRequestAll`](#httprequestall) method, only the calls to the endpoints specified in the `baseURL` attribute will be allowed. Everything else will be denied. | |
|
|
913
914
|
|`requestTimeout` | Optional | `number`| 60000 (seconds) | Specifies in seconds how long a request to the web worker should wait before being timed out. |
|
|
914
|
-
| `disableTrySignInSilently` | Optional | `boolean` | `
|
|
915
|
+
| `disableTrySignInSilently` | Optional | `boolean` | `true` | Specifies if the SDK should try to sign in silently on mount.|
|
|
915
916
|
|`enableOIDCSessionManagement` |Optional|`boolean`| false | Flag to enable OIDC Session Management |
|
|
916
917
|
|
|
917
918
|
### BasicUserInfo
|
|
@@ -948,7 +949,7 @@ initialize(config);
|
|
|
948
949
|
| `checkSessionIframe` | `string` | `"/oidc/checksession"` | The check-session endpoint. |
|
|
949
950
|
| `endSessionEndpoint` | `string` | `"/oidc/logout"` | The end-session endpoint. |
|
|
950
951
|
| `issuer` | `string` | "" | The issuer of the token. |
|
|
951
|
-
| `wellKnownEndpoint`
|
|
952
|
+
| `wellKnownEndpoint` | `string` | `"/oauth2/token/.well-known/openid-configuration"` | The well-known endpoint. This is the default endpoint defined in the SDK. |
|
|
952
953
|
|
|
953
954
|
### CustomGrantConfig
|
|
954
955
|
|
|
@@ -995,14 +996,14 @@ This extends the `AxiosRequestConfig` by providing an additional attribute that
|
|
|
995
996
|
### Prerequisites
|
|
996
997
|
|
|
997
998
|
- `Node.js` (version 10 or above).
|
|
998
|
-
- `
|
|
999
|
+
- `yarn` package manager.
|
|
999
1000
|
|
|
1000
1001
|
### Installing Dependencies
|
|
1001
1002
|
|
|
1002
|
-
The repository is a mono repository. The SDK repository is found in the [
|
|
1003
|
+
The repository is a mono repository. The SDK repository is found in the [lib]() directory. You can install the dependencies by running the following command at the root.
|
|
1003
1004
|
|
|
1004
1005
|
```
|
|
1005
|
-
|
|
1006
|
+
yarn build
|
|
1006
1007
|
```
|
|
1007
1008
|
|
|
1008
1009
|
## Contribute
|