authtara-sdk 1.1.13 → 1.1.14
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/dist/react.js +38 -16
- package/dist/react.mjs +38 -16
- package/package.json +90 -90
package/dist/react.js
CHANGED
|
@@ -42,6 +42,12 @@ module.exports = __toCommonJS(react_exports);
|
|
|
42
42
|
var React = __toESM(require("react"));
|
|
43
43
|
|
|
44
44
|
// src/oauth/popup.ts
|
|
45
|
+
var PopupBlockedError = class extends Error {
|
|
46
|
+
constructor(message = "Popup blocked. Please allow popups for this site.") {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = "PopupBlockedError";
|
|
49
|
+
}
|
|
50
|
+
};
|
|
45
51
|
var OAuthPopup = class {
|
|
46
52
|
constructor(apiUrl) {
|
|
47
53
|
this.popup = null;
|
|
@@ -66,7 +72,14 @@ var OAuthPopup = class {
|
|
|
66
72
|
`width=${width},height=${height},left=${left},top=${top},popup=1,scrollbars=1`
|
|
67
73
|
);
|
|
68
74
|
if (!this.popup) {
|
|
69
|
-
throw new
|
|
75
|
+
throw new PopupBlockedError("Popup blocked. Please allow popups for this site.");
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
if (this.popup.closed === void 0 || this.popup.closed === true) {
|
|
79
|
+
throw new PopupBlockedError("Popup blocked. Please allow popups for this site.");
|
|
80
|
+
}
|
|
81
|
+
} catch (e) {
|
|
82
|
+
throw new PopupBlockedError("Popup blocked. Please allow popups for this site.");
|
|
70
83
|
}
|
|
71
84
|
this.popup.focus();
|
|
72
85
|
return new Promise((resolve, reject) => {
|
|
@@ -180,22 +193,31 @@ function AuthTaraProvider({
|
|
|
180
193
|
scope: "read write"
|
|
181
194
|
});
|
|
182
195
|
const authorizeUrl = `${apiUrl}/api/oauth/authorize?${params.toString()}`;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
try {
|
|
197
|
+
const popup = new OAuthPopup(apiUrl);
|
|
198
|
+
const { code: authCode, state: returnedState } = await popup.open(authorizeUrl);
|
|
199
|
+
const exchangeResponse = await fetch("/api/sso/callback", {
|
|
200
|
+
method: "POST",
|
|
201
|
+
headers: { "Content-Type": "application/json" },
|
|
202
|
+
credentials: "include",
|
|
203
|
+
body: JSON.stringify({
|
|
204
|
+
code: authCode,
|
|
205
|
+
state: returnedState
|
|
206
|
+
})
|
|
207
|
+
});
|
|
208
|
+
if (!exchangeResponse.ok) {
|
|
209
|
+
const error = await exchangeResponse.json();
|
|
210
|
+
throw new Error(error.message || "Token exchange failed");
|
|
211
|
+
}
|
|
212
|
+
await loadSession();
|
|
213
|
+
} catch (error) {
|
|
214
|
+
if (error instanceof PopupBlockedError) {
|
|
215
|
+
console.warn("[AuthTara] Popup blocked, falling back to redirect mode");
|
|
216
|
+
window.location.href = authorizeUrl;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
throw error;
|
|
197
220
|
}
|
|
198
|
-
await loadSession();
|
|
199
221
|
} catch (error) {
|
|
200
222
|
console.error("[AuthTara] Sign in failed:", error);
|
|
201
223
|
throw error;
|
package/dist/react.mjs
CHANGED
|
@@ -6,6 +6,12 @@ import {
|
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
|
|
8
8
|
// src/oauth/popup.ts
|
|
9
|
+
var PopupBlockedError = class extends Error {
|
|
10
|
+
constructor(message = "Popup blocked. Please allow popups for this site.") {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "PopupBlockedError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
9
15
|
var OAuthPopup = class {
|
|
10
16
|
constructor(apiUrl) {
|
|
11
17
|
this.popup = null;
|
|
@@ -30,7 +36,14 @@ var OAuthPopup = class {
|
|
|
30
36
|
`width=${width},height=${height},left=${left},top=${top},popup=1,scrollbars=1`
|
|
31
37
|
);
|
|
32
38
|
if (!this.popup) {
|
|
33
|
-
throw new
|
|
39
|
+
throw new PopupBlockedError("Popup blocked. Please allow popups for this site.");
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
if (this.popup.closed === void 0 || this.popup.closed === true) {
|
|
43
|
+
throw new PopupBlockedError("Popup blocked. Please allow popups for this site.");
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
throw new PopupBlockedError("Popup blocked. Please allow popups for this site.");
|
|
34
47
|
}
|
|
35
48
|
this.popup.focus();
|
|
36
49
|
return new Promise((resolve, reject) => {
|
|
@@ -144,22 +157,31 @@ function AuthTaraProvider({
|
|
|
144
157
|
scope: "read write"
|
|
145
158
|
});
|
|
146
159
|
const authorizeUrl = `${apiUrl}/api/oauth/authorize?${params.toString()}`;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
try {
|
|
161
|
+
const popup = new OAuthPopup(apiUrl);
|
|
162
|
+
const { code: authCode, state: returnedState } = await popup.open(authorizeUrl);
|
|
163
|
+
const exchangeResponse = await fetch("/api/sso/callback", {
|
|
164
|
+
method: "POST",
|
|
165
|
+
headers: { "Content-Type": "application/json" },
|
|
166
|
+
credentials: "include",
|
|
167
|
+
body: JSON.stringify({
|
|
168
|
+
code: authCode,
|
|
169
|
+
state: returnedState
|
|
170
|
+
})
|
|
171
|
+
});
|
|
172
|
+
if (!exchangeResponse.ok) {
|
|
173
|
+
const error = await exchangeResponse.json();
|
|
174
|
+
throw new Error(error.message || "Token exchange failed");
|
|
175
|
+
}
|
|
176
|
+
await loadSession();
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (error instanceof PopupBlockedError) {
|
|
179
|
+
console.warn("[AuthTara] Popup blocked, falling back to redirect mode");
|
|
180
|
+
window.location.href = authorizeUrl;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
161
184
|
}
|
|
162
|
-
await loadSession();
|
|
163
185
|
} catch (error) {
|
|
164
186
|
console.error("[AuthTara] Sign in failed:", error);
|
|
165
187
|
throw error;
|
package/package.json
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "authtara-sdk",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "SDK Client untuk integrasi dengan DigitalSolution Platform - SSO, Billing, dan Metering",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.mjs",
|
|
12
|
-
"require": "./dist/index.js"
|
|
13
|
-
},
|
|
14
|
-
"./react": {
|
|
15
|
-
"types": "./dist/react.d.ts",
|
|
16
|
-
"import": "./dist/react.mjs",
|
|
17
|
-
"require": "./dist/react.js"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"dist",
|
|
22
|
-
"README.md",
|
|
23
|
-
"LICENSE"
|
|
24
|
-
],
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "tsup src/index.ts src/react.ts --format cjs,esm --dts --clean",
|
|
27
|
-
"dev": "tsup src/index.ts src/react.ts --format cjs,esm --dts --watch",
|
|
28
|
-
"test": "vitest",
|
|
29
|
-
"test:run": "vitest run",
|
|
30
|
-
"test:coverage": "vitest run --coverage",
|
|
31
|
-
"typecheck": "tsc --noEmit",
|
|
32
|
-
"prepublishOnly": "bun run build && bun test:run",
|
|
33
|
-
"release": "bun run build && bun test:run && npm version patch",
|
|
34
|
-
"release:minor": "bun run build && bun test:run && npm version minor",
|
|
35
|
-
"release:major": "bun run build && bun test:run && npm version major"
|
|
36
|
-
},
|
|
37
|
-
"keywords": [
|
|
38
|
-
"digitalsolution",
|
|
39
|
-
"authtara",
|
|
40
|
-
"sdk",
|
|
41
|
-
"sso",
|
|
42
|
-
"authentication",
|
|
43
|
-
"billing",
|
|
44
|
-
"metering",
|
|
45
|
-
"oauth",
|
|
46
|
-
"jwt",
|
|
47
|
-
"saas"
|
|
48
|
-
],
|
|
49
|
-
"author": "DigitalSolution Team",
|
|
50
|
-
"license": "MIT",
|
|
51
|
-
"repository": {
|
|
52
|
-
"type": "git",
|
|
53
|
-
"url": "https://github.com/digitalsolution/authtara-sdk.git"
|
|
54
|
-
},
|
|
55
|
-
"bugs": {
|
|
56
|
-
"url": "https://github.com/digitalsolution/authtara-sdk/issues",
|
|
57
|
-
"email": "support@digitalsolution.com"
|
|
58
|
-
},
|
|
59
|
-
"homepage": "https://docs.digitalsolution.com/sdk",
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"jose": "^6.0.11"
|
|
62
|
-
},
|
|
63
|
-
"peerDependencies": {
|
|
64
|
-
"react": "^18.0.0 || ^19.0.0",
|
|
65
|
-
"react-dom": "^18.0.0 || ^19.0.0"
|
|
66
|
-
},
|
|
67
|
-
"peerDependenciesMeta": {
|
|
68
|
-
"react": {
|
|
69
|
-
"optional": true
|
|
70
|
-
},
|
|
71
|
-
"react-dom": {
|
|
72
|
-
"optional": true
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
"devDependencies": {
|
|
76
|
-
"@types/node": "^24.0.0",
|
|
77
|
-
"@types/react": "^19.2.8",
|
|
78
|
-
"@types/react-dom": "^19.2.3",
|
|
79
|
-
"@vitest/coverage-v8": "^4.0.15",
|
|
80
|
-
"tsup": "^8.5.0",
|
|
81
|
-
"typescript": "^5.9.3",
|
|
82
|
-
"vitest": "^4.0.15"
|
|
83
|
-
},
|
|
84
|
-
"engines": {
|
|
85
|
-
"node": ">=18.0.0"
|
|
86
|
-
},
|
|
87
|
-
"publishConfig": {
|
|
88
|
-
"access": "public",
|
|
89
|
-
"registry": "https://registry.npmjs.org/"
|
|
90
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "authtara-sdk",
|
|
3
|
+
"version": "1.1.14",
|
|
4
|
+
"description": "SDK Client untuk integrasi dengan DigitalSolution Platform - SSO, Billing, dan Metering",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./react": {
|
|
15
|
+
"types": "./dist/react.d.ts",
|
|
16
|
+
"import": "./dist/react.mjs",
|
|
17
|
+
"require": "./dist/react.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts src/react.ts --format cjs,esm --dts --clean",
|
|
27
|
+
"dev": "tsup src/index.ts src/react.ts --format cjs,esm --dts --watch",
|
|
28
|
+
"test": "vitest",
|
|
29
|
+
"test:run": "vitest run",
|
|
30
|
+
"test:coverage": "vitest run --coverage",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"prepublishOnly": "bun run build && bun test:run",
|
|
33
|
+
"release": "bun run build && bun test:run && npm version patch",
|
|
34
|
+
"release:minor": "bun run build && bun test:run && npm version minor",
|
|
35
|
+
"release:major": "bun run build && bun test:run && npm version major"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"digitalsolution",
|
|
39
|
+
"authtara",
|
|
40
|
+
"sdk",
|
|
41
|
+
"sso",
|
|
42
|
+
"authentication",
|
|
43
|
+
"billing",
|
|
44
|
+
"metering",
|
|
45
|
+
"oauth",
|
|
46
|
+
"jwt",
|
|
47
|
+
"saas"
|
|
48
|
+
],
|
|
49
|
+
"author": "DigitalSolution Team",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/digitalsolution/authtara-sdk.git"
|
|
54
|
+
},
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/digitalsolution/authtara-sdk/issues",
|
|
57
|
+
"email": "support@digitalsolution.com"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://docs.digitalsolution.com/sdk",
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"jose": "^6.0.11"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
65
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"react": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"react-dom": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@types/node": "^24.0.0",
|
|
77
|
+
"@types/react": "^19.2.8",
|
|
78
|
+
"@types/react-dom": "^19.2.3",
|
|
79
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
80
|
+
"tsup": "^8.5.0",
|
|
81
|
+
"typescript": "^5.9.3",
|
|
82
|
+
"vitest": "^4.0.15"
|
|
83
|
+
},
|
|
84
|
+
"engines": {
|
|
85
|
+
"node": ">=18.0.0"
|
|
86
|
+
},
|
|
87
|
+
"publishConfig": {
|
|
88
|
+
"access": "public",
|
|
89
|
+
"registry": "https://registry.npmjs.org/"
|
|
90
|
+
}
|
|
91
91
|
}
|