forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoauth_authenticate.html
More file actions
308 lines (282 loc) · 14.2 KB
/
Copy pathoauth_authenticate.html
File metadata and controls
308 lines (282 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Connect {{ app_name }} to Omi</title>
<!-- Include Firebase SDKs -->
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-auth-compat.js"></script>
<!-- Include FirebaseUI for easy login UI, or use custom Firebase auth calls -->
<script src="https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth.js"></script>
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth.css" />
{% include "_oauth_shared_styles.html" %}
</head>
<body>
<main class="oauth-shell">
<div class="oauth-card">
<div class="oauth-header">
<span class="omi-logo">
<svg class="omi-mark" viewBox="237.36 237.338 549.318 549.322" fill="currentColor"
aria-hidden="true">
<circle cx="282.523" cy="511.982" r="45.163" />
<circle cx="339.909" cy="339.89" r="45.107" />
<circle cx="512.014" cy="282.495" r="45.156" />
<circle cx="684.096" cy="339.88" r="45.103" />
<circle cx="741.511" cy="512.003" r="45.167" />
<circle cx="684.096" cy="684.094" r="45.103" />
<circle cx="511.981" cy="741.5" r="45.16" />
<circle cx="339.902" cy="684.107" r="45.103" />
</svg>
Omi
</span>
<span class="oauth-eyebrow">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<rect x="5" y="10.5" width="14" height="9" rx="2" stroke="currentColor" stroke-width="1.8" />
<path d="M8 10.5V8a4 4 0 0 1 8 0v2.5" stroke="currentColor" stroke-width="1.8"
stroke-linecap="round" />
</svg>
Secure connection
</span>
</div>
<div class="oauth-content">
<div class="oauth-hero">
<div class="connect-lockup" aria-hidden="true">
<span class="lockup-tile lockup-app">
{% if app_image %}
<img src="{{ app_image }}" alt="">
{% else %}
{{ app_name[:1] }}
{% endif %}
</span>
<span class="lockup-bridge">
<span class="lockup-bridge-badge">
<svg viewBox="0 0 24 24" fill="none">
<path d="M10.5 13.5a3.4 3.4 0 0 0 4.8 0l2-2a3.4 3.4 0 0 0-4.8-4.8l-1 1"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round"
stroke-linejoin="round" />
<path d="M13.5 10.5a3.4 3.4 0 0 0-4.8 0l-2 2a3.4 3.4 0 0 0 4.8 4.8l1-1"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round"
stroke-linejoin="round" />
</svg>
</span>
</span>
<span class="lockup-tile lockup-omi">
<svg class="omi-mark" viewBox="237.36 237.338 549.318 549.322" fill="currentColor">
<circle cx="282.523" cy="511.982" r="45.163" />
<circle cx="339.909" cy="339.89" r="45.107" />
<circle cx="512.014" cy="282.495" r="45.156" />
<circle cx="684.096" cy="339.88" r="45.103" />
<circle cx="741.511" cy="512.003" r="45.167" />
<circle cx="684.096" cy="684.094" r="45.103" />
<circle cx="511.981" cy="741.5" r="45.16" />
<circle cx="339.902" cy="684.107" r="45.103" />
</svg>
</span>
</div>
<h1>Connect {{ app_name }}</h1>
<p class="oauth-subtitle">Sign in to allow <strong>{{ app_name }}</strong> to access your Omi
account.</p>
</div>
{% if permissions %}
<section class="permissions-card" aria-labelledby="permissions-title">
<p class="permissions-title" id="permissions-title">{{ app_name }} will be able to</p>
<ul class="permissions-list" tabindex="0" role="list" aria-labelledby="permissions-title">
{% for perm in permissions %}
<li>
<span class="perm-check" aria-hidden="true">
<svg viewBox="0 0 16 16" fill="none">
<path d="M3.5 8.5 6.5 11.5 12.5 4.5" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round" />
</svg>
</span>
<span>{{ perm.text }}</span>
</li>
{% endfor %}
</ul>
</section>
{% endif %}
<div class="oauth-actions">
<form class="email-sign-in-form" id="email-sign-in-form" novalidate>
<div class="oauth-field">
<label for="email-input">Email</label>
<input id="email-input" name="email" type="email" autocomplete="email"
autocapitalize="none" autocorrect="off" spellcheck="false" inputmode="email"
placeholder="you@example.com" required>
</div>
<div class="oauth-field">
<label for="password-input">Password</label>
<input id="password-input" name="password" type="password" autocomplete="current-password"
placeholder="••••••••" required>
</div>
<button class="email-sign-in-button" id="email-sign-in-button" type="submit">
Sign in
</button>
</form>
<div class="oauth-divider" id="social-sign-in-divider">or continue with</div>
<div id="firebaseui-auth-container"></div>
<div class="loader" id="loader" role="status" aria-live="polite">
<span class="spinner" aria-hidden="true"></span>
<span>Connecting…</span>
</div>
<div id="error-message" class="error" role="alert">
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true">
<circle cx="8" cy="8" r="6.6" stroke="currentColor" stroke-width="1.5" />
<path d="M8 4.6v4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
<circle cx="8" cy="11" r="0.9" fill="currentColor" />
</svg>
<span id="error-text"></span>
</div>
</div>
</div>
<div class="oauth-footer">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M12 3 5 6v5c0 4.2 2.9 7.6 7 9 4.1-1.4 7-4.8 7-9V6l-7-3Z" stroke="currentColor"
stroke-width="1.7" stroke-linejoin="round" />
<path d="M9 12l2 2 4-4" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"
stroke-linejoin="round" />
</svg>
<span>Only continue if you trust <strong>{{ app_name }}</strong>. By authorizing, you allow it to use
your data under Omi's <a href="https://www.omi.me/pages/terms-of-service">Terms of Service</a> and <a
href="https://www.omi.me/pages/privacy">Privacy Policy</a>.</span>
</div>
</div>
</main>
<script>
// These values are passed from the backend template rendering
const appId = "{{ app_id }}";
const state = "{{ state }}";
const csrfToken = "{{ csrf_token }}";
// Firebase configuration
const firebaseConfig = {
apiKey: "{{ firebase_api_key }}",
authDomain: "{{ firebase_auth_domain }}",
projectId: "{{ firebase_project_id }}"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const loader = document.getElementById('loader');
const errorMessage = document.getElementById('error-message');
const errorText = document.getElementById('error-text');
const emailSignInForm = document.getElementById('email-sign-in-form');
const emailInput = document.getElementById('email-input');
const passwordInput = document.getElementById('password-input');
const emailSignInButton = document.getElementById('email-sign-in-button');
const socialSignInDivider = document.getElementById('social-sign-in-divider');
const firebaseUiContainer = document.getElementById('firebaseui-auth-container');
function setLoading(isLoading) {
loader.classList.toggle('is-visible', isLoading);
emailInput.disabled = isLoading;
passwordInput.disabled = isLoading;
emailSignInButton.disabled = isLoading;
}
function clearError() {
errorText.textContent = '';
errorMessage.classList.remove('is-visible');
}
function showError(message) {
errorText.textContent = message;
errorMessage.classList.add('is-visible');
setLoading(false);
emailSignInForm.style.display = 'grid';
socialSignInDivider.style.display = 'flex';
firebaseUiContainer.style.display = 'block';
}
function showSignInError() {
showError('We could not sign in with that email and password. Check the credentials and try again.');
}
function hideSignInOptions() {
emailSignInForm.style.display = 'none';
socialSignInDivider.style.display = 'none';
firebaseUiContainer.style.display = 'none';
}
function exchangeFirebaseToken(idToken) {
const formData = new FormData();
formData.append('firebase_id_token', idToken);
formData.append('app_id', appId);
formData.append('csrf_token', csrfToken);
if (state) {
formData.append('state', state);
}
fetch('/v1/oauth/token', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
return response.json().then(err => { throw new Error(err.detail || 'Authentication failed'); });
}
return response.json();
})
.then(data => {
let finalRedirectUrl = data.redirect_url + "?uid=" + data.uid;
if (data.state) {
finalRedirectUrl += "&state=" + data.state;
}
window.location.href = finalRedirectUrl;
})
.catch(error => {
showError(error.message);
});
}
function finishSignIn(user) {
setLoading(true);
hideSignInOptions();
clearError();
user.getIdToken()
.then(exchangeFirebaseToken)
.catch(function () {
showError('We could not complete sign-in. Please try again.');
});
}
function isAppleDevice() {
return /Mac|iPod|iPhone|iPad/.test(navigator.platform);
}
let signInOptions = [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
];
if (isAppleDevice()) {
signInOptions.push('apple.com');
}
emailSignInForm.addEventListener('submit', function (event) {
event.preventDefault();
clearError();
if (!emailInput.value.trim() || !passwordInput.value) {
showError('Enter your email and password to continue.');
return;
}
setLoading(true);
firebase.auth()
.signInWithEmailAndPassword(emailInput.value.trim(), passwordInput.value)
.then(function (result) {
finishSignIn(result.user);
})
.catch(function () {
passwordInput.value = '';
showSignInError();
});
});
const uiConfig = {
signInFlow: 'popup', // Use popup flow instead of redirect
signInSuccessUrl: null, // We will handle redirect manually
signInOptions: signInOptions,
callbacks: {
signInSuccessWithAuthResult: function (authResult, redirectUrlParam) {
finishSignIn(authResult.user);
return false;
},
signInFailure: function (error) {
showError('Sign-in failed. Please try again.');
},
uiShown: function () {
setLoading(false);
}
}
};
// Initialize the FirebaseUI Widget using Firebase.
const ui = new firebaseui.auth.AuthUI(firebase.auth());
// The start method will wait until the DOM is loaded.
ui.start('#firebaseui-auth-container', uiConfig);
</script>
</body>
</html>