-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfireoauth.html
213 lines (181 loc) · 6.61 KB
/
fireoauth.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/fireoauth.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css">
<link rel="shortcut icon" href="https://raw.githubusercontent.com/tharunoptimus-pd/firepwa/main/favicon.ico?token=GHSAT0AAAAAABR46HVJ5M5L3QGFRZRQXOISYUJUWAA" type="image/x-icon">
<style>
html,
body {
height: 100%;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
font-weight: 300;
}
a {
text-decoration: none;
color: #007bff;
font-weight: 500;
font-size: 1.2rem;
}
h3 {
font-size: 1.4rem;
}
h3, h4 {
margin: 0;
padding: 0.3rem 0;
}
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
text-align: center;
}
.oneClickSignin {
padding: 0.5rem;
border: 1px solid #44444444;
border-radius: 5px;
box-shadow: 0 0 3px 0px #44444444;
opacity: 0.2;
pointer-events: none;
}
.qrcode {
opacity: 0.1;
}
.learnAboutFire {
padding-top: 1.25em;
}
.qrHolder {
display: none;
margin-top: 3rem;
}
.qrContainer {
align-items: center;
display: flex;
justify-content: center;
padding: 8px;
margin: 2rem auto;
box-shadow: 0 0px 6px 1px rgb(0 0 0 / 16%);
border: 1px solid #44444444;
border-radius: 6px;
width: 200px;
height: 200px;
}
</style>
<title>Fire OAuth</title>
<script>
if (window.location.hostname !== "localhost") {
if (location.protocol !== "https:") {
location.replace(
`https:${location.href.substring(
location.protocol.length
)}`
)
}
}
</script>
</head>
<body>
<div class="wrapper">
<h3 class="pageTitle">Login with Fire 🔥</h3>
<div class="qrAuthorize">
<h4 class="subTitle">Scan QR from your Fire OAuth App📱</h4>
<div class="qrContainer">
<canvas id="qr-code" class="qrcode"></canvas>
</div>
</div>
<div class="oneClickSignin">
<h4>Have Fire PWA on this device?</h4>
<a target="_blank" id="authorizeOverLink" href="https://firepwa.netlify.app/authorize?sessionId" rel="noopener">Click to Authorize 🔑 </a>
</div>
<div class="learnAboutFire">
<a target="_blank" href="https://fireoauth.netlify.app" rel="noopener">Learn More about Fire 🔥</a>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.2.0/socket.io.js"></script>
<script>
const FIRE_API_KEY = "635639f067016220e1955f57"
const FIRE_ENDPOINT = "https://fire.adaptable.app/api/apis/generate"
const CHANNEL_NAME = "fireOAuthChannel"
const broadCastingChannel = new BroadcastChannel(CHANNEL_NAME)
const FIRE_SERVER_SOCKET_ENDPOINT = "https://fire.adaptable.app"
let socket = io(FIRE_SERVER_SOCKET_ENDPOINT)
let qr
let qrcode = document.querySelector(".qrcode")
let oneClickSignin = document.querySelector(".oneClickSignin")
let pageTitle = document.querySelector(".pageTitle")
let subTitle = document.querySelector(".subTitle")
function setOpacity(opacity) {
oneClickSignin.style.opacity = opacity
oneClickSignin.style.pointerEvents = opacity === "1" ? "auto" : "none"
qrcode.style.opacity = opacity
}
async function getSessionID() {
let response
try {
response = await fetch(`${FIRE_ENDPOINT}/${FIRE_API_KEY}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
}
})
} catch (error) {
console.log(error)
return null
}
let data = await response.json()
let { sessionId, chatRoomId } = data
return { sessionId, chatRoomId }
}
function generateQR(value) {
(qr = new QRious({
element: document.getElementById("qr-code"),
size: 200,
level: 'M',
value: value,
}))
}
function changeHREF ({sessionId, chatRoomId}) {
let firePwaUrlHostname = "https://firepwa.netlify.app"
let originURL = encodeURIComponent(window.location.origin)
let url = `${firePwaUrlHostname}/authorize.html?sessionId=${sessionId}&chatRoomId=${chatRoomId}&url=${originURL}`
let a = document.getElementById("authorizeOverLink")
a.href = url
}
async function fire() {
NProgress.set(0.4)
let { sessionId, chatRoomId } = await getSessionID()
if(sessionId === undefined || chatRoomId === undefined || sessionId === null || chatRoomId === null) {
pageTitle.innerHTML = "Something went wrong 💀☠"
subTitle.innerHTML = "Please try again later 😩😢"
return
}
setOpacity("1")
NProgress.done()
let data = {
sessionId,
url: encodeURIComponent(window.location.origin)
}
data = JSON.stringify(data)
generateQR(data)
changeHREF({sessionId, chatRoomId})
socket.emit("join room", sessionId)
}
fire()
socket.on("trusted token", (token) => {
let data = {}
data.success = true
data.token = token
broadCastingChannel.postMessage(data)
window.close()
})
</script>
</body>
</html>