@asgardeo/auth-spa 0.2.19 → 0.2.22
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/.eslintrc.js +1 -2
- package/README.md +53 -24
- package/babel.config.js +1 -2
- package/dist/asgardeo-spa.production.esm.js +105 -44
- package/dist/asgardeo-spa.production.esm.js.map +1 -1
- package/dist/asgardeo-spa.production.js +106 -45
- package/dist/asgardeo-spa.production.js.map +1 -1
- package/dist/asgardeo-spa.production.min.js +1 -1
- package/dist/asgardeo-spa.production.min.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.esm.js +103 -42
- package/dist/polyfilled/asgardeo-spa.production.esm.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.js +103 -42
- package/dist/polyfilled/asgardeo-spa.production.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.min.js +1 -1
- package/dist/polyfilled/asgardeo-spa.production.min.js.map +1 -1
- package/dist/src/client.d.ts +10 -6
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +26 -14
- package/dist/src/client.js.map +1 -1
- package/dist/src/clients/main-thread-client.d.ts.map +1 -1
- package/dist/src/clients/main-thread-client.js +61 -48
- package/dist/src/clients/main-thread-client.js.map +1 -1
- package/dist/src/clients/web-worker-client.d.ts +1 -1
- package/dist/src/clients/web-worker-client.d.ts.map +1 -1
- package/dist/src/clients/web-worker-client.js +51 -32
- package/dist/src/clients/web-worker-client.js.map +1 -1
- package/dist/src/{exception/exception.d.ts → constants/errors.d.ts} +3 -11
- package/dist/src/constants/errors.d.ts.map +1 -0
- package/dist/src/{exception/exception.js → constants/errors.js} +3 -14
- package/dist/src/constants/errors.js.map +1 -0
- package/dist/src/constants/hooks.d.ts +2 -1
- package/dist/src/constants/hooks.d.ts.map +1 -1
- package/dist/src/constants/hooks.js +1 -0
- package/dist/src/constants/hooks.js.map +1 -1
- package/dist/src/constants/index.d.ts +1 -0
- package/dist/src/constants/index.d.ts.map +1 -1
- package/dist/src/constants/index.js +1 -0
- package/dist/src/constants/index.js.map +1 -1
- package/dist/src/constants/parameters.d.ts +1 -0
- package/dist/src/constants/parameters.d.ts.map +1 -1
- package/dist/src/constants/parameters.js +1 -0
- package/dist/src/constants/parameters.js.map +1 -1
- package/dist/src/helpers/session-management-helper.d.ts +1 -1
- package/dist/src/helpers/session-management-helper.d.ts.map +1 -1
- package/dist/src/helpers/session-management-helper.js +33 -43
- package/dist/src/helpers/session-management-helper.js.map +1 -1
- package/dist/src/index-polyfill.d.ts +0 -1
- package/dist/src/index-polyfill.d.ts.map +1 -1
- package/dist/src/index-polyfill.js +0 -1
- package/dist/src/index-polyfill.js.map +1 -1
- package/dist/src/models/client.d.ts +4 -4
- package/dist/src/models/client.d.ts.map +1 -1
- package/dist/src/models/http-client.d.ts +1 -1
- package/dist/src/models/http-client.d.ts.map +1 -1
- package/dist/src/models/index.d.ts +1 -0
- package/dist/src/models/index.d.ts.map +1 -1
- package/dist/src/models/index.js +1 -0
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/models/message.d.ts +1 -0
- package/dist/src/models/message.d.ts.map +1 -1
- package/dist/src/models/session-management-helper.d.ts +2 -1
- package/dist/src/models/session-management-helper.d.ts.map +1 -1
- package/dist/src/{exception/index.js → models/sign-out-error.d.ts} +6 -3
- package/dist/src/models/sign-out-error.d.ts.map +1 -0
- package/{src/exception/index.ts → dist/src/models/sign-out-error.js} +3 -3
- package/dist/src/models/sign-out-error.js.map +1 -0
- package/dist/src/models/web-worker.d.ts +3 -3
- package/dist/src/models/web-worker.d.ts.map +1 -1
- package/dist/src/models/web-worker.js.map +1 -1
- package/dist/src/public-api.d.ts +1 -1
- package/dist/src/public-api.d.ts.map +1 -1
- package/dist/src/public-api.js +1 -1
- package/dist/src/public-api.js.map +1 -1
- package/dist/src/utils/crypto-utils.d.ts +33 -0
- package/dist/src/utils/crypto-utils.d.ts.map +1 -0
- package/dist/src/utils/crypto-utils.js +55 -0
- package/dist/src/utils/crypto-utils.js.map +1 -0
- package/dist/src/utils/spa-utils.d.ts +5 -3
- package/dist/src/utils/spa-utils.d.ts.map +1 -1
- package/dist/src/utils/spa-utils.js +26 -10
- package/dist/src/utils/spa-utils.js.map +1 -1
- package/dist/src/worker/client.worker.d.ts.map +1 -1
- package/dist/src/worker/client.worker.js +5 -5
- package/dist/src/worker/client.worker.js.map +1 -1
- package/dist/src/worker/worker-core.d.ts.map +1 -1
- package/dist/src/worker/worker-core.js +57 -49
- package/dist/src/worker/worker-core.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -30
- package/rollup.config.js +3 -5
- package/src/client.ts +45 -50
- package/src/clients/main-thread-client.ts +96 -89
- package/src/clients/web-worker-client.ts +73 -48
- package/src/constants/errors.ts +19 -0
- package/src/constants/hooks.ts +2 -1
- package/src/constants/index.ts +1 -0
- package/src/constants/parameters.ts +1 -0
- package/src/helpers/session-management-helper.ts +31 -40
- package/src/index-polyfill.ts +0 -1
- package/src/models/client.ts +5 -5
- package/src/models/http-client.ts +3 -2
- package/src/models/index.ts +1 -0
- package/src/models/message.ts +1 -0
- package/src/models/session-management-helper.ts +3 -2
- package/{dist/src/exception/index.d.ts → src/models/sign-out-error.ts} +6 -3
- package/src/models/web-worker.ts +8 -2
- package/src/public-api.ts +2 -1
- package/src/utils/crypto-utils.ts +74 -0
- package/src/utils/spa-utils.ts +33 -10
- package/src/worker/client.worker.ts +6 -11
- package/src/worker/worker-core.ts +98 -101
- package/dist/src/exception/exception.d.ts.map +0 -1
- package/dist/src/exception/exception.js.map +0 -1
- package/dist/src/exception/index.d.ts.map +0 -1
- package/dist/src/exception/index.js.map +0 -1
- package/src/exception/exception.ts +0 -44
package/.eslintrc.js
CHANGED
|
@@ -27,8 +27,7 @@ module.exports = {
|
|
|
27
27
|
"@typescript-eslint/explicit-function-return-type": 0,
|
|
28
28
|
"@typescript-eslint/no-explicit-any": 0,
|
|
29
29
|
"@typescript-eslint/no-inferrable-types": "off",
|
|
30
|
-
"@typescript-eslint/no-unused-vars": "
|
|
31
|
-
"@typescript-eslint/no-unused-vars-experimental": "warn",
|
|
30
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
|
32
31
|
"@typescript-eslint/no-use-before-define": ["warn", {
|
|
33
32
|
classes: false,
|
|
34
33
|
functions: false,
|
package/README.md
CHANGED
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
- [Develop](#develop)
|
|
55
55
|
- [Prerequisites](#prerequisites)
|
|
56
56
|
- [Installing Dependencies](#installing-dependencies)
|
|
57
|
+
- [Error Codes](#error-codes)
|
|
57
58
|
- [Contribute](#contribute)
|
|
58
59
|
- [License](#license)
|
|
59
60
|
|
|
@@ -91,12 +92,12 @@ Or simply load the SDK by importing the script into the header of your HTML file
|
|
|
91
92
|
// This client is a class and can be instantiated as follows.
|
|
92
93
|
var auth = AsgardeoAuth.AsgardeoSPAClient.getInstance();
|
|
93
94
|
|
|
94
|
-
// Once instantiated, the client can be initialized by passing the relevant parameters such as the
|
|
95
|
+
// Once instantiated, the client can be initialized by passing the relevant parameters such as the baseUrl, redirect URL, client ID, etc.
|
|
95
96
|
auth.initialize({
|
|
96
97
|
signInRedirectURL: "http://localhost:3000/sign-in",
|
|
97
98
|
signOutRedirectURL: "http://localhost:3000/dashboard",
|
|
98
99
|
clientID: "client ID",
|
|
99
|
-
|
|
100
|
+
baseUrl: "https://api.asgardeo.io/t/<org_name>"
|
|
100
101
|
});
|
|
101
102
|
|
|
102
103
|
// To sign in, simply call the `signIn()` method.
|
|
@@ -123,7 +124,7 @@ auth.initialize({
|
|
|
123
124
|
signInRedirectURL: "http://localhost:3000/sign-in",
|
|
124
125
|
signOutRedirectURL: "http://localhost:3000/dashboard",
|
|
125
126
|
clientID: "client ID",
|
|
126
|
-
|
|
127
|
+
baseUrl: "https://api.asgardeo.io/t/<org_name>"
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
// To sign in, simply call the `signIn()` method.
|
|
@@ -145,15 +146,15 @@ auth.on("sign-in", (response) => {
|
|
|
145
146
|
Before trying out the sample apps, you need to create an application in **Asgardeo**.
|
|
146
147
|
|
|
147
148
|
1. Navigate to [**Asgardeo Console**](https://console.asgardeo.io/login) and click on **Applications** under **Develop** tab
|
|
148
|
-
|
|
149
|
+
|
|
149
150
|
2. Click on **New Application** and then **Single Page Application**.
|
|
150
|
-
|
|
151
|
+
|
|
151
152
|
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.
|
|
152
|
-
|
|
153
|
+
|
|
153
154
|
4. Click on Register. You will be navigated to management page of the **sample** application.
|
|
154
|
-
|
|
155
|
+
|
|
155
156
|
5. Add `https://localhost:5000` to **Allowed Origins** under **Access** tab and check **Public client** option.
|
|
156
|
-
|
|
157
|
+
|
|
157
158
|
6. Click on **Update** at the bottom.
|
|
158
159
|
|
|
159
160
|
### 2. Running the sample apps
|
|
@@ -280,7 +281,7 @@ const config = {
|
|
|
280
281
|
signInRedirectURL: "http://localhost:3000/sign-in",
|
|
281
282
|
signOutRedirectURL: "http://localhost:3000/dashboard",
|
|
282
283
|
clientID: "client ID",
|
|
283
|
-
|
|
284
|
+
baseUrl: "https://api.asgardeo.io/t/<org_name>"
|
|
284
285
|
}
|
|
285
286
|
|
|
286
287
|
auth.initialize(config);
|
|
@@ -341,7 +342,9 @@ The `sign-in` hook is used to fire a callback function after signing in is succe
|
|
|
341
342
|
```typeScript
|
|
342
343
|
auth.signIn();
|
|
343
344
|
```
|
|
345
|
+
|
|
344
346
|
---
|
|
347
|
+
|
|
345
348
|
### trySignInSilently
|
|
346
349
|
|
|
347
350
|
```typescript
|
|
@@ -361,13 +364,13 @@ This returns a promise that resolves with a `[BasicUserInfo](#BasicUserInfo)` ob
|
|
|
361
364
|
|
|
362
365
|
The `sign-in` hook is used to fire a callback function after signing in is successful. Check the [on()](#on) section for more information.
|
|
363
366
|
|
|
364
|
-
> :warning:
|
|
367
|
+
> :warning: **_Since this method uses an iFrame, this method will not work if third-party cookies are blocked in the browser._**
|
|
365
368
|
|
|
366
369
|
#### Example
|
|
367
370
|
|
|
368
371
|
```typescript
|
|
369
|
-
auth.trySignInSilently().then((response)=>{
|
|
370
|
-
if(response) {
|
|
372
|
+
auth.trySignInSilently().then((response) => {
|
|
373
|
+
if (response) {
|
|
371
374
|
// The user is signed in.
|
|
372
375
|
// handle basic user info
|
|
373
376
|
}
|
|
@@ -409,10 +412,10 @@ httpRequest(config: HttpRequestConfig): Promise<HttpResponse>;
|
|
|
409
412
|
1. config: `[HttpRequestConfig](#httpRequestConfig)`
|
|
410
413
|
A config object with the settings necessary to send http requests. This object is similar to the `AxiosRequestConfig` but provides these additional attributes:
|
|
411
414
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
415
|
+
| Attribute | Type | Default | Description |
|
|
416
|
+
| ------------------------ | --------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
417
|
+
| `attachToken` | `boolean` | `true` | If set to `true`, the token will be attached to the request header. |
|
|
418
|
+
| `shouldEncodeToFormData` | `boolean` | `false` | If set to `true`, the request body will be encoded to `FormData`. The body (specified by the `data` attribute) should be a Javascript object. |
|
|
416
419
|
|
|
417
420
|
#### Returns
|
|
418
421
|
|
|
@@ -725,6 +728,7 @@ If you are using TypeScript, you may want to use the `Hooks` enum that consists
|
|
|
725
728
|
| `"http-request-success"` | `httpRequest()` (Called when an http requests returns a response successfully) |
|
|
726
729
|
| `"revoke-access-token"` | `revokeAccessToken()` | A boolean value indicating if the process was successful or not |
|
|
727
730
|
| `"custom-grant"` | `customGrant()` | Returns the response from the custom grant request. |
|
|
731
|
+
| `sign-out-failed` | `signOut()` (Called when sign out fails) | An object of type [`SignOutError`](#SignOutError). |
|
|
728
732
|
|
|
729
733
|
**When the user signs out, the user is taken to the Asgardeo's logout page and then redirected back to the SPA on successful log out. Hence, developers should ensure that the `"sign-out"` hook is called when the page the user is redirected to loads.**
|
|
730
734
|
|
|
@@ -921,7 +925,7 @@ This table shows the extended attributes provided by the `Config` interface.
|
|
|
921
925
|
#### The AuthClientConfig Interface
|
|
922
926
|
|
|
923
927
|
| Attribute | Required/Optional | Type | Default Value | Description |
|
|
924
|
-
| ---------------------------- | ----------------- | --------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
|
|
928
|
+
| ---------------------------- | ----------------- | --------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
925
929
|
| `signInRedirectURL` | Required | `string` | "" | The URL to redirect to after the user authorizes the client app. eg: `https//localhost:3000/sign-in` |
|
|
926
930
|
| `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: `http://localhost:3000/dashboard` |
|
|
927
931
|
| `clientHost` | Optional | `string` | The origin of the client app obtained using `window.origin` | The hostname of the client app. eg: `https://localhost:3000` |
|
|
@@ -931,10 +935,10 @@ This table shows the extended attributes provided by the `Config` interface.
|
|
|
931
935
|
| `prompt` | Optional | `string` | "" | Specifies the prompt type of an OIDC request |
|
|
932
936
|
| `responseMode` | Optional | `ResponseMode` | `"query"` | Specifies the response mode. The value can either be `query` or `form_post` |
|
|
933
937
|
| `scope` | Optional | `string[]` | `["openid"]` | Specifies the requested scopes. |
|
|
934
|
-
| `
|
|
935
|
-
| `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. |
|
|
938
|
+
| `baseUrl` | Required | `string` | "" | The origin of the Identity Provider. eg: `https://api.asgardeo.io/t/<org_name>` |
|
|
936
939
|
| `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. |
|
|
937
|
-
| `
|
|
940
|
+
| `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.
|
|
941
|
+
| `wellKnownEndpoint` | Optional (Required if `baseUrl` or `endpoints` is not provided) | `string` | `"/oauth2/token/.well-known/openid-configuration"` | The URL of the `.well-known` endpoint. |
|
|
938
942
|
| `validateIDToken` | Optional | `boolean` | `true` | Allows you to enable/disable JWT ID token validation after obtaining the ID token. |
|
|
939
943
|
| `clockTolerance` | Optional | `number` | `60` | Allows you to configure the leeway when validating the id_token. |
|
|
940
944
|
|
|
@@ -973,7 +977,6 @@ This table shows the extended attributes provided by the `Config` interface.
|
|
|
973
977
|
| `checkSessionIframe` | `string` | `"/oidc/checksession"` | The check-session endpoint. |
|
|
974
978
|
| `endSessionEndpoint` | `string` | `"/oidc/logout"` | The end-session endpoint. |
|
|
975
979
|
| `issuer` | `string` | "" | The issuer of the token. |
|
|
976
|
-
| `wellKnownEndpoint` | `string` | `"/oauth2/token/.well-known/openid-configuration"` | The well-known endpoint. This is the default endpoint defined in the SDK. |
|
|
977
980
|
|
|
978
981
|
### CustomGrantConfig
|
|
979
982
|
|
|
@@ -1001,7 +1004,7 @@ Session information can be attached to the body of a custom-grant request using
|
|
|
1001
1004
|
|
|
1002
1005
|
### DecodedIDTokenPayload
|
|
1003
1006
|
|
|
1004
|
-
| Attribute
|
|
1007
|
+
| Attribute | Type | Description |
|
|
1005
1008
|
| ------------------ | ---------------------- | ---------------------------------------------- |
|
|
1006
1009
|
| aud | `string` \| `string[]` | The audience. |
|
|
1007
1010
|
| sub | `string` | The subject. This is the username of the user. |
|
|
@@ -1011,26 +1014,52 @@ Session information can be attached to the body of a custom-grant request using
|
|
|
1011
1014
|
| tenant_domain | `string` | The tenant domain to which the user belongs. |
|
|
1012
1015
|
|
|
1013
1016
|
### HTTPRequestConfig
|
|
1017
|
+
|
|
1014
1018
|
This extends the `AxiosRequestConfig` by providing an additional attribute that is used to specify if the access token should be attached to the request or not.
|
|
1015
1019
|
|Attribute | Type | Description|
|
|
1016
1020
|
|--|--|--|
|
|
1017
1021
|
|attachToken| `boolean`| Specifies if the access token should be attached to the header of the request.|
|
|
1018
1022
|
|
|
1023
|
+
### SignOutError
|
|
1024
|
+
|
|
1025
|
+
| Attribute | Type | Description |
|
|
1026
|
+
| ----------------- | -------- | ---------------------- |
|
|
1027
|
+
| error | `string` | The error message. |
|
|
1028
|
+
| error_description | `string` | The error description. |
|
|
1029
|
+
|
|
1019
1030
|
## Develop
|
|
1020
1031
|
|
|
1021
1032
|
### Prerequisites
|
|
1022
1033
|
|
|
1023
1034
|
- `Node.js` (version 10 or above).
|
|
1024
|
-
- `
|
|
1035
|
+
- `yarn` package manager.
|
|
1025
1036
|
|
|
1026
1037
|
### Installing Dependencies
|
|
1027
1038
|
|
|
1028
1039
|
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.
|
|
1029
1040
|
|
|
1030
1041
|
```
|
|
1031
|
-
|
|
1042
|
+
yarn build
|
|
1032
1043
|
```
|
|
1033
1044
|
|
|
1045
|
+
## Error Codes
|
|
1046
|
+
|
|
1047
|
+
Error code consist of four parts separated by a `-`.
|
|
1048
|
+
|
|
1049
|
+
- The first part refers to the SDK. Example: `JS` refers to this SDK.
|
|
1050
|
+
- The second part refers to the code file. Example: `MAIN_THREAD_CLIENT` refers to the `main-thread-client.ts` file.
|
|
1051
|
+
- The third part is the abbreviation of the name of the method/function that threw the error. If there are more than one method/function with the same abbreviation, then a number based on the order of declaration is appended to the abbreviation. Example: `HR` refers to the `httpRequest` method.
|
|
1052
|
+
- The fourth part refers to the type of error and is position. Example: `IV02` refers to an invalid argument error and the fact that this is the second error in the method/function. The following error types are available:
|
|
1053
|
+
|
|
1054
|
+
| Error Code | Description |
|
|
1055
|
+
| :--------- | :------------ |
|
|
1056
|
+
| `NE` | Network Error |
|
|
1057
|
+
| `HE` | Http Error |
|
|
1058
|
+
| `IV` | Invalid |
|
|
1059
|
+
| `NF` | Not Found |
|
|
1060
|
+
| `TO` | Timeout |
|
|
1061
|
+
| `SE` | Server Error |
|
|
1062
|
+
|
|
1034
1063
|
## Contribute
|
|
1035
1064
|
|
|
1036
1065
|
Please read [Contributing to the Code Base](http://wso2.github.io/) for details on our code of conduct, and the process for submitting pull requests to us.
|
package/babel.config.js
CHANGED