@ave-id/embed 0.2.1 → 0.2.3

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 (2) hide show
  1. package/dist/embed.js +47 -0
  2. package/package.json +4 -2
package/dist/embed.js CHANGED
@@ -79,10 +79,15 @@ export function openAveSheet({
79
79
  scope = "openid profile email",
80
80
  issuer = "https://aveid.net",
81
81
  theme = DEFAULT_THEME,
82
+ codeChallenge,
83
+ codeChallengeMethod,
82
84
  onSuccess,
83
85
  onError,
84
86
  onClose,
85
87
  }) {
88
+ let resolved = false;
89
+ let popup = null;
90
+
86
91
  // Create overlay backdrop
87
92
  const overlay = document.createElement("div");
88
93
  overlay.style.cssText = `
@@ -148,6 +153,13 @@ export function openAveSheet({
148
153
  embed: "1",
149
154
  theme,
150
155
  });
156
+
157
+ if (codeChallenge) {
158
+ params.set("code_challenge", codeChallenge);
159
+ }
160
+ if (codeChallengeMethod) {
161
+ params.set("code_challenge_method", codeChallengeMethod);
162
+ }
151
163
 
152
164
  iframe.src = `${issuer}/signin?${params.toString()}`;
153
165
  iframe.style.cssText = `
@@ -186,6 +198,9 @@ export function openAveSheet({
186
198
 
187
199
  // Close function
188
200
  const close = () => {
201
+ if (popup && !popup.closed) {
202
+ popup.close();
203
+ }
189
204
  sheet.style.animation = "aveSheetSlideDown 0.2s ease-in forwards";
190
205
  overlay.style.animation = "aveSheetFadeOut 0.2s ease-in forwards";
191
206
  setTimeout(() => {
@@ -206,17 +221,38 @@ export function openAveSheet({
206
221
  if (event.origin !== issuer) return;
207
222
  const data = event.data || {};
208
223
 
224
+ if (resolved) return;
225
+
226
+ if (data.type === "ave:auth_required") {
227
+ if (!popup || popup.closed) {
228
+ const width = 450;
229
+ const height = 650;
230
+ const left = (window.innerWidth - width) / 2 + window.screenX;
231
+ const top = (window.innerHeight - height) / 2 + window.screenY;
232
+ popup = window.open(
233
+ iframe.src,
234
+ "ave_auth",
235
+ `width=${width},height=${height},left=${left},top=${top},menubar=no,toolbar=no,location=no,status=no`
236
+ );
237
+ }
238
+ popup?.focus?.();
239
+ return;
240
+ }
241
+
209
242
  if (data.type === "ave:success") {
243
+ resolved = true;
210
244
  close();
211
245
  onSuccess?.(data.payload);
212
246
  }
213
247
 
214
248
  if (data.type === "ave:error") {
249
+ resolved = true;
215
250
  close();
216
251
  onError?.(data.payload);
217
252
  }
218
253
 
219
254
  if (data.type === "ave:close") {
255
+ resolved = true;
220
256
  close();
221
257
  }
222
258
  };
@@ -240,6 +276,9 @@ export function openAvePopup({
240
276
  redirectUri,
241
277
  scope = "openid profile email",
242
278
  issuer = "https://aveid.net",
279
+ theme = DEFAULT_THEME,
280
+ codeChallenge,
281
+ codeChallengeMethod,
243
282
  width = 450,
244
283
  height = 650,
245
284
  onSuccess,
@@ -251,7 +290,15 @@ export function openAvePopup({
251
290
  redirect_uri: redirectUri,
252
291
  scope,
253
292
  embed: "1",
293
+ theme,
254
294
  });
295
+
296
+ if (codeChallenge) {
297
+ params.set("code_challenge", codeChallenge);
298
+ }
299
+ if (codeChallengeMethod) {
300
+ params.set("code_challenge_method", codeChallengeMethod);
301
+ }
255
302
 
256
303
  const left = (window.innerWidth - width) / 2 + window.screenX;
257
304
  const top = (window.innerHeight - height) / 2 + window.screenY;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ave-id/embed",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "main": "dist/embed.js",
6
6
  "module": "dist/embed.js",
@@ -10,7 +10,9 @@
10
10
  "default": "./dist/embed.js"
11
11
  }
12
12
  },
13
- "files": ["dist"],
13
+ "files": [
14
+ "dist"
15
+ ],
14
16
  "publishConfig": {
15
17
  "access": "public"
16
18
  },