@qrauth/web-components 0.1.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.
- package/dist/base.d.ts +30 -0
- package/dist/base.js +148 -0
- package/dist/ephemeral.d.ts +61 -0
- package/dist/ephemeral.js +727 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/login.d.ts +60 -0
- package/dist/login.js +769 -0
- package/dist/qrauth-components.esm.js +1177 -0
- package/dist/qrauth-components.esm.js.map +7 -0
- package/dist/qrauth-components.js +1177 -0
- package/dist/qrauth-components.js.map +7 -0
- package/dist/twofa.d.ts +51 -0
- package/dist/twofa.js +625 -0
- package/package.json +50 -0
|
@@ -0,0 +1,1177 @@
|
|
|
1
|
+
/* @qrauth/web-components v0.1.0 — https://qrauth.io */
|
|
2
|
+
"use strict";var QRAuthComponents=(()=>{var v=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var S=(o,a,e)=>a in o?v(o,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[a]=e;var C=(o,a)=>{for(var e in a)v(o,e,{get:a[e],enumerable:!0})},A=(o,a,e,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of k(a))!I.call(o,i)&&i!==e&&v(o,i,{get:()=>a[i],enumerable:!(t=E(a,i))||t.enumerable});return o};var T=o=>A(v({},"__esModule",{value:!0}),o);var n=(o,a,e)=>S(o,typeof a!="symbol"?a+"":a,e);var q={};C(q,{QRAuthElement:()=>p,QRAuthEphemeral:()=>g,QRAuthLogin:()=>u,QRAuthTwoFA:()=>b});var p=class extends HTMLElement{constructor(){super();n(this,"shadow");n(this,"_sseConnection",null);n(this,"_pollInterval",null);this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["tenant","theme","base-url"]}get tenant(){return this.getAttribute("tenant")||""}get theme(){return this.getAttribute("theme")||"light"}get baseUrl(){let e=this.getAttribute("base-url");return e!==null?e:"https://qrauth.io"}connectedCallback(){this.render()}disconnectedCallback(){this.cleanup()}attributeChangedCallback(e,t,i){t!==i&&this.render()}connectSSE(e){this.disconnectSSE(),this._sseConnection=new EventSource(e),this._sseConnection.onerror=()=>{this.disconnectSSE()}}onSSEEvent(e,t){this._sseConnection&&this._sseConnection.addEventListener(e,i=>{let s=i;try{t(JSON.parse(s.data))}catch{}})}disconnectSSE(){this._sseConnection&&(this._sseConnection.close(),this._sseConnection=null)}startPolling(e,t,i,s){this.stopPolling();let r=async()=>{try{let d=await fetch(e,{headers:s});d.ok&&i(await d.json())}catch{}};r(),this._pollInterval=setInterval(r,t)}stopPolling(){this._pollInterval&&(clearInterval(this._pollInterval),this._pollInterval=null)}cleanup(){this.disconnectSSE(),this.stopPolling()}emit(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}async generateCodeVerifier(){let e=new Uint8Array(32);return crypto.getRandomValues(e),this._base64url(e)}async computeCodeChallenge(e){let i=new TextEncoder().encode(e),s=await crypto.subtle.digest("SHA-256",i);return this._base64url(new Uint8Array(s))}_base64url(e){let t=Array.from(e,i=>String.fromCodePoint(i)).join("");return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}getBaseStyles(){return`
|
|
3
|
+
:host {
|
|
4
|
+
display: inline-block;
|
|
5
|
+
font-family: var(--qrauth-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
|
|
6
|
+
--_primary: var(--qrauth-primary, #00a76f);
|
|
7
|
+
--_primary-dark: var(--qrauth-primary-dark, #007a52);
|
|
8
|
+
--_text: var(--qrauth-text, #1a1a2e);
|
|
9
|
+
--_text-muted: var(--qrauth-text-muted, #637381);
|
|
10
|
+
--_bg: var(--qrauth-bg, #ffffff);
|
|
11
|
+
--_surface: var(--qrauth-surface, #f9fafb);
|
|
12
|
+
--_border: var(--qrauth-border, #e0e0e0);
|
|
13
|
+
--_radius: var(--qrauth-radius, 12px);
|
|
14
|
+
--_shadow: var(--qrauth-shadow, 0 24px 48px rgba(0,0,0,0.15));
|
|
15
|
+
--_btn-bg: var(--qrauth-btn-bg, #1b2a4a);
|
|
16
|
+
--_btn-hover: var(--qrauth-btn-hover, #263b66);
|
|
17
|
+
--_success: #00a76f;
|
|
18
|
+
--_error: #ff5630;
|
|
19
|
+
--_warning: #ffab00;
|
|
20
|
+
--_disabled: #919eab;
|
|
21
|
+
}
|
|
22
|
+
:host([theme="dark"]) {
|
|
23
|
+
--_text: var(--qrauth-text, #f0f0f0);
|
|
24
|
+
--_text-muted: var(--qrauth-text-muted, #919eab);
|
|
25
|
+
--_bg: var(--qrauth-bg, #1a1a2e);
|
|
26
|
+
--_surface: var(--qrauth-surface, #242436);
|
|
27
|
+
--_border: var(--qrauth-border, rgba(255,255,255,0.12));
|
|
28
|
+
--_shadow: var(--qrauth-shadow, 0 24px 48px rgba(0,0,0,0.5));
|
|
29
|
+
--_btn-bg: var(--qrauth-btn-bg, #263b66);
|
|
30
|
+
--_btn-hover: var(--qrauth-btn-hover, #2e4578);
|
|
31
|
+
}
|
|
32
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
33
|
+
`}};var m=`<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
34
|
+
<path d="M48 24 H152 Q166 24 166 38 V108 Q166 156 100 182 Q34 156 34 108 V38 Q34 24 48 24 Z"
|
|
35
|
+
fill="none" stroke="#fff" stroke-width="5"/>
|
|
36
|
+
<g fill="#fff" opacity="0.2">
|
|
37
|
+
<rect x="52" y="40" width="18" height="18" rx="3"/>
|
|
38
|
+
<rect x="78" y="40" width="18" height="18" rx="3"/>
|
|
39
|
+
<rect x="130" y="40" width="18" height="18" rx="3"/>
|
|
40
|
+
<rect x="52" y="66" width="18" height="18" rx="3"/>
|
|
41
|
+
<rect x="104" y="66" width="18" height="18" rx="3"/>
|
|
42
|
+
<rect x="78" y="92" width="18" height="18" rx="3"/>
|
|
43
|
+
<rect x="130" y="92" width="18" height="18" rx="3"/>
|
|
44
|
+
<rect x="52" y="118" width="18" height="18" rx="3"/>
|
|
45
|
+
<rect x="104" y="118" width="18" height="18" rx="3"/>
|
|
46
|
+
</g>
|
|
47
|
+
<path d="M62 104 L88 134 L144 64"
|
|
48
|
+
fill="none" stroke="#fff" stroke-width="15"
|
|
49
|
+
stroke-linecap="round" stroke-linejoin="round"/>
|
|
50
|
+
</svg>`,_=`<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
51
|
+
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z" fill="currentColor"/>
|
|
52
|
+
</svg>`,B=`<svg class="spinner" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
53
|
+
<circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2.5"
|
|
54
|
+
stroke-dasharray="31.416" stroke-dashoffset="10" stroke-linecap="round"/>
|
|
55
|
+
</svg>`,u=class extends p{constructor(){super(...arguments);n(this,"_sessionId",null);n(this,"_codeVerifier",null);n(this,"_status","idle");n(this,"_expiresAt",null);n(this,"_timerInterval",null);n(this,"_pollTimeout",null)}static get observedAttributes(){return[...super.observedAttributes,"scopes","redirect-url","on-auth","display","animated"]}get scopes(){return this.getAttribute("scopes")||"identity"}get redirectUrl(){return this.getAttribute("redirect-url")}get onAuth(){return this.getAttribute("on-auth")}get display(){return this.getAttribute("display")||"button"}get animated(){return this.hasAttribute("animated")}disconnectedCallback(){super.disconnectedCallback(),this._clearTimers()}render(){this.display==="inline"?this._renderInline():this._renderButton()}_renderButton(){this.shadow.innerHTML=`
|
|
56
|
+
<style>
|
|
57
|
+
${this.getBaseStyles()}
|
|
58
|
+
:host { display: inline-block; }
|
|
59
|
+
|
|
60
|
+
.btn {
|
|
61
|
+
display: inline-flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
gap: 10px;
|
|
64
|
+
padding: 12px 24px;
|
|
65
|
+
background: var(--_btn-bg);
|
|
66
|
+
color: #fff;
|
|
67
|
+
border: none;
|
|
68
|
+
border-radius: var(--_radius);
|
|
69
|
+
font-size: 15px;
|
|
70
|
+
font-weight: 600;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
|
|
73
|
+
user-select: none;
|
|
74
|
+
line-height: 1.4;
|
|
75
|
+
font-family: inherit;
|
|
76
|
+
}
|
|
77
|
+
.btn:hover:not(:disabled) {
|
|
78
|
+
background: var(--_btn-hover);
|
|
79
|
+
transform: translateY(-1px);
|
|
80
|
+
box-shadow: 0 4px 12px rgba(27,42,74,0.3);
|
|
81
|
+
}
|
|
82
|
+
.btn:active:not(:disabled) { transform: translateY(0); }
|
|
83
|
+
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
84
|
+
.btn-icon { width: 22px; height: 22px; flex-shrink: 0; }
|
|
85
|
+
|
|
86
|
+
/* Modal overlay */
|
|
87
|
+
.overlay {
|
|
88
|
+
position: fixed;
|
|
89
|
+
inset: 0;
|
|
90
|
+
background: rgba(0,0,0,0.55);
|
|
91
|
+
z-index: 99999;
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
justify-content: center;
|
|
95
|
+
animation: fade-in 0.2s ease;
|
|
96
|
+
}
|
|
97
|
+
.overlay.hidden { display: none; }
|
|
98
|
+
|
|
99
|
+
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
|
|
100
|
+
@keyframes slide-up {
|
|
101
|
+
from { transform: translateY(24px); opacity: 0; }
|
|
102
|
+
to { transform: translateY(0); opacity: 1; }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.modal {
|
|
106
|
+
background: var(--_bg);
|
|
107
|
+
border-radius: 16px;
|
|
108
|
+
padding: 32px 28px 24px;
|
|
109
|
+
max-width: 380px;
|
|
110
|
+
width: 90vw;
|
|
111
|
+
box-shadow: var(--_shadow);
|
|
112
|
+
text-align: center;
|
|
113
|
+
animation: slide-up 0.3s ease;
|
|
114
|
+
position: relative;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
${this._sharedModalStyles()}
|
|
118
|
+
</style>
|
|
119
|
+
|
|
120
|
+
<button class="btn" id="open-btn" aria-label="Sign in with QRAuth">
|
|
121
|
+
<span class="btn-icon">${m}</span>
|
|
122
|
+
Sign in with QRAuth
|
|
123
|
+
</button>
|
|
124
|
+
|
|
125
|
+
<div class="overlay hidden" id="overlay" role="dialog" aria-modal="true" aria-label="QRAuth sign-in">
|
|
126
|
+
<div class="modal">
|
|
127
|
+
${this._modalContent()}
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
`,this._bindButtonEvents()}_renderInline(){this.shadow.innerHTML=`
|
|
131
|
+
<style>
|
|
132
|
+
${this.getBaseStyles()}
|
|
133
|
+
:host { display: block; }
|
|
134
|
+
|
|
135
|
+
.inline-container {
|
|
136
|
+
background: var(--_bg);
|
|
137
|
+
border: 1px solid var(--_border);
|
|
138
|
+
border-radius: 16px;
|
|
139
|
+
padding: 28px 24px 20px;
|
|
140
|
+
text-align: center;
|
|
141
|
+
max-width: 360px;
|
|
142
|
+
margin: 0 auto;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* Idle state: show start button */
|
|
146
|
+
.start-btn {
|
|
147
|
+
display: inline-flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
gap: 10px;
|
|
150
|
+
padding: 12px 24px;
|
|
151
|
+
background: var(--_btn-bg);
|
|
152
|
+
color: #fff;
|
|
153
|
+
border: none;
|
|
154
|
+
border-radius: var(--_radius);
|
|
155
|
+
font-size: 15px;
|
|
156
|
+
font-weight: 600;
|
|
157
|
+
cursor: pointer;
|
|
158
|
+
transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
|
|
159
|
+
font-family: inherit;
|
|
160
|
+
width: 100%;
|
|
161
|
+
justify-content: center;
|
|
162
|
+
}
|
|
163
|
+
.start-btn:hover:not(:disabled) {
|
|
164
|
+
background: var(--_btn-hover);
|
|
165
|
+
transform: translateY(-1px);
|
|
166
|
+
}
|
|
167
|
+
.start-btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
168
|
+
.btn-icon { width: 22px; height: 22px; flex-shrink: 0; }
|
|
169
|
+
|
|
170
|
+
${this._sharedModalStyles()}
|
|
171
|
+
</style>
|
|
172
|
+
|
|
173
|
+
<div class="inline-container">
|
|
174
|
+
<div id="inline-body">
|
|
175
|
+
${this._inlineIdleContent()}
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
`,this._bindInlineEvents()}_inlineIdleContent(){return`
|
|
179
|
+
<button class="start-btn" id="start-btn" aria-label="Sign in with QRAuth">
|
|
180
|
+
<span class="btn-icon">${m}</span>
|
|
181
|
+
Sign in with QRAuth
|
|
182
|
+
</button>
|
|
183
|
+
`}_modalContent(){return`
|
|
184
|
+
<button class="close-btn" id="close-btn" aria-label="Close">×</button>
|
|
185
|
+
<div id="modal-body">
|
|
186
|
+
${this._bodyForStatus("idle")}
|
|
187
|
+
</div>
|
|
188
|
+
`}_bodyForStatus(e,t){switch(e){case"idle":return`
|
|
189
|
+
<div class="state-header">
|
|
190
|
+
<div class="brand-icon">${m}</div>
|
|
191
|
+
<h3>Sign in with QRAuth</h3>
|
|
192
|
+
<p>Secure, passwordless authentication</p>
|
|
193
|
+
</div>
|
|
194
|
+
`;case"loading":return`
|
|
195
|
+
<div class="state-loading">
|
|
196
|
+
<div class="spinner-wrap">${B}</div>
|
|
197
|
+
<p class="status-text">Generating QR code...</p>
|
|
198
|
+
</div>
|
|
199
|
+
`;case"pending":case"SCANNED":{let i=t?.qrUrl?`https://api.qrserver.com/v1/create-qr-code/?size=440x440&data=${encodeURIComponent(t.qrUrl)}`:"",s=e==="SCANNED";return`
|
|
200
|
+
<h3>Sign in with QRAuth</h3>
|
|
201
|
+
<p class="subtitle">Scan this QR code with your phone camera</p>
|
|
202
|
+
<div class="qr-frame ${s?"scanned":""}${this.animated?" animated":""}">
|
|
203
|
+
<img src="${i}" alt="QR Code for authentication" width="220" height="220" loading="lazy"/>
|
|
204
|
+
<div class="qr-badge">${m}</div>
|
|
205
|
+
${s?'<div class="scanned-overlay"><span class="scanned-check">'+_+"</span></div>":""}
|
|
206
|
+
</div>
|
|
207
|
+
<div class="status-text ${s?"status-scanned":""}">
|
|
208
|
+
${s?"✓ QR code scanned — waiting for approval...":"Waiting for scan..."}
|
|
209
|
+
</div>
|
|
210
|
+
<div class="timer" id="timer">${t?.timerHtml??""}</div>
|
|
211
|
+
<div class="footer">Secured by <a href="https://qrauth.io" target="_blank" rel="noopener">QRAuth</a></div>
|
|
212
|
+
`}case"APPROVED":return`
|
|
213
|
+
<div class="state-approved">
|
|
214
|
+
<div class="success-icon">${_}</div>
|
|
215
|
+
<h3>Identity verified!</h3>
|
|
216
|
+
<p class="subtitle">You are now signed in</p>
|
|
217
|
+
</div>
|
|
218
|
+
`;case"DENIED":return`
|
|
219
|
+
<div class="state-denied">
|
|
220
|
+
<div class="error-icon">✗</div>
|
|
221
|
+
<h3>Authentication denied</h3>
|
|
222
|
+
<p class="subtitle">The request was declined on your device.</p>
|
|
223
|
+
<button class="retry-btn" id="retry-btn">Try again</button>
|
|
224
|
+
</div>
|
|
225
|
+
`;case"EXPIRED":return`
|
|
226
|
+
<div class="state-expired">
|
|
227
|
+
<div class="expired-icon">⌛</div>
|
|
228
|
+
<h3>Session expired</h3>
|
|
229
|
+
<p class="subtitle">The QR code has timed out.</p>
|
|
230
|
+
<button class="retry-btn" id="retry-btn">Try again</button>
|
|
231
|
+
</div>
|
|
232
|
+
`;case"error":return`
|
|
233
|
+
<div class="state-error">
|
|
234
|
+
<div class="error-icon">⚠</div>
|
|
235
|
+
<h3>Something went wrong</h3>
|
|
236
|
+
<p class="subtitle">${t?.errorMessage??"Failed to start authentication."}</p>
|
|
237
|
+
<button class="retry-btn" id="retry-btn">Try again</button>
|
|
238
|
+
</div>
|
|
239
|
+
`;default:return""}}_sharedModalStyles(){return`
|
|
240
|
+
/* Typography */
|
|
241
|
+
h3 {
|
|
242
|
+
font-size: 18px;
|
|
243
|
+
font-weight: 700;
|
|
244
|
+
color: var(--_text);
|
|
245
|
+
margin: 0 0 6px;
|
|
246
|
+
}
|
|
247
|
+
.subtitle {
|
|
248
|
+
font-size: 13px;
|
|
249
|
+
color: var(--_text-muted);
|
|
250
|
+
margin: 0 0 20px;
|
|
251
|
+
line-height: 1.5;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/* Close button */
|
|
255
|
+
.close-btn {
|
|
256
|
+
position: absolute;
|
|
257
|
+
top: 12px;
|
|
258
|
+
right: 14px;
|
|
259
|
+
background: none;
|
|
260
|
+
border: none;
|
|
261
|
+
cursor: pointer;
|
|
262
|
+
color: var(--_text-muted);
|
|
263
|
+
font-size: 22px;
|
|
264
|
+
line-height: 1;
|
|
265
|
+
padding: 4px 6px;
|
|
266
|
+
border-radius: 6px;
|
|
267
|
+
transition: color 0.15s, background 0.15s;
|
|
268
|
+
font-family: inherit;
|
|
269
|
+
}
|
|
270
|
+
.close-btn:hover { color: var(--_text); background: var(--_surface); }
|
|
271
|
+
|
|
272
|
+
/* Brand icon in idle state */
|
|
273
|
+
.state-header { padding: 8px 0 4px; }
|
|
274
|
+
.brand-icon {
|
|
275
|
+
width: 56px;
|
|
276
|
+
height: 56px;
|
|
277
|
+
background: var(--_btn-bg);
|
|
278
|
+
border-radius: 14px;
|
|
279
|
+
display: inline-flex;
|
|
280
|
+
align-items: center;
|
|
281
|
+
justify-content: center;
|
|
282
|
+
margin-bottom: 14px;
|
|
283
|
+
padding: 10px;
|
|
284
|
+
}
|
|
285
|
+
.brand-icon svg { width: 36px; height: 36px; }
|
|
286
|
+
|
|
287
|
+
/* Loading state */
|
|
288
|
+
.state-loading {
|
|
289
|
+
padding: 32px 0;
|
|
290
|
+
display: flex;
|
|
291
|
+
flex-direction: column;
|
|
292
|
+
align-items: center;
|
|
293
|
+
gap: 16px;
|
|
294
|
+
}
|
|
295
|
+
.spinner-wrap { color: var(--_primary); }
|
|
296
|
+
.spinner {
|
|
297
|
+
width: 40px;
|
|
298
|
+
height: 40px;
|
|
299
|
+
animation: spin 0.8s linear infinite;
|
|
300
|
+
}
|
|
301
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
302
|
+
|
|
303
|
+
/* QR frame */
|
|
304
|
+
.qr-frame {
|
|
305
|
+
display: inline-block;
|
|
306
|
+
padding: 14px;
|
|
307
|
+
background: #fff;
|
|
308
|
+
border: 2px solid var(--_border);
|
|
309
|
+
border-radius: var(--_radius);
|
|
310
|
+
margin-bottom: 14px;
|
|
311
|
+
position: relative;
|
|
312
|
+
transition: border-color 0.3s;
|
|
313
|
+
}
|
|
314
|
+
.qr-frame.scanned { border-color: var(--_success); }
|
|
315
|
+
.qr-frame.animated { animation: qr-pulse 2s ease-in-out infinite; }
|
|
316
|
+
@keyframes qr-pulse {
|
|
317
|
+
0%, 100% { box-shadow: 0 0 0 0 rgba(0,167,111,0); }
|
|
318
|
+
50% { box-shadow: 0 0 0 8px rgba(0,167,111,0.15); }
|
|
319
|
+
}
|
|
320
|
+
.qr-frame img { display: block; width: 220px; height: 220px; border-radius: 4px; }
|
|
321
|
+
.qr-badge {
|
|
322
|
+
position: absolute;
|
|
323
|
+
top: 50%;
|
|
324
|
+
left: 50%;
|
|
325
|
+
transform: translate(-50%, -50%);
|
|
326
|
+
width: 52px;
|
|
327
|
+
height: 52px;
|
|
328
|
+
background: #1b2a4a;
|
|
329
|
+
border-radius: 10px;
|
|
330
|
+
padding: 6px;
|
|
331
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
|
|
332
|
+
display: flex;
|
|
333
|
+
align-items: center;
|
|
334
|
+
justify-content: center;
|
|
335
|
+
}
|
|
336
|
+
.qr-badge svg { width: 100%; height: 100%; }
|
|
337
|
+
|
|
338
|
+
/* Scanned overlay on QR */
|
|
339
|
+
.scanned-overlay {
|
|
340
|
+
position: absolute;
|
|
341
|
+
inset: 0;
|
|
342
|
+
background: rgba(0,167,111,0.08);
|
|
343
|
+
border-radius: calc(var(--_radius) - 2px);
|
|
344
|
+
display: flex;
|
|
345
|
+
align-items: center;
|
|
346
|
+
justify-content: center;
|
|
347
|
+
}
|
|
348
|
+
.scanned-check {
|
|
349
|
+
width: 48px;
|
|
350
|
+
height: 48px;
|
|
351
|
+
background: var(--_success);
|
|
352
|
+
border-radius: 50%;
|
|
353
|
+
display: flex;
|
|
354
|
+
align-items: center;
|
|
355
|
+
justify-content: center;
|
|
356
|
+
color: #fff;
|
|
357
|
+
opacity: 0;
|
|
358
|
+
animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.1s forwards;
|
|
359
|
+
}
|
|
360
|
+
.scanned-check svg { width: 28px; height: 28px; }
|
|
361
|
+
@keyframes pop-in {
|
|
362
|
+
from { transform: scale(0.5); opacity: 0; }
|
|
363
|
+
to { transform: scale(1); opacity: 1; }
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/* Status text */
|
|
367
|
+
.status-text {
|
|
368
|
+
font-size: 13px;
|
|
369
|
+
color: var(--_text-muted);
|
|
370
|
+
min-height: 20px;
|
|
371
|
+
}
|
|
372
|
+
.status-scanned {
|
|
373
|
+
color: var(--_success);
|
|
374
|
+
font-weight: 600;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/* Timer */
|
|
378
|
+
.timer {
|
|
379
|
+
font-size: 12px;
|
|
380
|
+
color: var(--_disabled);
|
|
381
|
+
margin-top: 8px;
|
|
382
|
+
font-variant-numeric: tabular-nums;
|
|
383
|
+
min-height: 18px;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/* Success state */
|
|
387
|
+
.state-approved {
|
|
388
|
+
padding: 24px 0 12px;
|
|
389
|
+
animation: fade-scale-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
|
390
|
+
}
|
|
391
|
+
@keyframes fade-scale-in {
|
|
392
|
+
from { transform: scale(0.85); opacity: 0; }
|
|
393
|
+
to { transform: scale(1); opacity: 1; }
|
|
394
|
+
}
|
|
395
|
+
.success-icon {
|
|
396
|
+
width: 64px;
|
|
397
|
+
height: 64px;
|
|
398
|
+
background: var(--_success);
|
|
399
|
+
border-radius: 50%;
|
|
400
|
+
display: inline-flex;
|
|
401
|
+
align-items: center;
|
|
402
|
+
justify-content: center;
|
|
403
|
+
color: #fff;
|
|
404
|
+
margin-bottom: 16px;
|
|
405
|
+
}
|
|
406
|
+
.success-icon svg { width: 36px; height: 36px; }
|
|
407
|
+
|
|
408
|
+
/* Denied / expired / error states */
|
|
409
|
+
.state-denied, .state-expired, .state-error {
|
|
410
|
+
padding: 20px 0 8px;
|
|
411
|
+
}
|
|
412
|
+
.error-icon, .expired-icon {
|
|
413
|
+
font-size: 48px;
|
|
414
|
+
margin-bottom: 12px;
|
|
415
|
+
line-height: 1;
|
|
416
|
+
display: block;
|
|
417
|
+
}
|
|
418
|
+
.state-denied .error-icon { color: var(--_error); }
|
|
419
|
+
.state-expired .expired-icon { color: var(--_disabled); }
|
|
420
|
+
.state-error .error-icon { color: var(--_warning); }
|
|
421
|
+
|
|
422
|
+
/* Retry button */
|
|
423
|
+
.retry-btn {
|
|
424
|
+
margin-top: 14px;
|
|
425
|
+
padding: 9px 22px;
|
|
426
|
+
background: var(--_surface);
|
|
427
|
+
border: 1px solid var(--_border);
|
|
428
|
+
border-radius: 8px;
|
|
429
|
+
font-size: 13px;
|
|
430
|
+
font-weight: 500;
|
|
431
|
+
cursor: pointer;
|
|
432
|
+
color: var(--_text-muted);
|
|
433
|
+
font-family: inherit;
|
|
434
|
+
transition: background 0.15s, border-color 0.15s;
|
|
435
|
+
}
|
|
436
|
+
.retry-btn:hover { background: var(--_border); color: var(--_text); }
|
|
437
|
+
|
|
438
|
+
/* Footer */
|
|
439
|
+
.footer {
|
|
440
|
+
margin-top: 18px;
|
|
441
|
+
font-size: 10px;
|
|
442
|
+
color: #c4cdd5;
|
|
443
|
+
}
|
|
444
|
+
.footer a { color: var(--_disabled); text-decoration: none; }
|
|
445
|
+
.footer a:hover { text-decoration: underline; }
|
|
446
|
+
`}_bindButtonEvents(){this.shadow.getElementById("open-btn")?.addEventListener("click",()=>{this._openModal(),this._startAuth()});let t=this.shadow.getElementById("overlay");t?.addEventListener("click",i=>{i.target===t&&this._closeModal()}),this._bindModalButtons()}_bindInlineEvents(){this.shadow.getElementById("start-btn")?.addEventListener("click",()=>{this._startAuth()})}_bindModalButtons(){this.shadow.getElementById("close-btn")?.addEventListener("click",()=>this._closeModal()),this.shadow.getElementById("retry-btn")?.addEventListener("click",()=>this._retry())}_openModal(){this.shadow.getElementById("overlay")?.classList.remove("hidden"),this._updateBody(this._bodyForStatus("idle"))}_closeModal(){this.shadow.getElementById("overlay")?.classList.add("hidden"),this._clearTimers(),this._sessionId=null,this._codeVerifier=null,this._status="idle",this._expiresAt=null}async _startAuth(){this._status="loading",this._updateBody(this._bodyForStatus("loading"));try{this._codeVerifier=await this.generateCodeVerifier();let e=await this.computeCodeChallenge(this._codeVerifier),t={"Content-Type":"application/json","X-Client-Id":this.tenant},i={scopes:this.scopes.split(/\s+/).filter(Boolean),codeChallenge:e,codeChallengeMethod:"S256"},s=await fetch(`${this.baseUrl}/api/v1/auth-sessions`,{method:"POST",headers:t,body:JSON.stringify(i)});if(!s.ok){let d=await s.json().catch(()=>({message:"Failed to create session"}));throw new Error(d.message??"Failed to create session")}let r=await s.json();this._sessionId=r.sessionId,this._expiresAt=new Date(r.expiresAt).getTime(),this._status="pending",this._updateBody(this._bodyForStatus("pending",{qrUrl:r.qrUrl})),this._bindModalButtons(),this._startCountdown(),this._beginPolling(r.sessionId)}catch(e){let t=e instanceof Error?e.message:"Unexpected error";this._status="error",this._updateBody(this._bodyForStatus("error",{errorMessage:t})),this._bindModalButtons(),this.emit("qrauth:error",{message:t})}}_retry(){if(this._clearTimers(),this._sessionId=null,this._codeVerifier=null,this._status="idle",this._expiresAt=null,this.display==="inline"){let e=this.shadow.getElementById("inline-body");e&&(e.innerHTML=this._inlineIdleContent(),this._bindInlineEvents())}else this._startAuth()}_beginPolling(e){let t="PENDING",i=2e3,s=5e3,r=0,d=20,h=async()=>{if(!this._sessionId)return;let l=`${this.baseUrl}/api/v1/auth-sessions/${e}`;this._codeVerifier&&(l+=`?code_verifier=${encodeURIComponent(this._codeVerifier)}`);try{let c=await(await fetch(l,{headers:{"X-Client-Id":this.tenant}})).json();if(r=0,i=2e3,c.status!==t&&(t=c.status,this._handleStatusChange(c.status,c),["APPROVED","DENIED","EXPIRED"].includes(c.status)))return;this._pollTimeout=setTimeout(h,i)}catch{if(r++,r>=d){this._handleStatusChange("EXPIRED",void 0);return}i=Math.min(i*1.5,s),this._pollTimeout=setTimeout(h,i)}};this._pollTimeout=setTimeout(h,i)}_handleStatusChange(e,t){switch(this._status=e,e){case"SCANNED":{let i=this.shadow.querySelector(".qr-frame img")?.src,s=i?decodeURIComponent(i.replace(/.*[?&]data=/,"").split("&")[0]):"";this._updateBody(this._bodyForStatus("SCANNED",{qrUrl:s,timerHtml:this._formatTimer()})),this._bindModalButtons(),this.emit("qrauth:scanned",t);break}case"APPROVED":{this._clearTimers(),this._updateBody(this._bodyForStatus("APPROVED")),this._bindModalButtons(),this.emit("qrauth:authenticated",{sessionId:t?.sessionId,user:t?.user,signature:t?.signature});let i=this.onAuth;if(i){let s=window[i];typeof s=="function"&&s(t)}this.redirectUrl?setTimeout(()=>{window.location.href=this.redirectUrl},1500):this.display==="button"&&setTimeout(()=>this._closeModal(),2200);break}case"DENIED":this._clearTimers(),this._updateBody(this._bodyForStatus("DENIED")),this._bindModalButtons(),this.emit("qrauth:denied");break;case"EXPIRED":this._clearTimers(),this._status="EXPIRED",this._updateBody(this._bodyForStatus("EXPIRED")),this._bindModalButtons(),this.emit("qrauth:expired");break}}_startCountdown(){this._timerInterval=setInterval(()=>{let e=this.shadow.getElementById("timer");if(!e||!this._expiresAt)return;let t=Math.max(0,Math.floor((this._expiresAt-Date.now())/1e3));e.textContent=t>0?this._formatTimer(t):"",t<=0&&(clearInterval(this._timerInterval),this._timerInterval=null,(this._status==="pending"||this._status==="SCANNED")&&this._handleStatusChange("EXPIRED",void 0))},1e3)}_formatTimer(e){let t=e??(this._expiresAt?Math.max(0,Math.floor((this._expiresAt-Date.now())/1e3)):0),i=Math.floor(t/60),s=t%60;return`Expires in ${i}:${s<10?"0":""}${s}`}_updateBody(e){let t=this.display==="inline"?this.shadow.getElementById("inline-body"):this.shadow.getElementById("modal-body");t&&(t.innerHTML=e)}_clearTimers(){this._timerInterval&&(clearInterval(this._timerInterval),this._timerInterval=null),this._pollTimeout&&(clearTimeout(this._pollTimeout),this._pollTimeout=null)}};customElements.define("qrauth-login",u);var x=`<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
447
|
+
<path d="M48 24 H152 Q166 24 166 38 V108 Q166 156 100 182 Q34 156 34 108 V38 Q34 24 48 24 Z"
|
|
448
|
+
fill="none" stroke="#fff" stroke-width="5"/>
|
|
449
|
+
<g fill="#fff" opacity="0.2">
|
|
450
|
+
<rect x="52" y="40" width="18" height="18" rx="3"/>
|
|
451
|
+
<rect x="78" y="40" width="18" height="18" rx="3"/>
|
|
452
|
+
<rect x="130" y="40" width="18" height="18" rx="3"/>
|
|
453
|
+
<rect x="52" y="66" width="18" height="18" rx="3"/>
|
|
454
|
+
<rect x="104" y="66" width="18" height="18" rx="3"/>
|
|
455
|
+
<rect x="78" y="92" width="18" height="18" rx="3"/>
|
|
456
|
+
<rect x="130" y="92" width="18" height="18" rx="3"/>
|
|
457
|
+
<rect x="52" y="118" width="18" height="18" rx="3"/>
|
|
458
|
+
<rect x="104" y="118" width="18" height="18" rx="3"/>
|
|
459
|
+
</g>
|
|
460
|
+
<path d="M62 104 L88 134 L144 64"
|
|
461
|
+
fill="none" stroke="#fff" stroke-width="15"
|
|
462
|
+
stroke-linecap="round" stroke-linejoin="round"/>
|
|
463
|
+
</svg>`,R=`<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
464
|
+
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z" fill="currentColor"/>
|
|
465
|
+
</svg>`,M=`<svg class="spinner" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
466
|
+
<circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2.5"
|
|
467
|
+
stroke-dasharray="31.416" stroke-dashoffset="10" stroke-linecap="round"/>
|
|
468
|
+
</svg>`,g=class extends p{constructor(){super(...arguments);n(this,"_sessionId",null);n(this,"_claimUrl",null);n(this,"_status","idle");n(this,"_expiresAt",null);n(this,"_timerInterval",null);n(this,"_pollTimeout",null)}static get observedAttributes(){return[...super.observedAttributes,"scopes","ttl","max-uses","device-binding","display"]}get scopes(){return this.getAttribute("scopes")||"access"}get ttl(){return this.getAttribute("ttl")||"30m"}get maxUses(){return parseInt(this.getAttribute("max-uses")||"1",10)}get deviceBinding(){return this.hasAttribute("device-binding")}get display(){return this.getAttribute("display")||"inline"}disconnectedCallback(){super.disconnectedCallback(),this._clearTimers()}render(){this.display==="button"?this._renderButton():this._renderInline()}_renderButton(){this.shadow.innerHTML=`
|
|
469
|
+
<style>
|
|
470
|
+
${this.getBaseStyles()}
|
|
471
|
+
:host { display: inline-block; }
|
|
472
|
+
|
|
473
|
+
.btn {
|
|
474
|
+
display: inline-flex;
|
|
475
|
+
align-items: center;
|
|
476
|
+
gap: 10px;
|
|
477
|
+
padding: 12px 24px;
|
|
478
|
+
background: var(--_btn-bg);
|
|
479
|
+
color: #fff;
|
|
480
|
+
border: none;
|
|
481
|
+
border-radius: var(--_radius);
|
|
482
|
+
font-size: 15px;
|
|
483
|
+
font-weight: 600;
|
|
484
|
+
cursor: pointer;
|
|
485
|
+
transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
|
|
486
|
+
user-select: none;
|
|
487
|
+
line-height: 1.4;
|
|
488
|
+
font-family: inherit;
|
|
489
|
+
}
|
|
490
|
+
.btn:hover:not(:disabled) {
|
|
491
|
+
background: var(--_btn-hover);
|
|
492
|
+
transform: translateY(-1px);
|
|
493
|
+
box-shadow: 0 4px 12px rgba(27,42,74,0.3);
|
|
494
|
+
}
|
|
495
|
+
.btn:active:not(:disabled) { transform: translateY(0); }
|
|
496
|
+
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
497
|
+
.btn-icon { width: 22px; height: 22px; flex-shrink: 0; }
|
|
498
|
+
|
|
499
|
+
/* Modal overlay */
|
|
500
|
+
.overlay {
|
|
501
|
+
position: fixed;
|
|
502
|
+
inset: 0;
|
|
503
|
+
background: rgba(0,0,0,0.55);
|
|
504
|
+
z-index: 99999;
|
|
505
|
+
display: flex;
|
|
506
|
+
align-items: center;
|
|
507
|
+
justify-content: center;
|
|
508
|
+
animation: fade-in 0.2s ease;
|
|
509
|
+
}
|
|
510
|
+
.overlay.hidden { display: none; }
|
|
511
|
+
|
|
512
|
+
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
|
|
513
|
+
@keyframes slide-up {
|
|
514
|
+
from { transform: translateY(24px); opacity: 0; }
|
|
515
|
+
to { transform: translateY(0); opacity: 1; }
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
.modal {
|
|
519
|
+
background: var(--_bg);
|
|
520
|
+
border-radius: 16px;
|
|
521
|
+
padding: 32px 28px 24px;
|
|
522
|
+
max-width: 380px;
|
|
523
|
+
width: 90vw;
|
|
524
|
+
box-shadow: var(--_shadow);
|
|
525
|
+
text-align: center;
|
|
526
|
+
animation: slide-up 0.3s ease;
|
|
527
|
+
position: relative;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
${this._sharedModalStyles()}
|
|
531
|
+
</style>
|
|
532
|
+
|
|
533
|
+
<button class="btn" id="open-btn" aria-label="Get access QR code">
|
|
534
|
+
<span class="btn-icon">${x}</span>
|
|
535
|
+
Get Access QR
|
|
536
|
+
</button>
|
|
537
|
+
|
|
538
|
+
<div class="overlay hidden" id="overlay" role="dialog" aria-modal="true" aria-label="QRAuth ephemeral access">
|
|
539
|
+
<div class="modal">
|
|
540
|
+
${this._modalContent()}
|
|
541
|
+
</div>
|
|
542
|
+
</div>
|
|
543
|
+
`,this._bindButtonEvents()}_renderInline(){this.shadow.innerHTML=`
|
|
544
|
+
<style>
|
|
545
|
+
${this.getBaseStyles()}
|
|
546
|
+
:host { display: block; }
|
|
547
|
+
|
|
548
|
+
.inline-container {
|
|
549
|
+
background: var(--_bg);
|
|
550
|
+
border: 1px solid var(--_border);
|
|
551
|
+
border-radius: 16px;
|
|
552
|
+
padding: 28px 24px 20px;
|
|
553
|
+
text-align: center;
|
|
554
|
+
max-width: 360px;
|
|
555
|
+
margin: 0 auto;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/* Idle state: show start button */
|
|
559
|
+
.start-btn {
|
|
560
|
+
display: inline-flex;
|
|
561
|
+
align-items: center;
|
|
562
|
+
gap: 10px;
|
|
563
|
+
padding: 12px 24px;
|
|
564
|
+
background: var(--_btn-bg);
|
|
565
|
+
color: #fff;
|
|
566
|
+
border: none;
|
|
567
|
+
border-radius: var(--_radius);
|
|
568
|
+
font-size: 15px;
|
|
569
|
+
font-weight: 600;
|
|
570
|
+
cursor: pointer;
|
|
571
|
+
transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
|
|
572
|
+
font-family: inherit;
|
|
573
|
+
width: 100%;
|
|
574
|
+
justify-content: center;
|
|
575
|
+
}
|
|
576
|
+
.start-btn:hover:not(:disabled) {
|
|
577
|
+
background: var(--_btn-hover);
|
|
578
|
+
transform: translateY(-1px);
|
|
579
|
+
}
|
|
580
|
+
.start-btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
581
|
+
.btn-icon { width: 22px; height: 22px; flex-shrink: 0; }
|
|
582
|
+
|
|
583
|
+
${this._sharedModalStyles()}
|
|
584
|
+
</style>
|
|
585
|
+
|
|
586
|
+
<div class="inline-container">
|
|
587
|
+
<div id="inline-body">
|
|
588
|
+
${this._inlineIdleContent()}
|
|
589
|
+
</div>
|
|
590
|
+
</div>
|
|
591
|
+
`,this._bindInlineEvents()}_inlineIdleContent(){return`
|
|
592
|
+
<button class="start-btn" id="start-btn" aria-label="Get access QR code">
|
|
593
|
+
<span class="btn-icon">${x}</span>
|
|
594
|
+
Get Access QR
|
|
595
|
+
</button>
|
|
596
|
+
`}_modalContent(){return`
|
|
597
|
+
<button class="close-btn" id="close-btn" aria-label="Close">×</button>
|
|
598
|
+
<div id="modal-body">
|
|
599
|
+
${this._bodyForStatus("idle")}
|
|
600
|
+
</div>
|
|
601
|
+
`}_bodyForStatus(e,t){switch(e){case"idle":return`
|
|
602
|
+
<div class="state-header">
|
|
603
|
+
<div class="brand-icon">${x}</div>
|
|
604
|
+
<h3>Ephemeral Access</h3>
|
|
605
|
+
<p>Scan to claim temporary access</p>
|
|
606
|
+
</div>
|
|
607
|
+
`;case"loading":return`
|
|
608
|
+
<div class="state-loading">
|
|
609
|
+
<div class="spinner-wrap">${M}</div>
|
|
610
|
+
<p class="status-text">Generating access QR...</p>
|
|
611
|
+
</div>
|
|
612
|
+
`;case"active":{let i=t?.claimUrl?`https://api.qrserver.com/v1/create-qr-code/?size=440x440&data=${encodeURIComponent(t.claimUrl)}`:"",s=t?.useCount??0,r=t?.maxUses??1,h=r>1?`<div class="use-badge">${s}/${r} claimed</div>`:"";return`
|
|
613
|
+
<h3>Scan to Access</h3>
|
|
614
|
+
<p class="subtitle">Present this QR code to gain entry</p>
|
|
615
|
+
<div class="qr-frame">
|
|
616
|
+
<img src="${i}" alt="Ephemeral access QR code" width="220" height="220" loading="lazy"/>
|
|
617
|
+
<div class="qr-badge">${x}</div>
|
|
618
|
+
</div>
|
|
619
|
+
${h}
|
|
620
|
+
<div class="timer" id="timer">${t?.timerHtml??""}</div>
|
|
621
|
+
<div class="footer">Secured by <a href="https://qrauth.io" target="_blank" rel="noopener">QRAuth</a></div>
|
|
622
|
+
`}case"CLAIMED":return`
|
|
623
|
+
<div class="state-claimed">
|
|
624
|
+
<div class="success-icon">${R}</div>
|
|
625
|
+
<h3>Access granted!</h3>
|
|
626
|
+
<p class="subtitle">The QR code has been claimed successfully</p>
|
|
627
|
+
</div>
|
|
628
|
+
`;case"EXPIRED":return`
|
|
629
|
+
<div class="state-expired">
|
|
630
|
+
<div class="expired-icon">⌛</div>
|
|
631
|
+
<h3>Access expired</h3>
|
|
632
|
+
<p class="subtitle">This QR code has timed out.</p>
|
|
633
|
+
<button class="retry-btn" id="retry-btn">Generate new QR</button>
|
|
634
|
+
</div>
|
|
635
|
+
`;case"REVOKED":return`
|
|
636
|
+
<div class="state-revoked">
|
|
637
|
+
<div class="error-icon">🚫</div>
|
|
638
|
+
<h3>Access revoked</h3>
|
|
639
|
+
<p class="subtitle">This ephemeral session has been revoked.</p>
|
|
640
|
+
</div>
|
|
641
|
+
`;case"error":return`
|
|
642
|
+
<div class="state-error">
|
|
643
|
+
<div class="error-icon">⚠</div>
|
|
644
|
+
<h3>Something went wrong</h3>
|
|
645
|
+
<p class="subtitle">${t?.errorMessage??"Failed to create ephemeral session."}</p>
|
|
646
|
+
<button class="retry-btn" id="retry-btn">Try again</button>
|
|
647
|
+
</div>
|
|
648
|
+
`;default:return""}}_sharedModalStyles(){return`
|
|
649
|
+
/* Typography */
|
|
650
|
+
h3 {
|
|
651
|
+
font-size: 18px;
|
|
652
|
+
font-weight: 700;
|
|
653
|
+
color: var(--_text);
|
|
654
|
+
margin: 0 0 6px;
|
|
655
|
+
}
|
|
656
|
+
.subtitle {
|
|
657
|
+
font-size: 13px;
|
|
658
|
+
color: var(--_text-muted);
|
|
659
|
+
margin: 0 0 20px;
|
|
660
|
+
line-height: 1.5;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/* Close button */
|
|
664
|
+
.close-btn {
|
|
665
|
+
position: absolute;
|
|
666
|
+
top: 12px;
|
|
667
|
+
right: 14px;
|
|
668
|
+
background: none;
|
|
669
|
+
border: none;
|
|
670
|
+
cursor: pointer;
|
|
671
|
+
color: var(--_text-muted);
|
|
672
|
+
font-size: 22px;
|
|
673
|
+
line-height: 1;
|
|
674
|
+
padding: 4px 6px;
|
|
675
|
+
border-radius: 6px;
|
|
676
|
+
transition: color 0.15s, background 0.15s;
|
|
677
|
+
font-family: inherit;
|
|
678
|
+
}
|
|
679
|
+
.close-btn:hover { color: var(--_text); background: var(--_surface); }
|
|
680
|
+
|
|
681
|
+
/* Brand icon in idle state */
|
|
682
|
+
.state-header { padding: 8px 0 4px; }
|
|
683
|
+
.brand-icon {
|
|
684
|
+
width: 56px;
|
|
685
|
+
height: 56px;
|
|
686
|
+
background: var(--_btn-bg);
|
|
687
|
+
border-radius: 14px;
|
|
688
|
+
display: inline-flex;
|
|
689
|
+
align-items: center;
|
|
690
|
+
justify-content: center;
|
|
691
|
+
margin-bottom: 14px;
|
|
692
|
+
padding: 10px;
|
|
693
|
+
}
|
|
694
|
+
.brand-icon svg { width: 36px; height: 36px; }
|
|
695
|
+
|
|
696
|
+
/* Loading state */
|
|
697
|
+
.state-loading {
|
|
698
|
+
padding: 32px 0;
|
|
699
|
+
display: flex;
|
|
700
|
+
flex-direction: column;
|
|
701
|
+
align-items: center;
|
|
702
|
+
gap: 16px;
|
|
703
|
+
}
|
|
704
|
+
.spinner-wrap { color: var(--_primary); }
|
|
705
|
+
.spinner {
|
|
706
|
+
width: 40px;
|
|
707
|
+
height: 40px;
|
|
708
|
+
animation: spin 0.8s linear infinite;
|
|
709
|
+
}
|
|
710
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
711
|
+
|
|
712
|
+
/* QR frame */
|
|
713
|
+
.qr-frame {
|
|
714
|
+
display: inline-block;
|
|
715
|
+
padding: 14px;
|
|
716
|
+
background: #fff;
|
|
717
|
+
border: 2px solid var(--_border);
|
|
718
|
+
border-radius: var(--_radius);
|
|
719
|
+
margin-bottom: 14px;
|
|
720
|
+
position: relative;
|
|
721
|
+
transition: border-color 0.3s;
|
|
722
|
+
}
|
|
723
|
+
.qr-frame img { display: block; width: 220px; height: 220px; border-radius: 4px; }
|
|
724
|
+
.qr-badge {
|
|
725
|
+
position: absolute;
|
|
726
|
+
top: 50%;
|
|
727
|
+
left: 50%;
|
|
728
|
+
transform: translate(-50%, -50%);
|
|
729
|
+
width: 52px;
|
|
730
|
+
height: 52px;
|
|
731
|
+
background: #1b2a4a;
|
|
732
|
+
border-radius: 10px;
|
|
733
|
+
padding: 6px;
|
|
734
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
|
|
735
|
+
display: flex;
|
|
736
|
+
align-items: center;
|
|
737
|
+
justify-content: center;
|
|
738
|
+
}
|
|
739
|
+
.qr-badge svg { width: 100%; height: 100%; }
|
|
740
|
+
|
|
741
|
+
/* Multi-use badge */
|
|
742
|
+
.use-badge {
|
|
743
|
+
display: inline-block;
|
|
744
|
+
background: var(--_surface);
|
|
745
|
+
border: 1px solid var(--_border);
|
|
746
|
+
border-radius: 20px;
|
|
747
|
+
padding: 4px 12px;
|
|
748
|
+
font-size: 12px;
|
|
749
|
+
font-weight: 600;
|
|
750
|
+
color: var(--_text-muted);
|
|
751
|
+
margin-bottom: 8px;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/* Status text */
|
|
755
|
+
.status-text {
|
|
756
|
+
font-size: 13px;
|
|
757
|
+
color: var(--_text-muted);
|
|
758
|
+
min-height: 20px;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/* Timer */
|
|
762
|
+
.timer {
|
|
763
|
+
font-size: 12px;
|
|
764
|
+
color: var(--_disabled);
|
|
765
|
+
margin-top: 8px;
|
|
766
|
+
font-variant-numeric: tabular-nums;
|
|
767
|
+
min-height: 18px;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/* Claimed / success state */
|
|
771
|
+
.state-claimed {
|
|
772
|
+
padding: 24px 0 12px;
|
|
773
|
+
animation: fade-scale-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
|
774
|
+
}
|
|
775
|
+
@keyframes fade-scale-in {
|
|
776
|
+
from { transform: scale(0.85); opacity: 0; }
|
|
777
|
+
to { transform: scale(1); opacity: 1; }
|
|
778
|
+
}
|
|
779
|
+
.success-icon {
|
|
780
|
+
width: 64px;
|
|
781
|
+
height: 64px;
|
|
782
|
+
background: var(--_success);
|
|
783
|
+
border-radius: 50%;
|
|
784
|
+
display: inline-flex;
|
|
785
|
+
align-items: center;
|
|
786
|
+
justify-content: center;
|
|
787
|
+
color: #fff;
|
|
788
|
+
margin-bottom: 16px;
|
|
789
|
+
}
|
|
790
|
+
.success-icon svg { width: 36px; height: 36px; }
|
|
791
|
+
|
|
792
|
+
/* Expired / revoked / error states */
|
|
793
|
+
.state-expired, .state-revoked, .state-error {
|
|
794
|
+
padding: 20px 0 8px;
|
|
795
|
+
}
|
|
796
|
+
.error-icon, .expired-icon {
|
|
797
|
+
font-size: 48px;
|
|
798
|
+
margin-bottom: 12px;
|
|
799
|
+
line-height: 1;
|
|
800
|
+
display: block;
|
|
801
|
+
}
|
|
802
|
+
.state-revoked .error-icon { color: var(--_error); }
|
|
803
|
+
.state-expired .expired-icon { color: var(--_disabled); }
|
|
804
|
+
.state-error .error-icon { color: var(--_warning); }
|
|
805
|
+
|
|
806
|
+
/* Retry button */
|
|
807
|
+
.retry-btn {
|
|
808
|
+
margin-top: 14px;
|
|
809
|
+
padding: 9px 22px;
|
|
810
|
+
background: var(--_surface);
|
|
811
|
+
border: 1px solid var(--_border);
|
|
812
|
+
border-radius: 8px;
|
|
813
|
+
font-size: 13px;
|
|
814
|
+
font-weight: 500;
|
|
815
|
+
cursor: pointer;
|
|
816
|
+
color: var(--_text-muted);
|
|
817
|
+
font-family: inherit;
|
|
818
|
+
transition: background 0.15s, border-color 0.15s;
|
|
819
|
+
}
|
|
820
|
+
.retry-btn:hover { background: var(--_border); color: var(--_text); }
|
|
821
|
+
|
|
822
|
+
/* Footer */
|
|
823
|
+
.footer {
|
|
824
|
+
margin-top: 18px;
|
|
825
|
+
font-size: 10px;
|
|
826
|
+
color: #c4cdd5;
|
|
827
|
+
}
|
|
828
|
+
.footer a { color: var(--_disabled); text-decoration: none; }
|
|
829
|
+
.footer a:hover { text-decoration: underline; }
|
|
830
|
+
`}_bindButtonEvents(){this.shadow.getElementById("open-btn")?.addEventListener("click",()=>{this._openModal(),this._startSession()});let t=this.shadow.getElementById("overlay");t?.addEventListener("click",i=>{i.target===t&&this._closeModal()}),this._bindModalButtons()}_bindInlineEvents(){this.shadow.getElementById("start-btn")?.addEventListener("click",()=>{this._startSession()})}_bindModalButtons(){this.shadow.getElementById("close-btn")?.addEventListener("click",()=>this._closeModal()),this.shadow.getElementById("retry-btn")?.addEventListener("click",()=>this._retry())}_openModal(){this.shadow.getElementById("overlay")?.classList.remove("hidden"),this._updateBody(this._bodyForStatus("idle"))}_closeModal(){this.shadow.getElementById("overlay")?.classList.add("hidden"),this._clearTimers(),this._sessionId=null,this._claimUrl=null,this._status="idle",this._expiresAt=null}async _startSession(){this._status="loading",this._updateBody(this._bodyForStatus("loading"));try{let e=await fetch(`${this.baseUrl}/api/v1/ephemeral`,{method:"POST",headers:{"Content-Type":"application/json","X-Client-Id":this.tenant},body:JSON.stringify({scopes:this.scopes.split(/\s+/).filter(Boolean),ttl:this.ttl,maxUses:this.maxUses,deviceBinding:this.deviceBinding})});if(!e.ok){let i=await e.json().catch(()=>({message:"Failed to create session"}));throw new Error(i.message??"Failed to create session")}let t=await e.json();this._sessionId=t.sessionId,this._claimUrl=t.claimUrl,this._expiresAt=new Date(t.expiresAt).getTime(),this._status="active",this._updateBody(this._bodyForStatus("active",{claimUrl:t.claimUrl,timerHtml:this._formatTimer(),useCount:0,maxUses:t.maxUses})),this._bindModalButtons(),this._startCountdown(),this._beginPolling(t.sessionId)}catch(e){let t=e instanceof Error?e.message:"Unexpected error";this._status="error",this._updateBody(this._bodyForStatus("error",{errorMessage:t})),this._bindModalButtons(),this.emit("qrauth:error",{message:t})}}_retry(){if(this._clearTimers(),this._sessionId=null,this._claimUrl=null,this._status="idle",this._expiresAt=null,this.display==="inline"){let e=this.shadow.getElementById("inline-body");e&&(e.innerHTML=this._inlineIdleContent(),this._bindInlineEvents())}else this._startSession()}_beginPolling(e){let t=2e3,i=5e3,s=0,r=20,d=async()=>{if(this._sessionId)try{let l=await(await fetch(`${this.baseUrl}/api/v1/ephemeral/${e}`,{headers:{"X-Client-Id":this.tenant}})).json();if(s=0,t=2e3,this._handleStatusChange(l.status,l),["CLAIMED","EXPIRED","REVOKED"].includes(l.status)){if(l.status==="CLAIMED"&&l.useCount<l.maxUses){this._updateBody(this._bodyForStatus("active",{claimUrl:this._claimUrl??void 0,timerHtml:this._formatTimer(),useCount:l.useCount,maxUses:l.maxUses})),this._bindModalButtons(),this._pollTimeout=setTimeout(d,t);return}return}this._pollTimeout=setTimeout(d,t)}catch{if(s++,s>=r){this._handleStatusChange("EXPIRED",void 0);return}t=Math.min(t*1.5,i),this._pollTimeout=setTimeout(d,t)}};this._pollTimeout=setTimeout(d,t)}_handleStatusChange(e,t){switch(e){case"CLAIMED":{this._clearTimers(),this._status="CLAIMED",this._updateBody(this._bodyForStatus("CLAIMED")),this._bindModalButtons(),this.emit("qrauth:claimed",{sessionId:t?.sessionId,status:t?.status,scopes:t?.scopes,metadata:t?.metadata,useCount:t?.useCount,maxUses:t?.maxUses}),this.display==="button"&&setTimeout(()=>this._closeModal(),2200);break}case"EXPIRED":this._clearTimers(),this._status="EXPIRED",this._updateBody(this._bodyForStatus("EXPIRED")),this._bindModalButtons(),this.emit("qrauth:expired");break;case"REVOKED":this._clearTimers(),this._status="REVOKED",this._updateBody(this._bodyForStatus("REVOKED")),this._bindModalButtons(),this.emit("qrauth:revoked");break}}_startCountdown(){this._timerInterval=setInterval(()=>{let e=this.shadow.getElementById("timer");if(!e||!this._expiresAt)return;let t=Math.max(0,Math.floor((this._expiresAt-Date.now())/1e3));e.textContent=t>0?this._formatTimer(t):"",t<=0&&(clearInterval(this._timerInterval),this._timerInterval=null,this._status==="active"&&this._handleStatusChange("EXPIRED",void 0))},1e3)}_formatTimer(e){let t=e??(this._expiresAt?Math.max(0,Math.floor((this._expiresAt-Date.now())/1e3)):0),i=Math.floor(t/60),s=t%60;return`Expires in ${i}:${s<10?"0":""}${s}`}_updateBody(e){let t=this.display==="inline"?this.shadow.getElementById("inline-body"):this.shadow.getElementById("modal-body");t&&(t.innerHTML=e)}_clearTimers(){this._timerInterval&&(clearInterval(this._timerInterval),this._timerInterval=null),this._pollTimeout&&(clearTimeout(this._pollTimeout),this._pollTimeout=null)}};customElements.define("qrauth-ephemeral",g);var f=`<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
831
|
+
<path d="M48 24 H152 Q166 24 166 38 V108 Q166 156 100 182 Q34 156 34 108 V38 Q34 24 48 24 Z"
|
|
832
|
+
fill="none" stroke="#fff" stroke-width="5"/>
|
|
833
|
+
<g fill="#fff" opacity="0.2">
|
|
834
|
+
<rect x="52" y="40" width="18" height="18" rx="3"/>
|
|
835
|
+
<rect x="78" y="40" width="18" height="18" rx="3"/>
|
|
836
|
+
<rect x="130" y="40" width="18" height="18" rx="3"/>
|
|
837
|
+
<rect x="52" y="66" width="18" height="18" rx="3"/>
|
|
838
|
+
<rect x="104" y="66" width="18" height="18" rx="3"/>
|
|
839
|
+
<rect x="78" y="92" width="18" height="18" rx="3"/>
|
|
840
|
+
<rect x="130" y="92" width="18" height="18" rx="3"/>
|
|
841
|
+
<rect x="52" y="118" width="18" height="18" rx="3"/>
|
|
842
|
+
<rect x="104" y="118" width="18" height="18" rx="3"/>
|
|
843
|
+
</g>
|
|
844
|
+
<path d="M62 104 L88 134 L144 64"
|
|
845
|
+
fill="none" stroke="#fff" stroke-width="15"
|
|
846
|
+
stroke-linecap="round" stroke-linejoin="round"/>
|
|
847
|
+
</svg>`,y=`<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
848
|
+
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z" fill="currentColor"/>
|
|
849
|
+
</svg>`,D=`<svg class="spinner" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
850
|
+
<circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2.5"
|
|
851
|
+
stroke-dasharray="31.416" stroke-dashoffset="10" stroke-linecap="round"/>
|
|
852
|
+
</svg>`,b=class extends p{constructor(){super(...arguments);n(this,"_sessionId",null);n(this,"_codeVerifier",null);n(this,"_status","idle");n(this,"_expiresAt",null);n(this,"_timerInterval",null);n(this,"_pollTimeout",null)}static get observedAttributes(){return[...super.observedAttributes,"session-token","scopes","auto-start"]}get sessionToken(){return this.getAttribute("session-token")}get scopes(){return this.getAttribute("scopes")||"identity"}get autoStart(){return this.hasAttribute("auto-start")}connectedCallback(){super.connectedCallback(),this.autoStart&&this._startAuth()}disconnectedCallback(){super.disconnectedCallback(),this._clearTimers()}render(){this.shadow.innerHTML=`
|
|
853
|
+
<style>
|
|
854
|
+
${this.getBaseStyles()}
|
|
855
|
+
:host { display: block; }
|
|
856
|
+
|
|
857
|
+
.container {
|
|
858
|
+
background: var(--_bg);
|
|
859
|
+
border: 1px solid var(--_border);
|
|
860
|
+
border-radius: 16px;
|
|
861
|
+
padding: 24px 20px 18px;
|
|
862
|
+
text-align: center;
|
|
863
|
+
max-width: 320px;
|
|
864
|
+
margin: 0 auto;
|
|
865
|
+
box-shadow: 0 2px 12px rgba(0,0,0,0.06);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/* Step indicator */
|
|
869
|
+
.step-label {
|
|
870
|
+
display: inline-flex;
|
|
871
|
+
align-items: center;
|
|
872
|
+
gap: 6px;
|
|
873
|
+
font-size: 11px;
|
|
874
|
+
font-weight: 600;
|
|
875
|
+
letter-spacing: 0.06em;
|
|
876
|
+
text-transform: uppercase;
|
|
877
|
+
color: var(--_primary);
|
|
878
|
+
background: rgba(0,167,111,0.08);
|
|
879
|
+
border-radius: 20px;
|
|
880
|
+
padding: 4px 10px;
|
|
881
|
+
margin-bottom: 14px;
|
|
882
|
+
}
|
|
883
|
+
.step-dot {
|
|
884
|
+
width: 6px;
|
|
885
|
+
height: 6px;
|
|
886
|
+
border-radius: 50%;
|
|
887
|
+
background: var(--_primary);
|
|
888
|
+
flex-shrink: 0;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/* Idle start button */
|
|
892
|
+
.start-btn {
|
|
893
|
+
display: inline-flex;
|
|
894
|
+
align-items: center;
|
|
895
|
+
gap: 10px;
|
|
896
|
+
padding: 11px 22px;
|
|
897
|
+
background: var(--_btn-bg);
|
|
898
|
+
color: #fff;
|
|
899
|
+
border: none;
|
|
900
|
+
border-radius: var(--_radius);
|
|
901
|
+
font-size: 14px;
|
|
902
|
+
font-weight: 600;
|
|
903
|
+
cursor: pointer;
|
|
904
|
+
transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
|
|
905
|
+
font-family: inherit;
|
|
906
|
+
width: 100%;
|
|
907
|
+
justify-content: center;
|
|
908
|
+
margin-top: 4px;
|
|
909
|
+
}
|
|
910
|
+
.start-btn:hover:not(:disabled) {
|
|
911
|
+
background: var(--_btn-hover);
|
|
912
|
+
transform: translateY(-1px);
|
|
913
|
+
box-shadow: 0 4px 12px rgba(27,42,74,0.3);
|
|
914
|
+
}
|
|
915
|
+
.start-btn:active:not(:disabled) { transform: translateY(0); }
|
|
916
|
+
.start-btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
917
|
+
.btn-icon { width: 20px; height: 20px; flex-shrink: 0; }
|
|
918
|
+
|
|
919
|
+
${this._sharedStyles()}
|
|
920
|
+
</style>
|
|
921
|
+
|
|
922
|
+
<div class="container" role="region" aria-label="Second-factor authentication">
|
|
923
|
+
<div id="body">
|
|
924
|
+
${this._bodyForStatus("idle")}
|
|
925
|
+
</div>
|
|
926
|
+
</div>
|
|
927
|
+
`,this._bindBodyEvents()}_bodyForStatus(e,t){let i=`
|
|
928
|
+
<div class="step-label">
|
|
929
|
+
<span class="step-dot"></span>
|
|
930
|
+
Step 2 of 2 — Verify identity
|
|
931
|
+
</div>
|
|
932
|
+
`;switch(e){case"idle":return`
|
|
933
|
+
${i}
|
|
934
|
+
<div class="state-header">
|
|
935
|
+
<div class="brand-icon">${f}</div>
|
|
936
|
+
<h3>Verify your identity</h3>
|
|
937
|
+
<p class="subtitle">Scan the QR code with your phone to confirm it's you</p>
|
|
938
|
+
</div>
|
|
939
|
+
<button class="start-btn" id="start-btn" aria-label="Start 2FA verification">
|
|
940
|
+
<span class="btn-icon">${f}</span>
|
|
941
|
+
Verify your identity
|
|
942
|
+
</button>
|
|
943
|
+
`;case"loading":return`
|
|
944
|
+
${i}
|
|
945
|
+
<div class="state-loading">
|
|
946
|
+
<div class="spinner-wrap">${D}</div>
|
|
947
|
+
<p class="status-text">Generating QR code...</p>
|
|
948
|
+
</div>
|
|
949
|
+
`;case"pending":case"SCANNED":{let s=t?.qrUrl?`https://api.qrserver.com/v1/create-qr-code/?size=320x320&data=${encodeURIComponent(t.qrUrl)}`:"",r=e==="SCANNED";return`
|
|
950
|
+
${i}
|
|
951
|
+
<h3>Scan to verify</h3>
|
|
952
|
+
<p class="subtitle">Use your phone camera to complete verification</p>
|
|
953
|
+
<div class="qr-frame ${r?"scanned":""}">
|
|
954
|
+
<img src="${s}" alt="QR Code for 2FA verification" width="160" height="160" loading="lazy"/>
|
|
955
|
+
<div class="qr-badge">${f}</div>
|
|
956
|
+
${r?'<div class="scanned-overlay"><span class="scanned-check">'+y+"</span></div>":""}
|
|
957
|
+
</div>
|
|
958
|
+
<div class="status-text ${r?"status-scanned":""}">
|
|
959
|
+
${r?"✓ Scanned — waiting for approval...":"Waiting for scan..."}
|
|
960
|
+
</div>
|
|
961
|
+
<div class="timer" id="timer">${t?.timerHtml??""}</div>
|
|
962
|
+
<div class="footer">Secured by <a href="https://qrauth.io" target="_blank" rel="noopener">QRAuth</a></div>
|
|
963
|
+
`}case"APPROVED":return`
|
|
964
|
+
<div class="state-approved">
|
|
965
|
+
<div class="success-icon">${y}</div>
|
|
966
|
+
<h3>Identity verified!</h3>
|
|
967
|
+
<p class="subtitle">Second factor confirmed</p>
|
|
968
|
+
</div>
|
|
969
|
+
`;case"DENIED":return`
|
|
970
|
+
<div class="state-denied">
|
|
971
|
+
<div class="error-icon">✗</div>
|
|
972
|
+
<h3>Verification denied</h3>
|
|
973
|
+
<p class="subtitle">The request was declined on your device.</p>
|
|
974
|
+
<button class="retry-btn" id="retry-btn">Try again</button>
|
|
975
|
+
</div>
|
|
976
|
+
`;case"EXPIRED":return`
|
|
977
|
+
<div class="state-expired">
|
|
978
|
+
<div class="expired-icon">⌛</div>
|
|
979
|
+
<h3>Session expired</h3>
|
|
980
|
+
<p class="subtitle">The QR code has timed out.</p>
|
|
981
|
+
<button class="retry-btn" id="retry-btn">Try again</button>
|
|
982
|
+
</div>
|
|
983
|
+
`;case"error":return`
|
|
984
|
+
<div class="state-error">
|
|
985
|
+
<div class="error-icon">⚠</div>
|
|
986
|
+
<h3>Something went wrong</h3>
|
|
987
|
+
<p class="subtitle">${t?.errorMessage??"Failed to start verification."}</p>
|
|
988
|
+
<button class="retry-btn" id="retry-btn">Try again</button>
|
|
989
|
+
</div>
|
|
990
|
+
`;default:return""}}_sharedStyles(){return`
|
|
991
|
+
/* Typography */
|
|
992
|
+
h3 {
|
|
993
|
+
font-size: 16px;
|
|
994
|
+
font-weight: 700;
|
|
995
|
+
color: var(--_text);
|
|
996
|
+
margin: 0 0 5px;
|
|
997
|
+
}
|
|
998
|
+
.subtitle {
|
|
999
|
+
font-size: 12px;
|
|
1000
|
+
color: var(--_text-muted);
|
|
1001
|
+
margin: 0 0 16px;
|
|
1002
|
+
line-height: 1.5;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/* Brand icon in idle state */
|
|
1006
|
+
.state-header { padding: 4px 0 2px; }
|
|
1007
|
+
.brand-icon {
|
|
1008
|
+
width: 48px;
|
|
1009
|
+
height: 48px;
|
|
1010
|
+
background: var(--_btn-bg);
|
|
1011
|
+
border-radius: 12px;
|
|
1012
|
+
display: inline-flex;
|
|
1013
|
+
align-items: center;
|
|
1014
|
+
justify-content: center;
|
|
1015
|
+
margin-bottom: 12px;
|
|
1016
|
+
padding: 8px;
|
|
1017
|
+
}
|
|
1018
|
+
.brand-icon svg { width: 32px; height: 32px; }
|
|
1019
|
+
|
|
1020
|
+
/* Loading state */
|
|
1021
|
+
.state-loading {
|
|
1022
|
+
padding: 24px 0;
|
|
1023
|
+
display: flex;
|
|
1024
|
+
flex-direction: column;
|
|
1025
|
+
align-items: center;
|
|
1026
|
+
gap: 14px;
|
|
1027
|
+
}
|
|
1028
|
+
.spinner-wrap { color: var(--_primary); }
|
|
1029
|
+
.spinner {
|
|
1030
|
+
width: 36px;
|
|
1031
|
+
height: 36px;
|
|
1032
|
+
animation: spin 0.8s linear infinite;
|
|
1033
|
+
}
|
|
1034
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
1035
|
+
|
|
1036
|
+
/* QR frame \u2014 compact 160x160 */
|
|
1037
|
+
.qr-frame {
|
|
1038
|
+
display: inline-block;
|
|
1039
|
+
padding: 10px;
|
|
1040
|
+
background: #fff;
|
|
1041
|
+
border: 2px solid var(--_border);
|
|
1042
|
+
border-radius: var(--_radius);
|
|
1043
|
+
margin-bottom: 12px;
|
|
1044
|
+
position: relative;
|
|
1045
|
+
transition: border-color 0.3s;
|
|
1046
|
+
}
|
|
1047
|
+
.qr-frame.scanned { border-color: var(--_success); }
|
|
1048
|
+
.qr-frame img { display: block; width: 160px; height: 160px; border-radius: 4px; }
|
|
1049
|
+
|
|
1050
|
+
/* Smaller badge for compact QR */
|
|
1051
|
+
.qr-badge {
|
|
1052
|
+
position: absolute;
|
|
1053
|
+
top: 50%;
|
|
1054
|
+
left: 50%;
|
|
1055
|
+
transform: translate(-50%, -50%);
|
|
1056
|
+
width: 40px;
|
|
1057
|
+
height: 40px;
|
|
1058
|
+
background: #1b2a4a;
|
|
1059
|
+
border-radius: 8px;
|
|
1060
|
+
padding: 5px;
|
|
1061
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
|
|
1062
|
+
display: flex;
|
|
1063
|
+
align-items: center;
|
|
1064
|
+
justify-content: center;
|
|
1065
|
+
}
|
|
1066
|
+
.qr-badge svg { width: 100%; height: 100%; }
|
|
1067
|
+
|
|
1068
|
+
/* Scanned overlay on QR */
|
|
1069
|
+
.scanned-overlay {
|
|
1070
|
+
position: absolute;
|
|
1071
|
+
inset: 0;
|
|
1072
|
+
background: rgba(0,167,111,0.08);
|
|
1073
|
+
border-radius: calc(var(--_radius) - 2px);
|
|
1074
|
+
display: flex;
|
|
1075
|
+
align-items: center;
|
|
1076
|
+
justify-content: center;
|
|
1077
|
+
}
|
|
1078
|
+
.scanned-check {
|
|
1079
|
+
width: 40px;
|
|
1080
|
+
height: 40px;
|
|
1081
|
+
background: var(--_success);
|
|
1082
|
+
border-radius: 50%;
|
|
1083
|
+
display: flex;
|
|
1084
|
+
align-items: center;
|
|
1085
|
+
justify-content: center;
|
|
1086
|
+
color: #fff;
|
|
1087
|
+
opacity: 0;
|
|
1088
|
+
animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.1s forwards;
|
|
1089
|
+
}
|
|
1090
|
+
.scanned-check svg { width: 22px; height: 22px; }
|
|
1091
|
+
@keyframes pop-in {
|
|
1092
|
+
from { transform: scale(0.5); opacity: 0; }
|
|
1093
|
+
to { transform: scale(1); opacity: 1; }
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
/* Status text */
|
|
1097
|
+
.status-text {
|
|
1098
|
+
font-size: 12px;
|
|
1099
|
+
color: var(--_text-muted);
|
|
1100
|
+
min-height: 18px;
|
|
1101
|
+
}
|
|
1102
|
+
.status-scanned {
|
|
1103
|
+
color: var(--_success);
|
|
1104
|
+
font-weight: 600;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
/* Timer */
|
|
1108
|
+
.timer {
|
|
1109
|
+
font-size: 11px;
|
|
1110
|
+
color: var(--_disabled);
|
|
1111
|
+
margin-top: 6px;
|
|
1112
|
+
font-variant-numeric: tabular-nums;
|
|
1113
|
+
min-height: 16px;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/* Success state */
|
|
1117
|
+
.state-approved {
|
|
1118
|
+
padding: 16px 0 8px;
|
|
1119
|
+
animation: fade-scale-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
|
1120
|
+
}
|
|
1121
|
+
@keyframes fade-scale-in {
|
|
1122
|
+
from { transform: scale(0.85); opacity: 0; }
|
|
1123
|
+
to { transform: scale(1); opacity: 1; }
|
|
1124
|
+
}
|
|
1125
|
+
.success-icon {
|
|
1126
|
+
width: 56px;
|
|
1127
|
+
height: 56px;
|
|
1128
|
+
background: var(--_success);
|
|
1129
|
+
border-radius: 50%;
|
|
1130
|
+
display: inline-flex;
|
|
1131
|
+
align-items: center;
|
|
1132
|
+
justify-content: center;
|
|
1133
|
+
color: #fff;
|
|
1134
|
+
margin-bottom: 14px;
|
|
1135
|
+
}
|
|
1136
|
+
.success-icon svg { width: 30px; height: 30px; }
|
|
1137
|
+
|
|
1138
|
+
/* Denied / expired / error states */
|
|
1139
|
+
.state-denied, .state-expired, .state-error {
|
|
1140
|
+
padding: 16px 0 6px;
|
|
1141
|
+
}
|
|
1142
|
+
.error-icon, .expired-icon {
|
|
1143
|
+
font-size: 40px;
|
|
1144
|
+
margin-bottom: 10px;
|
|
1145
|
+
line-height: 1;
|
|
1146
|
+
display: block;
|
|
1147
|
+
}
|
|
1148
|
+
.state-denied .error-icon { color: var(--_error); }
|
|
1149
|
+
.state-expired .expired-icon { color: var(--_disabled); }
|
|
1150
|
+
.state-error .error-icon { color: var(--_warning); }
|
|
1151
|
+
|
|
1152
|
+
/* Retry button */
|
|
1153
|
+
.retry-btn {
|
|
1154
|
+
margin-top: 12px;
|
|
1155
|
+
padding: 8px 20px;
|
|
1156
|
+
background: var(--_surface);
|
|
1157
|
+
border: 1px solid var(--_border);
|
|
1158
|
+
border-radius: 8px;
|
|
1159
|
+
font-size: 12px;
|
|
1160
|
+
font-weight: 500;
|
|
1161
|
+
cursor: pointer;
|
|
1162
|
+
color: var(--_text-muted);
|
|
1163
|
+
font-family: inherit;
|
|
1164
|
+
transition: background 0.15s, border-color 0.15s;
|
|
1165
|
+
}
|
|
1166
|
+
.retry-btn:hover { background: var(--_border); color: var(--_text); }
|
|
1167
|
+
|
|
1168
|
+
/* Footer */
|
|
1169
|
+
.footer {
|
|
1170
|
+
margin-top: 14px;
|
|
1171
|
+
font-size: 10px;
|
|
1172
|
+
color: #c4cdd5;
|
|
1173
|
+
}
|
|
1174
|
+
.footer a { color: var(--_disabled); text-decoration: none; }
|
|
1175
|
+
.footer a:hover { text-decoration: underline; }
|
|
1176
|
+
`}_bindBodyEvents(){this.shadow.getElementById("start-btn")?.addEventListener("click",()=>this._startAuth()),this.shadow.getElementById("retry-btn")?.addEventListener("click",()=>this._retry())}async _startAuth(){this._status="loading",this._updateBody(this._bodyForStatus("loading"));try{this._codeVerifier=await this.generateCodeVerifier();let e=await this.computeCodeChallenge(this._codeVerifier),t={"Content-Type":"application/json","X-Client-Id":this.tenant},i={scopes:this.scopes.split(/\s+/).filter(Boolean),codeChallenge:e,codeChallengeMethod:"S256"},s=await fetch(`${this.baseUrl}/api/v1/auth-sessions`,{method:"POST",headers:t,body:JSON.stringify(i)});if(!s.ok){let d=await s.json().catch(()=>({message:"Failed to create session"}));throw new Error(d.message??"Failed to create session")}let r=await s.json();this._sessionId=r.sessionId,this._expiresAt=new Date(r.expiresAt).getTime(),this._status="pending",this._updateBody(this._bodyForStatus("pending",{qrUrl:r.qrUrl})),this._bindBodyEvents(),this._startCountdown(),this._beginPolling(r.sessionId)}catch(e){let t=e instanceof Error?e.message:"Unexpected error";this._status="error",this._updateBody(this._bodyForStatus("error",{errorMessage:t})),this._bindBodyEvents(),this.emit("qrauth:error",{message:t})}}_retry(){this._clearTimers(),this._sessionId=null,this._codeVerifier=null,this._status="idle",this._expiresAt=null,this._updateBody(this._bodyForStatus("idle")),this._bindBodyEvents()}_beginPolling(e){let t="PENDING",i=2e3,s=5e3,r=0,d=20,h=async()=>{if(!this._sessionId)return;let l=`${this.baseUrl}/api/v1/auth-sessions/${e}`;this._codeVerifier&&(l+=`?code_verifier=${encodeURIComponent(this._codeVerifier)}`);try{let c=await(await fetch(l,{headers:{"X-Client-Id":this.tenant}})).json();if(r=0,i=2e3,c.status!==t&&(t=c.status,this._handleStatusChange(c.status,c),["APPROVED","DENIED","EXPIRED"].includes(c.status)))return;this._pollTimeout=setTimeout(h,i)}catch{if(r++,r>=d){this._handleStatusChange("EXPIRED",void 0);return}i=Math.min(i*1.5,s),this._pollTimeout=setTimeout(h,i)}};this._pollTimeout=setTimeout(h,i)}_handleStatusChange(e,t){switch(this._status=e,e){case"SCANNED":{let i=this.shadow.querySelector(".qr-frame img")?.src,s=i?decodeURIComponent(i.replace(/.*[?&]data=/,"").split("&")[0]):"";this._updateBody(this._bodyForStatus("SCANNED",{qrUrl:s,timerHtml:this._formatTimer()})),this._bindBodyEvents();break}case"APPROVED":{this._clearTimers(),this._updateBody(this._bodyForStatus("APPROVED")),this.emit("qrauth:verified",{sessionId:t?.sessionId,user:t?.user,signature:t?.signature});break}case"DENIED":this._clearTimers(),this._updateBody(this._bodyForStatus("DENIED")),this._bindBodyEvents(),this.emit("qrauth:denied");break;case"EXPIRED":this._clearTimers(),this._status="EXPIRED",this._updateBody(this._bodyForStatus("EXPIRED")),this._bindBodyEvents(),this.emit("qrauth:expired");break}}_startCountdown(){this._timerInterval=setInterval(()=>{let e=this.shadow.getElementById("timer");if(!e||!this._expiresAt)return;let t=Math.max(0,Math.floor((this._expiresAt-Date.now())/1e3));e.textContent=t>0?this._formatTimer(t):"",t<=0&&(clearInterval(this._timerInterval),this._timerInterval=null,(this._status==="pending"||this._status==="SCANNED")&&this._handleStatusChange("EXPIRED",void 0))},1e3)}_formatTimer(e){let t=e??(this._expiresAt?Math.max(0,Math.floor((this._expiresAt-Date.now())/1e3)):0),i=Math.floor(t/60),s=t%60;return`Expires in ${i}:${s<10?"0":""}${s}`}_updateBody(e){let t=this.shadow.getElementById("body");t&&(t.innerHTML=e)}_clearTimers(){this._timerInterval&&(clearInterval(this._timerInterval),this._timerInterval=null),this._pollTimeout&&(clearTimeout(this._pollTimeout),this._pollTimeout=null)}};customElements.define("qrauth-2fa",b);return T(q);})();
|
|
1177
|
+
//# sourceMappingURL=qrauth-components.js.map
|