cidaas-javascript-sdk 2.4.2 → 2.5.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +5 -3
  2. package/README.md +2 -3
  3. package/package.json +10 -12
  4. package/src/main/authentication/index.ts +223 -0
  5. package/src/main/global.d.ts +10 -0
  6. package/src/main/index.ts +6 -0
  7. package/src/main/web-auth/ConsentService.ts +98 -0
  8. package/src/main/web-auth/Entities.ts +645 -0
  9. package/src/main/web-auth/Helper.ts +75 -0
  10. package/src/main/web-auth/LoginService.ts +248 -0
  11. package/src/main/web-auth/TokenService.ts +196 -0
  12. package/src/main/web-auth/UserService.ts +388 -0
  13. package/src/main/web-auth/VerificationService.ts +267 -0
  14. package/src/main/web-auth/WebAuth.ts +1706 -0
  15. package/types/authentication/index.d.ts +55 -0
  16. package/types/authentication/index.js +262 -0
  17. package/types/index.d.ts +4 -0
  18. package/types/index.js +9 -0
  19. package/types/web-auth/ConsentService.d.ts +59 -0
  20. package/types/web-auth/ConsentService.js +97 -0
  21. package/types/web-auth/Entities.d.ts +567 -0
  22. package/types/web-auth/Entities.js +88 -0
  23. package/types/web-auth/Helper.d.ts +24 -0
  24. package/types/web-auth/Helper.js +89 -0
  25. package/types/web-auth/LoginService.d.ts +102 -0
  26. package/types/web-auth/LoginService.js +248 -0
  27. package/types/web-auth/TokenService.d.ts +48 -0
  28. package/types/web-auth/TokenService.js +210 -0
  29. package/types/web-auth/UserService.d.ts +143 -0
  30. package/types/web-auth/UserService.js +408 -0
  31. package/types/web-auth/VerificationService.d.ts +125 -0
  32. package/types/web-auth/VerificationService.js +273 -0
  33. package/types/web-auth/WebAuth.d.ts +895 -0
  34. package/types/web-auth/WebAuth.js +1767 -0
  35. package/src/main/.gitkeep +0 -0
  36. package/src/main/authentication/index.js +0 -213
  37. package/src/main/index.js +0 -11
  38. package/src/main/web-auth/exception.js +0 -7
  39. package/src/main/web-auth/webauth.js +0 -1899
  40. package/src/test/sum.js +0 -4
  41. package/src/test/test.js +0 -5
  42. package/types/.DS_Store +0 -0
  43. package/types/main/authentication/index.d.ts +0 -15
  44. package/types/main/index.d.ts +0 -5
  45. package/types/main/web-auth/exception.d.ts +0 -7
  46. package/types/main/web-auth/webauth.d.ts +0 -141
  47. package/types/test/sum.d.ts +0 -2
  48. package/types/test/test.d.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
- ## [2.4.2](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/compare/v2.4.1...v2.4.2) (2023-04-04)
1
+ # [2.5.0](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/compare/v2.4.3...v2.5.0) (2023-05-03)
2
2
 
3
3
 
4
- ### Bug Fixes
4
+ ### Features
5
5
 
6
- * read tag after release ([e66a657](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/commit/e66a65704f738e0105a6047958f130756cbf99b5))
6
+ * js to ts migration with version update in readme ([2e8ae77](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/commit/2e8ae77f8c521c796f45ba87aadc17c19f2ebca8))
7
+ * typescript migration ([79d875d](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/commit/79d875d5983a35500bc70ee4e7e6f189468966e4))
8
+ * typescript migration ([d84074d](https://gitlab.widas.de/cidaas-public-devkits/cidaas-public-sdks/cidaas-javascript-sdk/commit/d84074def880a2b321dd3a8a1541b1ecec203d16))
package/README.md CHANGED
@@ -22,9 +22,8 @@ Make sure you have installed all of the following prerequisites on your developm
22
22
  From CDN
23
23
 
24
24
  ```html
25
- <!-- Release version 2.0.9 -->
26
- <!-- Minified version -->
27
- <script src="https://cdn.cidaas.de/javascript/oidc/2.4.2/cidaas-javascript-sdk.min.js"></script>
25
+ <!-- Replace the required <version> in the script tag, example: 3.0.0. All the released tag can be found https://www.npmjs.com/package/cidaas-javascript-sdk?activeTab=versions -->
26
+ <script src="https://cdn.cidaas.de/javascript/oidc/<version>/cidaas-javascript-sdk.min.js"></script>
28
27
  ```
29
28
 
30
29
  From npm
package/package.json CHANGED
@@ -1,20 +1,19 @@
1
1
  {
2
2
  "name": "cidaas-javascript-sdk",
3
- "version": "2.4.2",
3
+ "version": "2.5.0",
4
4
  "author": "cidaas by Widas ID GmbH",
5
5
  "description": "Cidaas native javascript sdk",
6
6
  "license": "MIT",
7
- "main": "src/main/index.js",
7
+ "main": "types/main/index.js",
8
8
  "types": "types/main/index.d.ts",
9
9
  "engine": {
10
10
  "node": ">=8.9.10"
11
11
  },
12
12
  "scripts": {
13
- "dev": "webpack --config webpack.dev.js",
14
- "build": "npm run build-types && webpack --config webpack.prod.js",
15
- "test": "jest --coverage",
16
- "test:coverage": "jest --coverage",
17
- "build-types": "npx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir types"
13
+ "dev": "tsc && webpack --config webpack.dev.js",
14
+ "build": "tsc && webpack --config webpack.prod.js",
15
+ "test": "echo 'test'",
16
+ "test:coverage": "echo 'test coverage'"
18
17
  },
19
18
  "files": [
20
19
  "src",
@@ -28,16 +27,15 @@
28
27
  },
29
28
  "dependencies": {
30
29
  "@fingerprintjs/fingerprintjs": "^3.4.0",
31
- "@types/node": "^18.11.18",
30
+ "@types/crypto-js": "^4.1.1",
32
31
  "crypto-js": "^4.1.1",
33
- "oidc-client": "^1.11.5"
32
+ "oidc-client-ts": "^2.2.1"
34
33
  },
35
34
  "devDependencies": {
36
- "compression-webpack-plugin": "^9.0.0",
37
- "jest": "27.3.1",
38
35
  "terser-webpack-plugin": "^5.2.4",
36
+ "ts-loader": "^9.4.2",
39
37
  "typescript": "^4.5.4",
40
- "webpack": "^5.76.2",
38
+ "webpack": "^5.59.1",
41
39
  "webpack-cli": "^4.9.1",
42
40
  "webpack-dev-server": "^4.3.1",
43
41
  "webpack-hot-middleware": "^2.25.1",
@@ -0,0 +1,223 @@
1
+ import { UserManager, UserManagerSettings } from "oidc-client-ts";
2
+
3
+ export class Authentication {
4
+
5
+ constructor(public webAuthSettings: UserManagerSettings, public userManager: UserManager) { }
6
+
7
+ /**
8
+ * redirect sign in
9
+ * @param view_type
10
+ */
11
+ redirectSignIn(view_type: string) {
12
+ try {
13
+ if (this.userManager) {
14
+ if (this.webAuthSettings) {
15
+ if (!this.webAuthSettings.extraQueryParams) {
16
+ this.webAuthSettings.extraQueryParams = {};
17
+ }
18
+ this.webAuthSettings.extraQueryParams.view_type = view_type;
19
+ if (this.webAuthSettings.scope) {
20
+ if (this.webAuthSettings.response_type.indexOf("id_token") == -1 && this.webAuthSettings.scope.indexOf("openid") != -1 && !this.webAuthSettings.extraQueryParams.nonce) {
21
+ this.webAuthSettings.extraQueryParams.nonce = new Date().getTime().toString();
22
+ }
23
+ }
24
+ }
25
+ this.userManager.signinRedirect({
26
+ extraQueryParams: this.webAuthSettings.extraQueryParams,
27
+ redirect_uri: this.webAuthSettings.redirect_uri
28
+ }).then(function () {
29
+ console.log("Redirect logged in using cidaas sdk");
30
+ });
31
+ } else {
32
+ throw "user manager is null";
33
+ }
34
+ } catch (ex) {
35
+ console.log("user manager instance is empty : " + ex);
36
+ }
37
+ };
38
+
39
+ /**
40
+ * redirect sign in callback
41
+ * @returns
42
+ */
43
+ redirectSignInCallback() {
44
+ return new Promise((resolve, reject) => {
45
+ try {
46
+ if (this.userManager) {
47
+ this.userManager.signinRedirectCallback(this.webAuthSettings.redirect_uri)
48
+ .then(function (user: any) {
49
+ if (user) {
50
+ resolve(user);
51
+ return;
52
+ }
53
+ resolve(undefined);
54
+ });
55
+ } else {
56
+ throw "user manager is null";
57
+ }
58
+ } catch (ex) {
59
+ reject(ex);
60
+ }
61
+ });
62
+ }
63
+
64
+ /**
65
+ * redirect sign out
66
+ * @returns
67
+ */
68
+ redirectSignOut() {
69
+ return new Promise((resolve, reject) => {
70
+ try {
71
+ if (this.userManager && this.webAuthSettings) {
72
+ this.userManager.signoutRedirect({
73
+ state: this.webAuthSettings
74
+ }).then(function (resp: any) {
75
+ console.log('signed out', resp);
76
+ window.authentication.redirectSignOutCallback().then(function (resp: any) {
77
+ resolve(resp);
78
+ });
79
+ });
80
+ } else {
81
+ throw "user manager or settings is null";
82
+ }
83
+ } catch (ex) {
84
+ reject(ex);
85
+ }
86
+ });
87
+ };
88
+
89
+ /**
90
+ * redirect sign out callback
91
+ * @returns
92
+ */
93
+ redirectSignOutCallback() {
94
+ return new Promise((resolve, reject) => {
95
+ try {
96
+ if (this.userManager) {
97
+ this.userManager.signoutRedirectCallback().then(function (resp: any) {
98
+ console.log("Signed out");
99
+ resolve(resp);
100
+ });
101
+ } else {
102
+ resolve(undefined);
103
+ throw "user manager is null";
104
+ }
105
+ } catch (ex) {
106
+ reject(ex);
107
+ }
108
+ });
109
+ };
110
+
111
+ /**
112
+ * pop up sign in
113
+ */
114
+ popupSignIn() {
115
+ try {
116
+ if (this.userManager && this.webAuthSettings) {
117
+ this.userManager.signinPopup().then(function () {
118
+ console.log("signed in");
119
+ });
120
+ } else {
121
+ throw "user manager or settings is null";
122
+ }
123
+ } catch (ex) { console.error(ex) }
124
+ };
125
+
126
+ /**
127
+ * pop up sign in callback
128
+ */
129
+ popupSignInCallback() {
130
+ try {
131
+ if (this.userManager) {
132
+ this.userManager.signinPopupCallback();
133
+ }
134
+ } catch (ex) { console.error(ex) }
135
+ };
136
+
137
+ /**
138
+ * pop up sign out
139
+ */
140
+ popupSignOut() {
141
+ try {
142
+ if (this.userManager && this.webAuthSettings) {
143
+ this.userManager.signoutPopup({
144
+ state: this.webAuthSettings
145
+ }).then(function (resp: any) {
146
+ console.log('signed out', resp);
147
+ });
148
+ } else {
149
+ throw "user manager or settings is null";
150
+ }
151
+ } catch (ex) { console.error(ex) }
152
+
153
+ };
154
+
155
+ /**
156
+ * silent sign in
157
+ */
158
+ silentSignIn() {
159
+ try {
160
+ if (this.userManager && this.webAuthSettings) {
161
+ this.userManager.signinSilent({
162
+ state: this.webAuthSettings
163
+ }).then(function (user: any) {
164
+ console.log("signed in : " + user.access_token);
165
+ });
166
+ } else {
167
+ throw "user manager is null";
168
+ }
169
+ } catch (ex) { console.error(ex) }
170
+ };
171
+
172
+ /**
173
+ * silent sign in callback
174
+ */
175
+ silentSignInCallback() {
176
+ try {
177
+ if (this.userManager) {
178
+ this.userManager.signinSilentCallback();
179
+ } else {
180
+ throw "user manager is null";
181
+ }
182
+ } catch (ex) { console.error(ex) }
183
+ };
184
+
185
+ /**
186
+ * silent sign in callback v2
187
+ * @returns
188
+ */
189
+ silentSignInCallbackV2() {
190
+ return new Promise((resolve, reject) => {
191
+ try {
192
+ if (this.userManager) {
193
+ this.userManager.signinSilentCallback(this.webAuthSettings.silent_redirect_uri)
194
+ .then(function (user: any) {
195
+ if (user) {
196
+ resolve(user);
197
+ return;
198
+ }
199
+ resolve(undefined);
200
+ });
201
+ } else {
202
+ throw "user manager is null";
203
+ }
204
+ } catch (ex) {
205
+ reject(ex);
206
+ }
207
+ });
208
+
209
+ };
210
+
211
+ /**
212
+ * silent sign out callback
213
+ */
214
+ popupSignOutCallback() {
215
+ try {
216
+ if (this.userManager) {
217
+ this.userManager.signoutPopupCallback(this.webAuthSettings.post_logout_redirect_uri, true);
218
+ } else {
219
+ throw "user manager is null";
220
+ }
221
+ } catch (ex) { console.error(ex) }
222
+ };
223
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * all the global variables are declared in this file
3
+ */
4
+
5
+ interface Window {
6
+ webAuthSettings: any;
7
+ usermanager: any;
8
+ localeSettings: string;
9
+ authentication: any;
10
+ }
@@ -0,0 +1,6 @@
1
+ import { Authentication } from "./authentication";
2
+ import { WebAuth } from "./web-auth/WebAuth";
3
+
4
+ const { version: Version } = require('../../package.json');
5
+
6
+ export { WebAuth, Authentication, Version };
@@ -0,0 +1,98 @@
1
+ import { IConsentAcceptEntity } from "./Entities"
2
+ import { Helper } from "./Helper";
3
+
4
+ export namespace ConsentService {
5
+ /**
6
+ * get user consent details
7
+ * @param options
8
+ * @returns
9
+ */
10
+ export function getConsentDetailsV2(options: {
11
+ consent_id: string;
12
+ consent_version_id: string;
13
+ sub: string;
14
+ }) {
15
+ var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/usage/public/info";
16
+ return Helper.createPostPromise(options, _serviceURL, false);
17
+ };
18
+
19
+ /**
20
+ * accept constn v2
21
+ * @param options
22
+ * @returns
23
+ */
24
+ export function acceptConsentV2(options: IConsentAcceptEntity) {
25
+ var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/usage/accept";
26
+ return Helper.createPostPromise(options, _serviceURL, false);
27
+ };
28
+
29
+ /**
30
+ * get scope consent version details
31
+ * @param options
32
+ * @returns
33
+ */
34
+ export function getScopeConsentVersionDetailsV2(options: {
35
+ scopeid: string;
36
+ locale: string;
37
+ access_token: string;
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
+ });
63
+ };
64
+
65
+ /**
66
+ * accept scope Consent
67
+ * @param options
68
+ * @returns
69
+ */
70
+ export function acceptScopeConsent(options: {
71
+ client_id: string;
72
+ sub: string;
73
+ scopes: string[];
74
+ }) {
75
+ var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/consent/scope/accept";
76
+ return Helper.createPostPromise(options, _serviceURL, false);
77
+ };
78
+
79
+ /**
80
+ * accept claim Consent
81
+ * @param options
82
+ * @returns
83
+ */
84
+ export function acceptClaimConsent(options: { client_id: string; sub: string; accepted_claims: string[]; }) {
85
+ var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/consent/claim/accept";
86
+ return Helper.createPostPromise(options, _serviceURL, false);
87
+ };
88
+
89
+ /**
90
+ * revoke claim Consent
91
+ * @param options
92
+ * @returns
93
+ */
94
+ export function revokeClaimConsent(options: { client_id: string; sub: string; revoked_claims: string[]; }) {
95
+ var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/consent/claim/revoke";
96
+ return Helper.createPostPromise(options, _serviceURL, false);
97
+ };
98
+ }