-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-callback.html
More file actions
218 lines (187 loc) · 7.86 KB
/
code-callback.html
File metadata and controls
218 lines (187 loc) · 7.86 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
<!DOCTYPE html>
<html>
<head>
<title>Auth Sandbox</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
max-width: 768px;
margin-left: auto;
margin-right: auto;
}
.box {
border: 1px solid #000;
border-radius: 2px;
padding: 1rem;
margin: 1rem;
}
.warning-box {
color: #e55;
border-color: #e55;
}
.code-input {
font-size: 2rem;
font-family: monospace;
margin-right: 1rem;
}
.hidden {
display: none !important;
}
.code-container {
display: flex;
flex-direction: row;
align-items: stretch;
}
.copy-notification {
color: #161;
background: #aea;
padding: 0.5rem;
border: 1px solid #161;
border-radius: 2px;
display: inline-block;
opacity: 0;
transition: opacity 250ms;
position: absolute;
left: 0;
top: 0;
margin: 1rem;
pointer-events:none;
}
.in {
opacity: 1;
}
</style>
</head>
<body>
<div class="loading">
<h1>Please wait...</h1>
<hr>
</div>
<div class="results hidden">
<h1>One more thing...</h1>
<h3>To finish signing in, copy the code below, and paste it into the app.</h3>
<div class="box warning-box">
<h2 style="margin-top: 0.4em;">Warning!</h2>
<p>This code will grant access to the account you just signed into.</p>
<ul>
<li>Only paste this into the app if you trust it</li>
<li><strong>NEVER share this code with anyone else - they may be trying to access your account!</strong></li>
</ul>
</div>
<div class="box code-box">
<p>
If you <span data-reveal="reveal">trust the app</span>, copy and paste this code into it. You can close this window when you are finished.
</p>
<div class="code-container">
<input class="code-input" id="codeField" type="text" value="the-test-code"/>
<button class="code-copy-button" type="button" data-action="copy" data-target="#codeField">Copy Params</button>
<button class="code-copy-button hidden" style="margin-left: 1rem;" type="button" data-action="copy-code" data-target="#codeField">Copy Code</button>
</div>
</div>
</div>
<div class="error hidden">
<div class="box warning-box">
<h2>Something went wrong</h2>
<p>We couldn't finish signing you in. Contact the app developer for help.</p>
</div>
</div>
<script>
"use strict";
(function(window) {
function main() {
let query = window.location.search;
if (!query) {
invalidCode();
return;
}
let params = query.substr(1); // strip the ?
if (params.indexOf("code=") == -1 && params.indexOf("id_token=" == -1) && params.indexOf("access_token" == -1)){
invalidCode();
return;
}
registerCopyButton();
registerRevealButton();
let codeElement = document.getElementById("codeField");
codeElement.value = params;
showResultsBox();
}
function registerCopyButton() {
let copies = document.querySelectorAll("[data-action]");
copies.forEach((ele) => {
ele.addEventListener('click', copy_onClick);
});
}
function registerRevealButton() {
let copies = document.querySelectorAll("[data-reveal]");
copies.forEach((ele) => {
ele.addEventListener('dblclick', reveal);
});
}
function reveal() {
var targets = document.querySelectorAll(".code-copy-button.hidden");
targets.forEach((ele) => {
ele.classList.remove("hidden");
});
}
function copy_onClick(event) {
let targetSelector = this.dataset["target"];
if (!targetSelector) {
console.warn("Copy button failed: cannot determine the target", {sender: this, event: event});
return;
}
let target = document.querySelector(targetSelector);
if (!target) {
console.warn("Copy button failed: could not find the target in the document", {selector: targetSelector, sender: this, event: event});
return;
}
console.log({sender: this, event: event});
// if copy just code
if (this.dataset["action"] === "copy-code") {
var search = new URLSearchParams(target.value);
var codeVal = search.get("code");
var start = target.value.indexOf(codeVal);
var end = start + codeVal.length;
target.focus();
target.setSelectionRange(start, end);
}
else {
target.select();
}
document.execCommand('copy');
let copiedNotification = document.createElement("div");
copiedNotification.innerText = "Copied to clipboard!";
copiedNotification.classList.add("copy-notification");
let rect = this.getBoundingClientRect();
copiedNotification.style.left = rect.left + "px";
copiedNotification.style.top = rect.top + "px";
document.body.appendChild(copiedNotification);
setTimeout(() => {
copiedNotification.classList.add('in');
}, 1);
setTimeout(() => {
copiedNotification.classList.remove('in');
setTimeout(() => {
copiedNotification.remove();
}, 300);
}, 3000);
}
function hideLoading() {
let loading = document.querySelector('.loading');
if(loading)
loading.classList.add('hidden');
}
function showResultsBox() {
hideLoading();
var results = document.querySelector('.results');
results.classList.remove('hidden');
}
function invalidCode() {
hideLoading();
var results = document.querySelector('.error');
results.classList.remove('hidden');
}
main();
})(window);
</script>
</body>
</html>