@asgardeo/auth-spa 0.2.21 → 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/README.md +46 -24
- package/dist/asgardeo-spa.production.esm.js +19 -16
- package/dist/asgardeo-spa.production.esm.js.map +1 -1
- package/dist/asgardeo-spa.production.js +19 -16
- 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 +42 -39
- package/dist/polyfilled/asgardeo-spa.production.esm.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.js +42 -39
- 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 +6 -3
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +14 -11
- 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 +40 -34
- package/dist/src/clients/main-thread-client.js.map +1 -1
- package/dist/src/clients/web-worker-client.d.ts.map +1 -1
- package/dist/src/clients/web-worker-client.js +7 -9
- package/dist/src/clients/web-worker-client.js.map +1 -1
- package/dist/src/models/client.d.ts +2 -2
- package/dist/src/models/client.d.ts.map +1 -1
- package/dist/src/utils/crypto-utils.d.ts +2 -4
- package/dist/src/utils/crypto-utils.d.ts.map +1 -1
- package/dist/src/utils/crypto-utils.js +3 -6
- package/dist/src/utils/crypto-utils.js.map +1 -1
- package/dist/src/worker/client.worker.d.ts.map +1 -1
- package/dist/src/worker/client.worker.js +3 -3
- 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 +48 -42
- package/dist/src/worker/worker-core.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/client.ts +24 -35
- package/src/clients/main-thread-client.ts +63 -75
- package/src/clients/web-worker-client.ts +20 -30
- package/src/models/client.ts +2 -3
- package/src/utils/crypto-utils.ts +15 -19
- package/src/worker/client.worker.ts +5 -10
- package/src/worker/worker-core.ts +81 -89
- package/dist/src/exception/exception.d.ts +0 -27
- package/dist/src/exception/exception.d.ts.map +0 -1
- package/dist/src/exception/exception.js +0 -30
- package/dist/src/exception/exception.js.map +0 -1
- package/dist/src/exception/index.d.ts +0 -19
- package/dist/src/exception/index.d.ts.map +0 -1
- package/dist/src/exception/index.js +0 -19
- package/dist/src/exception/index.js.map +0 -1
- package/src/exception/exception.ts +0 -44
- package/src/exception/index.ts +0 -19
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.
|
|
@@ -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,7 +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. |
|
|
728
|
-
| `sign-out-failed` | `signOut()` (Called when sign out fails)
|
|
731
|
+
| `sign-out-failed` | `signOut()` (Called when sign out fails) | An object of type [`SignOutError`](#SignOutError). |
|
|
729
732
|
|
|
730
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.**
|
|
731
734
|
|
|
@@ -922,7 +925,7 @@ This table shows the extended attributes provided by the `Config` interface.
|
|
|
922
925
|
#### The AuthClientConfig Interface
|
|
923
926
|
|
|
924
927
|
| Attribute | Required/Optional | Type | Default Value | Description |
|
|
925
|
-
| ---------------------------- | ----------------- | --------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
|
|
928
|
+
| ---------------------------- | ----------------- | --------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
926
929
|
| `signInRedirectURL` | Required | `string` | "" | The URL to redirect to after the user authorizes the client app. eg: `https//localhost:3000/sign-in` |
|
|
927
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` |
|
|
928
931
|
| `clientHost` | Optional | `string` | The origin of the client app obtained using `window.origin` | The hostname of the client app. eg: `https://localhost:3000` |
|
|
@@ -932,10 +935,10 @@ This table shows the extended attributes provided by the `Config` interface.
|
|
|
932
935
|
| `prompt` | Optional | `string` | "" | Specifies the prompt type of an OIDC request |
|
|
933
936
|
| `responseMode` | Optional | `ResponseMode` | `"query"` | Specifies the response mode. The value can either be `query` or `form_post` |
|
|
934
937
|
| `scope` | Optional | `string[]` | `["openid"]` | Specifies the requested scopes. |
|
|
935
|
-
| `
|
|
936
|
-
| `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>` |
|
|
937
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. |
|
|
938
|
-
| `
|
|
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. |
|
|
939
942
|
| `validateIDToken` | Optional | `boolean` | `true` | Allows you to enable/disable JWT ID token validation after obtaining the ID token. |
|
|
940
943
|
| `clockTolerance` | Optional | `number` | `60` | Allows you to configure the leeway when validating the id_token. |
|
|
941
944
|
|
|
@@ -974,7 +977,6 @@ This table shows the extended attributes provided by the `Config` interface.
|
|
|
974
977
|
| `checkSessionIframe` | `string` | `"/oidc/checksession"` | The check-session endpoint. |
|
|
975
978
|
| `endSessionEndpoint` | `string` | `"/oidc/logout"` | The end-session endpoint. |
|
|
976
979
|
| `issuer` | `string` | "" | The issuer of the token. |
|
|
977
|
-
| `wellKnownEndpoint` | `string` | `"/oauth2/token/.well-known/openid-configuration"` | The well-known endpoint. This is the default endpoint defined in the SDK. |
|
|
978
980
|
|
|
979
981
|
### CustomGrantConfig
|
|
980
982
|
|
|
@@ -1002,7 +1004,7 @@ Session information can be attached to the body of a custom-grant request using
|
|
|
1002
1004
|
|
|
1003
1005
|
### DecodedIDTokenPayload
|
|
1004
1006
|
|
|
1005
|
-
| Attribute
|
|
1007
|
+
| Attribute | Type | Description |
|
|
1006
1008
|
| ------------------ | ---------------------- | ---------------------------------------------- |
|
|
1007
1009
|
| aud | `string` \| `string[]` | The audience. |
|
|
1008
1010
|
| sub | `string` | The subject. This is the username of the user. |
|
|
@@ -1012,32 +1014,52 @@ Session information can be attached to the body of a custom-grant request using
|
|
|
1012
1014
|
| tenant_domain | `string` | The tenant domain to which the user belongs. |
|
|
1013
1015
|
|
|
1014
1016
|
### HTTPRequestConfig
|
|
1017
|
+
|
|
1015
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.
|
|
1016
1019
|
|Attribute | Type | Description|
|
|
1017
1020
|
|--|--|--|
|
|
1018
1021
|
|attachToken| `boolean`| Specifies if the access token should be attached to the header of the request.|
|
|
1019
1022
|
|
|
1020
1023
|
### SignOutError
|
|
1021
|
-
|
|
1022
|
-
|
|
|
1023
|
-
|
|
|
1024
|
-
|
|
|
1024
|
+
|
|
1025
|
+
| Attribute | Type | Description |
|
|
1026
|
+
| ----------------- | -------- | ---------------------- |
|
|
1027
|
+
| error | `string` | The error message. |
|
|
1028
|
+
| error_description | `string` | The error description. |
|
|
1025
1029
|
|
|
1026
1030
|
## Develop
|
|
1027
1031
|
|
|
1028
1032
|
### Prerequisites
|
|
1029
1033
|
|
|
1030
1034
|
- `Node.js` (version 10 or above).
|
|
1031
|
-
- `
|
|
1035
|
+
- `yarn` package manager.
|
|
1032
1036
|
|
|
1033
1037
|
### Installing Dependencies
|
|
1034
1038
|
|
|
1035
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.
|
|
1036
1040
|
|
|
1037
1041
|
```
|
|
1038
|
-
|
|
1042
|
+
yarn build
|
|
1039
1043
|
```
|
|
1040
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
|
+
|
|
1041
1063
|
## Contribute
|
|
1042
1064
|
|
|
1043
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.
|