-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ErrorReceived to embedded auth server
Also style the default HTML site based on error/success values. Fixes #566
- Loading branch information
1 parent
ddb1dc0
commit 163200f
Showing
6 changed files
with
97 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,54 @@ | ||
function getUrlParams(hash, start) { | ||
const hashes = hash.slice(hash.indexOf(start) + 1).split('&') | ||
const hashes = hash.slice(hash.indexOf(start) + 1).split("&"); | ||
|
||
if (!hashes || hashes.length === 0 || hashes[0] === "") { | ||
return undefined; | ||
} | ||
|
||
const params = {} | ||
hashes.map(hash => { | ||
const [key, val] = hash.split('=') | ||
params[key] = decodeURIComponent(val) | ||
}) | ||
return params | ||
const params = {}; | ||
hashes.map((hash) => { | ||
const [key, val] = hash.split("="); | ||
params[key] = decodeURIComponent(val); | ||
}); | ||
return params; | ||
} | ||
|
||
function handleImplicitGrant() { | ||
const params = getUrlParams(window.location.hash, '#'); | ||
const params = getUrlParams(window.location.hash, "#"); | ||
if (!params) { | ||
return; | ||
} | ||
params.request_type = "token"; | ||
|
||
console.log("Sent request_type token to server", params); | ||
fetch('?' + new URLSearchParams(params).toString(), { | ||
method: 'POST', | ||
fetch("?" + new URLSearchParams(params).toString(), { | ||
method: "POST", | ||
}); | ||
} | ||
handleImplicitGrant(); | ||
|
||
function handleAuthenticationCode() { | ||
const params = getUrlParams(window.location.search, '?'); | ||
const params = getUrlParams(window.location.search, "?"); | ||
if (!params) { | ||
return; | ||
} | ||
params.request_type = "code"; | ||
|
||
console.log("Sent request_type code to server", params); | ||
fetch('?' + new URLSearchParams(params).toString(), { | ||
method: 'POST', | ||
fetch("?" + new URLSearchParams(params).toString(), { | ||
method: "POST", | ||
}); | ||
} | ||
handleAuthenticationCode(); | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
const errorContainer = document.querySelector("#error"); | ||
const successContainer = document.querySelector("#success"); | ||
const params = new URLSearchParams(window.location.search); | ||
|
||
if (params.has("error")) { | ||
errorContainer.classList.remove("hidden"); | ||
} else { | ||
successContainer.classList.remove("hidden"); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,54 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<title>Spotify Authorization</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link | ||
href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" | ||
rel="stylesheet" | ||
/> | ||
<link href="/auth_assets/main.css" rel="stylesheet" /> | ||
<script src="/auth_assets/main.js"></script> | ||
</head> | ||
|
||
<head> | ||
<meta charset='utf-8'> | ||
<meta http-equiv='X-UA-Compatible' content='IE=edge'> | ||
<title>Spotify Authorization</title> | ||
<meta name='viewport' content='width=device-width, initial-scale=1'> | ||
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet"> | ||
<link href="/auth_assets/main.css" rel="stylesheet"> | ||
<script src="/auth_assets/main.js"></script> | ||
</head> | ||
|
||
<body> | ||
<main> | ||
<div class="flex justify-center flex-wrap logo"> | ||
<div class="w-1/8"> | ||
<img src="/auth_assets/logo.svg" width="120" height="120" /> | ||
<body> | ||
<main> | ||
<div class="flex justify-center flex-wrap logo"> | ||
<div class="w-1/8"> | ||
<img src="/auth_assets/logo.svg" width="120" height="120" /> | ||
</div> | ||
</div> | ||
</div> | ||
<h1 class="text-4xl">Success!</h1> | ||
<p class="text-xl mx-2"> | ||
Spotify Authorization was successful. You can close this tab and go back to your app. | ||
</p> | ||
<div class="text-center py-4 lg:px-4 my-6"> | ||
<div class="p-2 bg-teal-800 items-center text-teal-100 leading-none lg:rounded-full flex lg:inline-flex" | ||
role="alert"> | ||
<span class="flex rounded-full bg-teal-500 uppercase px-2 py-1 text-xs font-bold mr-3">Tip</span> | ||
<span class="font-semibold mr-2 text-left flex-auto"> | ||
If the app does not detect the authorization, make sure you use one of the following supported Browsers: | ||
<b>Chrome</b>, <b>Edge</b> or <b>Firefox</b> | ||
</span> | ||
<div id="error" class="hidden"> | ||
<h1 class="text-4xl">Error!</h1> | ||
<p class="text-xl mx-2"> | ||
Spotify Authorization was not successful. You may want to retry. | ||
</p> | ||
</div> | ||
</div> | ||
</main> | ||
</body> | ||
|
||
<div id="success" class="hidden"> | ||
<h1 class="text-4xl">Success!</h1> | ||
<p class="text-xl mx-2"> | ||
Spotify Authorization was successful. You can close this tab and go | ||
back to your app. | ||
</p> | ||
</div> | ||
<div class="text-center py-4 lg:px-4 my-6"> | ||
<div | ||
class="p-2 bg-teal-800 items-center text-teal-100 leading-none lg:rounded-full flex lg:inline-flex" | ||
role="alert" | ||
> | ||
<span | ||
class="flex rounded-full bg-teal-500 uppercase px-2 py-1 text-xs font-bold mr-3" | ||
>Tip</span | ||
> | ||
<span class="font-semibold mr-2 text-left flex-auto"> | ||
If the app does not detect the authorization, make sure you use one | ||
of the following supported Browsers: | ||
<b>Chrome</b>, <b>Edge</b> or <b>Firefox</b> | ||
</span> | ||
</div> | ||
</div> | ||
</main> | ||
</body> | ||
</html> |