-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathyoutube_auth.html
More file actions
88 lines (77 loc) · 3.17 KB
/
youtube_auth.html
File metadata and controls
88 lines (77 loc) · 3.17 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
---
layout: app
title: SAMMI YouTube Live Authorization
permalink: integrations/youtube/auth
---
<div id="authLink">
<h4> Step 1: Authorize the integration</h4>
Please <a href="https://accounts.google.com/o/oauth2/v2/auth?client_id=777753337212-ijh2ablbkkcn3tpg2fqoq4ap5cs56bgq.apps.googleusercontent.com&redirect_uri=https://sammi.solutions/docs/integrations/youtube/auth&response_type=code&scope=https://www.googleapis.com/auth/youtube&access_type=offline&prompt=consent"><button class="ytButton" type="button"></button></a> and authorize SAMMI. Wait until you're redirected back to this page.<br>
<p>Note that you will be presented with a screen to authorize LioranBoard and not SAMMI. This is okay, it will be changed later to reflect our new name.</p>
By authorizing the integration you're agreeing to our <a href="https://sammi.solutions/docs/integrations/youtube#privacypolicy">Privacy Policy</a>.
</div>
<div id="setRefreshToken" class="my-2">
<h4> Step 2: Save your refresh token</h4>
<div id="tokenDiv"><span>Your Refresh token: </span>
<input type="password" class="form-control" id="token"> <button class='btn btn-success mx-2 my-2' id='copyCred'>Copy to Clipboard</button></div>
<div id="tokenError">
</div>
<div id="info"><p>
</div>
</div>
<script>
hideContent('setRefreshToken');
const urlString = window.location.href;
const url = new URL(urlString);
const code = url.searchParams.get('code');
if (code) {
Auth()
.then((response) => Update(true, response))
.catch((e) => Update(false, e));
}
async function Auth() {
const response = await fetch(`https://ryffwm1pmc.execute-api.us-west-1.amazonaws.com/YouTubeStage/refreshtoken?code=${code}&redirect_uri=https://sammi.solutions/docs/integrations/youtube/auth`);
let content;
if (!response.ok) {
const data = await response.json();
const error = data.error || data.error_description || 'Something went wrong.';
throw error;
} else {
content = await response.json();
}
return content;
}
function Update(success, response) {
displayContent('setRefreshToken');
if (success) {
hideContent('authLink')
document.getElementById('token').value = response.refresh_token;
document.getElementById('copyCred').addEventListener('click', () => {
CopyToClipboard(response.refresh_token, 'copyCred');
});
} else {
hideContent('tokenDiv');
hideContent('info');
document.getElementById('tokenError').innerHTML = `<p>Error retrieving refresh token: <span style="color:red">${response}</span>. <br>Please try to authorize the app again.<p>`;
displayContent('authLink');
}
}
function displayContent(id) {
const elem = document.getElementById(id);
elem.style.display = 'block';
}
function hideContent(id) {
const elem = document.getElementById(id);
elem.style.display = 'none';
}
function CopyToClipboard(value, name) {
const copyhelper = document.createElement('input');
copyhelper.className = 'copyhelper';
document.body.appendChild(copyhelper);
copyhelper.value = value;
copyhelper.select();
document.execCommand('copy');
document.body.removeChild(copyhelper);
const button = document.querySelector(`#${name}`);
button.innerHTML = 'Copied to Clipboard';
}
</script>