cidaas-javascript-sdk 3.0.5 → 3.1.1

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/CHANGELOG.md CHANGED
@@ -1,6 +1,7 @@
1
- ## [3.0.5](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/compare/v3.0.4...v3.0.5) (2023-08-04)
1
+ ## [3.1.1](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/compare/v3.1.0...v3.1.1) (2023-09-05)
2
2
 
3
3
 
4
4
  ### Bug Fixes
5
5
 
6
- * store code verifier in pkce flow ([f6f7835](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/commit/f6f783507e6b3d7bc3bf24140e546951d71dd4b5))
6
+ * **https://gitlab.widas.de/cidaas-v2/user-management1/issues/-/issues/855:** altered usercheck exists with remember me & webfinger ([a4f3694](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/commit/a4f3694643199171bc8b3144f1e2cfae85d3eac8))
7
+ * **https://gitlab.widas.de/cidaas-v2/user-management1/issues/-/issues/855:** altered usercheck exists with remember me & webfinger ([d253b76](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/commit/d253b763e8b1912e36e0b811cfddf1714d6bc6bc))
package/README.md CHANGED
@@ -40,8 +40,27 @@ Please check the [Changelogs](https://github.com/Cidaas/cidaas-sdk-javascript-v2
40
40
 
41
41
  #### Initialisation
42
42
 
43
- After adding ****cidaas-sdk.js**** create a local file and name it like ****index.js****.
43
+ After adding ****cidaas-sdk.js**** create a local file and name it like ****index.js****. Cidaas options variable should be defined there for initializing cidaas sdk.
44
44
 
45
+ Cidaas options variable support every [OIDC Client UserManagerSettings Properties](https://authts.github.io/oidc-client-ts/interfaces/UserManagerSettings.html) which has the following notable properties:
46
+
47
+ | Property Name | Required | Description |
48
+ | ------ | ------ | ------ |
49
+ | authority | yes | cidaas instance base url |
50
+ | client_id | yes | client application's identifier, which could be found in cidaas admin ui |
51
+ | redirect_uri | yes | URL to be redirected after successful login attempt. |
52
+ | post_logout_redirect_uri | no | URL to be redirected after successful logout attempt. |
53
+ | response_type | no | The type of response that will come after successful login attempt. The default value is 'code' if no properties is being sent. This determines the OAuth authorization flow being used.|
54
+ | scope | no | the scope the application requires and requests from cidaas. The default value is 'openid' if no properties is being sent. |
55
+
56
+ In addition to it, There are the following custom properties which could / need to be defined in cidaas option variable:
57
+
58
+ | Property Name | Required | Description |
59
+ | ------ | ------ | ------ |
60
+ | cidaas_version | no | You can find out the cidaas version from cidaas service portal |
61
+ | mode | no | Define which login variants to be called during calling loginWithBrowser(). The selection includes: `redirect`, `window` and `silent`. The default value is `redirect` if no properties is being sent. |
62
+
63
+ an example of index.js is looks like this:
45
64
 
46
65
  ```js
47
66
  var options = {
@@ -49,11 +68,10 @@ var options = {
49
68
  client_id: 'your app id',
50
69
  redirect_uri: 'your redirect url',
51
70
  post_logout_redirect_uri: 'your post logout redirect url',
52
- popup_post_logout_redirect_uri: 'your post popup logout redirect url',
53
- silent_redirect_uri: 'your silent redirect url',
54
71
  response_type: 'id_token token',
55
72
  scope: 'openid email roles profile',
56
- mode: 'redirect'
73
+ mode: 'redirect',
74
+ cidaas_version: 3
57
75
  }
58
76
  ```
59
77
 
@@ -71,6 +89,18 @@ Since version 1.2.0 using 'code' as the 'response_type' will start the OAuth Aut
71
89
  var cidaas = new CidaasSDK.WebAuth(options);
72
90
  ```
73
91
 
92
+ #### Migrating to Cidaas V3
93
+
94
+ Cidaas V3 has response handling adjustment on some of cidaas service call. To migrate to cidaas V3, you need to do the following:
95
+
96
+ - ensure that you use at least cidaas version: 3.* You can find out the cidaas version from cidaas service portal and ask our customer service if it need to be updated.
97
+
98
+ - ensure that you use at least cidaas-javascript-sdk version: 3.0.5
99
+
100
+ - add `cidaas_version: 3` to Cidaas options variable
101
+
102
+ Without Providing CidaasVersion, your application will use response handling of Cidaas V2 by default.
103
+
74
104
  #### Usage
75
105
 
76
106
  #### Browser Methods
@@ -2582,4 +2612,4 @@ The SDK will throws Custom Exception if something went wrong during the operatio
2582
2612
  | HTTP Status Code | When could it be thrown |
2583
2613
  |----------------- | ----------------------- |
2584
2614
  | 500 | during creation of WebAuth instance |
2585
- | 417 | if there are any other failure |
2615
+ | 417 | if there are any other failure |
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "cidaas-javascript-sdk",
3
- "version": "3.0.5",
3
+ "version": "3.1.1",
4
4
  "author": "cidaas by Widas ID GmbH",
5
5
  "description": "Cidaas native javascript sdk",
6
6
  "license": "MIT",
7
7
  "main": "types/main/index.js",
8
8
  "types": "types/main/index.d.ts",
9
+ "testEnvironment": "jsdom",
9
10
  "engine": {
10
11
  "node": ">=8.9.10"
11
12
  },
12
13
  "scripts": {
13
14
  "dev": "tsc && webpack --config webpack.dev.js",
14
15
  "build": "tsc && webpack --config webpack.prod.js",
15
- "test": "echo 'test'",
16
- "test:coverage": "echo 'test coverage'"
16
+ "test": "jest --transformIgnorePatterns \"node_modules/(?!@toolz/allow)/\" --env=jsdom",
17
+ "test:coverage": "jest --coverage --env=jsdom"
17
18
  },
18
19
  "files": [
19
20
  "src",
@@ -27,23 +28,33 @@
27
28
  },
28
29
  "dependencies": {
29
30
  "@fingerprintjs/fingerprintjs": "^3.4.0",
31
+ "@toolz/is-a-regular-object": "^1.0.1",
30
32
  "@types/crypto-js": "^4.1.1",
33
+ "@types/jest": "^29.5.3",
31
34
  "crypto-js": "^4.1.1",
32
35
  "oidc-client-ts": "^2.2.1"
33
36
  },
34
37
  "devDependencies": {
38
+ "@babel/core": "^7.22.9",
39
+ "@babel/preset-env": "^7.22.9",
40
+ "@babel/preset-typescript": "^7.22.5",
41
+ "babel-jest": "^29.6.1",
42
+ "@jest/globals": "^29.6.1",
43
+ "@types/mocha": "5.2.7",
44
+ "jest": "^29.6.1",
45
+ "jest-environment-jsdom": "^29.6.1",
46
+ "jsdom": "^22.1.0",
47
+ "jsdom-global": "^3.0.2",
48
+ "mocha": "^10.1.0",
35
49
  "terser-webpack-plugin": "^5.2.4",
50
+ "ts-jest": "^29.1.1",
36
51
  "ts-loader": "^9.4.2",
52
+ "ts-node": "10.9.1",
37
53
  "typescript": "^4.5.4",
38
54
  "webpack": "^5.59.1",
39
55
  "webpack-cli": "^4.9.1",
40
56
  "webpack-dev-server": "^4.3.1",
41
57
  "webpack-hot-middleware": "^2.25.1",
42
58
  "webpack-merge": "^5.8.0"
43
- },
44
- "jest": {
45
- "collectCoverageFrom": [
46
- "src/main/**/*.{js,jsx,mjs}"
47
- ]
48
59
  }
49
60
  }
@@ -13,7 +13,7 @@ export namespace ConsentService {
13
13
  sub: string;
14
14
  }) {
15
15
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/usage/public/info";
16
- return Helper.createPostPromise(options, _serviceURL, false);
16
+ return Helper.createPostPromise(options, _serviceURL, false,"POST");
17
17
  };
18
18
 
19
19
  /**
@@ -23,7 +23,7 @@ export namespace ConsentService {
23
23
  */
24
24
  export function acceptConsentV2(options: IConsentAcceptEntity) {
25
25
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/usage/accept";
26
- return Helper.createPostPromise(options, _serviceURL, false);
26
+ return Helper.createPostPromise(options, _serviceURL, false, "POST" );
27
27
  };
28
28
 
29
29
  /**
@@ -36,30 +36,8 @@ export namespace ConsentService {
36
36
  locale: string;
37
37
  access_token: string;
38
38
  }) {
39
- return new Promise((resolve, reject) => {
40
- try {
41
- var http = new XMLHttpRequest();
42
- var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/versions/details/" + options.scopeid + "?locale=" + options.locale;
43
- http.onreadystatechange = function () {
44
- if (http.readyState == 4) {
45
- if (http.responseText) {
46
- resolve(JSON.parse(http.responseText));
47
- } else {
48
- resolve(false);
49
- }
50
- }
51
- };
52
- http.open("GET", _serviceURL, true);
53
- http.setRequestHeader("Content-type", "application/json");
54
- http.setRequestHeader("Authorization", `Bearer ${options.access_token}`);
55
- if (window.localeSettings) {
56
- http.setRequestHeader("accept-language", window.localeSettings);
57
- }
58
- http.send();
59
- } catch (ex) {
60
- reject(ex);
61
- }
62
- });
39
+ const _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/versions/details/" + options.scopeid + "?locale=" + options.locale;
40
+ return Helper.createPostPromise(undefined, _serviceURL,false, "GET", options.access_token);
63
41
  };
64
42
 
65
43
  /**
@@ -73,7 +51,7 @@ export namespace ConsentService {
73
51
  scopes: string[];
74
52
  }) {
75
53
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/consent/scope/accept";
76
- return Helper.createPostPromise(options, _serviceURL, false);
54
+ return Helper.createPostPromise(options, _serviceURL, false, "POST");
77
55
  };
78
56
 
79
57
  /**
@@ -83,7 +61,7 @@ export namespace ConsentService {
83
61
  */
84
62
  export function acceptClaimConsent(options: { client_id: string; sub: string; accepted_claims: string[]; }) {
85
63
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/consent/claim/accept";
86
- return Helper.createPostPromise(options, _serviceURL, false);
64
+ return Helper.createPostPromise(options, _serviceURL, false, "POST");
87
65
  };
88
66
 
89
67
  /**
@@ -93,6 +71,6 @@ export namespace ConsentService {
93
71
  */
94
72
  export function revokeClaimConsent(options: { client_id: string; sub: string; revoked_claims: string[]; }) {
95
73
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/consent/claim/revoke";
96
- return Helper.createPostPromise(options, _serviceURL, false);
74
+ return Helper.createPostPromise(options, _serviceURL, false, "POST");
97
75
  };
98
76
  }
@@ -1,3 +1,5 @@
1
+ import { UserManagerSettings } from "oidc-client-ts";
2
+
1
3
  export interface AcceptResetPasswordEntity {
2
4
  resetRequestId: string ;
3
5
  exchangeId: string;
@@ -126,7 +128,8 @@ export class FindUserEntity {
126
128
  customFields: any;
127
129
  provider: string = "";
128
130
  providerUserId: string = "";
129
-
131
+ rememberMe: string = "";
132
+ webfinger: string = "";
130
133
  sub_not: string = "";
131
134
 
132
135
  //additional param
@@ -319,49 +322,6 @@ export interface IUserEntity {
319
322
  }
320
323
 
321
324
 
322
- export interface IUserEntity {
323
- userStatus: string;
324
- user_status: string;
325
- user_status_reason: string;
326
- username: string;
327
- sub: string;
328
- given_name: string;
329
- family_name: string;
330
- middle_name: string;
331
- nickname: string;
332
- originalProviderUserId?: string[];
333
- email: string;
334
- email_verified: boolean;
335
- mobile_number: string;
336
- mobile_number_obj: IMobileEntity | null;
337
- mobile_number_verified: boolean;
338
- phone_number: string;
339
- phone_number_obj: IMobileEntity | null;
340
- phone_number_verified: boolean;
341
- profile: string;
342
- picture: string;
343
- website: string;
344
- gender: string;
345
- zoneinfo: string;
346
- locale: string;
347
- birthdate: Date | null;
348
- address?: IAddressEntity;
349
- customFields?: any;
350
- identityCustomFields?: any;
351
- password: string;
352
- provider: string;
353
- providerUserId: string;
354
- identityId: string;
355
- mfa_enabled?: boolean;
356
- roles: string[];
357
- userGroups: IUserGroupMap[];
358
- groups?: IUserGroupMap[];
359
- rawJSON: string;
360
- trackId: string;
361
- need_reset_password: boolean;
362
- }
363
-
364
-
365
325
  export interface IUserGroupMap {
366
326
  sub: string;
367
327
  groupId: string;
@@ -643,3 +603,8 @@ export interface IChangePasswordEntity {
643
603
  loginSettingsId: string;
644
604
  client_id?: string;
645
605
  }
606
+
607
+ export interface ICidaasSDKSettings extends UserManagerSettings {
608
+ mode?: string;
609
+ cidaas_version?: number;
610
+ }
@@ -26,11 +26,11 @@ export class Helper {
26
26
  * @param options
27
27
  * @param serviceurl
28
28
  * @param errorResolver
29
- * @param access_token
30
- * @param headers
29
+ * @param access_token??
30
+ * @param headers??
31
31
  * @returns
32
32
  */
33
- static createPostPromise(options: any, serviceurl: string, errorResolver: boolean, access_token?: string, headers?: any) {
33
+ static createPostPromise(options: any, serviceurl: string, errorResolver: boolean, method:string, access_token?: string, headers?: any) {
34
34
  return new Promise((resolve, reject) => {
35
35
  try {
36
36
  var http = new XMLHttpRequest();
@@ -43,7 +43,7 @@ export class Helper {
43
43
  }
44
44
  }
45
45
  };
46
- http.open("POST", serviceurl, true);
46
+ http.open(method, serviceurl, true);
47
47
  http.setRequestHeader("Content-type", "application/json");
48
48
  if (headers) {
49
49
  for (var key in headers) {
@@ -9,30 +9,13 @@ export namespace TokenService {
9
9
  * @returns
10
10
  */
11
11
  export function renewToken(options: AccessTokenRequest) {
12
- return new Promise((resolve, reject) => {
13
- try {
14
- if (!options.refresh_token) {
15
- throw new CustomException("refresh_token cannot be empty", 417);
16
- }
17
- options.client_id = window.webAuthSettings.client_id;
18
- options.grant_type = 'refresh_token';
19
- var http = new XMLHttpRequest();
20
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
21
- http.onreadystatechange = function () {
22
- if (http.readyState == 4) {
23
- resolve(JSON.parse(http.responseText));
24
- }
25
- };
26
- http.open("POST", _serviceURL, true);
27
- http.setRequestHeader("Content-type", "application/json");
28
- if (window.localeSettings) {
29
- http.setRequestHeader("accept-language", window.localeSettings);
30
- }
31
- http.send(JSON.stringify(options));
32
- } catch (ex) {
33
- reject(ex);
34
- }
35
- });
12
+ if (!options.refresh_token) {
13
+ throw new CustomException("refresh_token cannot be empty", 417);
14
+ }
15
+ options.client_id = window.webAuthSettings.client_id;
16
+ options.grant_type = 'refresh_token';
17
+ const _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
18
+ return Helper.createPostPromise(options, _serviceURL, undefined, "POST");
36
19
  };
37
20
 
38
21
  /**
@@ -40,39 +23,19 @@ export namespace TokenService {
40
23
  * @param options
41
24
  * @returns
42
25
  */
43
- export function getAccessToken(options: AccessTokenRequest) {
44
- return new Promise((resolve, reject) => {
45
- try {
46
- if (!options.code) {
47
- throw new CustomException("code cannot be empty", 417);
48
- }
49
- options.client_id = window.webAuthSettings.client_id;
50
- options.redirect_uri = window.webAuthSettings.redirect_uri;
51
- options.grant_type = "authorization_code";
52
- var http = new XMLHttpRequest();
53
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
54
- http.onreadystatechange = function () {
55
- if (http.readyState == 4) {
56
- resolve(JSON.parse(http.responseText));
57
- }
58
- };
59
- http.open("POST", _serviceURL, true);
60
- http.setRequestHeader("Content-type", "application/json");
61
- if (window.localeSettings) {
62
- http.setRequestHeader("accept-language", window.localeSettings);
63
- }
64
- if (!window.webAuthSettings.disablePKCE) {
65
- window.usermanager._client.createSigninRequest(window.webAuthSettings).then((signInRequest: any) => {
66
- options.code_verifier = signInRequest.state?.code_verifier;
67
- http.send(JSON.stringify(options));
68
- })
69
- } else {
70
- http.send(JSON.stringify(options));
71
- }
72
- } catch (ex) {
73
- reject(ex);
74
- }
75
- });
26
+ export async function getAccessToken(options: AccessTokenRequest) {
27
+ if (!options.code) {
28
+ throw new CustomException("code cannot be empty", 417);
29
+ }
30
+ options.client_id = window.webAuthSettings.client_id;
31
+ options.redirect_uri = window.webAuthSettings.redirect_uri;
32
+ options.grant_type = "authorization_code";
33
+ if (!window.webAuthSettings.disablePKCE) {
34
+ var signInRequest = await window.usermanager._client.createSigninRequest(window.webAuthSettings);
35
+ options.code_verifier = signInRequest.state?.code_verifier;
36
+ }
37
+ const _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
38
+ return Helper.createPostPromise(options, _serviceURL, undefined, "POST");
76
39
  };
77
40
 
78
41
  /**
@@ -81,28 +44,11 @@ export namespace TokenService {
81
44
  * @returns
82
45
  */
83
46
  export function validateAccessToken(options: TokenIntrospectionEntity) {
84
- return new Promise((resolve, reject) => {
85
- try {
86
- if (!options.token || !options.token_type_hint) {
87
- throw new CustomException("token or token_type_hint cannot be empty", 417);
88
- }
89
- var http = new XMLHttpRequest();
90
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/introspect";
91
- http.onreadystatechange = function () {
92
- if (http.readyState == 4) {
93
- resolve(JSON.parse(http.responseText));
94
- }
95
- };
96
- http.open("POST", _serviceURL, true);
97
- http.setRequestHeader("Content-type", "application/json");
98
- if (window.localeSettings) {
99
- http.setRequestHeader("accept-language", window.localeSettings);
100
- }
101
- http.send(JSON.stringify(options));
102
- } catch (ex) {
103
- reject(ex);
104
- }
105
- });
47
+ if (!options.token || !options.token_type_hint) {
48
+ throw new CustomException("token or token_type_hint cannot be empty", 417);
49
+ }
50
+ const _serviceURL = window.webAuthSettings.authority + "/token-srv/introspect";
51
+ return Helper.createPostPromise(options, _serviceURL, false, "POST");
106
52
  };
107
53
 
108
54
  /**
@@ -114,29 +60,8 @@ export namespace TokenService {
114
60
  track_id: string;
115
61
  locale: string;
116
62
  }) {
117
- return new Promise((resolve, reject) => {
118
- try {
119
- var http = new XMLHttpRequest();
120
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + options.track_id + "?acceptLanguage=" + options.locale;
121
- http.onreadystatechange = function () {
122
- if (http.readyState == 4) {
123
- if (http.responseText) {
124
- resolve(JSON.parse(http.responseText));
125
- } else {
126
- resolve(false);
127
- }
128
- }
129
- };
130
- http.open("GET", _serviceURL, true);
131
- http.setRequestHeader("Content-type", "application/json");
132
- if (window.localeSettings) {
133
- http.setRequestHeader("accept-language", window.localeSettings);
134
- }
135
- http.send();
136
- } catch (ex) {
137
- reject(ex);
138
- }
139
- });
63
+ const _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + options.track_id + "?acceptLanguage=" + options.locale;
64
+ return Helper.createPostPromise(undefined, _serviceURL, false, "GET");
140
65
  };
141
66
 
142
67
  /**
@@ -146,8 +71,8 @@ export namespace TokenService {
146
71
  * @returns
147
72
  */
148
73
  export function updateSuggestMFA(track_id: string, options: ISuggestedMFAActionConfig) {
149
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/suggested/mfa/update/" + track_id;
150
- return Helper.createPostPromise(options, _serviceURL, false);
74
+ const _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/suggested/mfa/update/" + track_id;
75
+ return Helper.createPostPromise(options, _serviceURL, false, "POST");
151
76
  };
152
77
 
153
78
  /**
@@ -156,29 +81,8 @@ export namespace TokenService {
156
81
  * @returns
157
82
  */
158
83
  export function getMissingFieldsLogin(trackId: string) {
159
- return new Promise((resolve, reject) => {
160
- try {
161
- var http = new XMLHttpRequest();
162
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + trackId;
163
- http.onreadystatechange = function () {
164
- if (http.readyState == 4) {
165
- if (http.responseText) {
166
- resolve(JSON.parse(http.responseText));
167
- } else {
168
- resolve(undefined);
169
- }
170
- }
171
- };
172
- http.open("GET", _serviceURL, true);
173
- http.setRequestHeader("Content-type", "application/json");
174
- if (window.localeSettings) {
175
- http.setRequestHeader("accept-language", window.localeSettings);
176
- }
177
- http.send();
178
- } catch (ex) {
179
- reject(ex);
180
- }
181
- });
84
+ const _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + trackId;
85
+ return Helper.createPostPromise(undefined, _serviceURL, false, "GET");
182
86
  };
183
87
 
184
88
  /**