Add logout support (#9)
* Add logout support * Use token as json payload * Comment
This commit is contained in:
1 parent
8aa1d1ae51
commit
22dfe785f1
4 files changed
+52
-7
No files matched your search
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Play video by ID/URL in web app
|
||||
- Metadata to Video Player
|
||||
- Support for DASH and Live videos
|
||||
- Log out button to web app
|
||||
|
||||
### Fixed
|
||||
- Bug where Settings page and home page are both visible, if settings page is selected, and user logs in.
|
||||
|
||||
@@ -5,6 +5,18 @@ namespace Http
|
||||
function new()
|
||||
super()
|
||||
|
||||
m.Get("/api/command/logout", function(context as object) as boolean
|
||||
response = context.response
|
||||
server = context.server
|
||||
|
||||
if Invidious.Logout()
|
||||
server.task.top.login = false
|
||||
end if
|
||||
|
||||
response.Default(204, "OK")
|
||||
return true
|
||||
end function)
|
||||
|
||||
m.Get("*", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
@@ -24,7 +36,7 @@ namespace Http
|
||||
' 302 to prevent redirection to current host permanently
|
||||
response.Redirect(`${Invidious.GetCurrentHost()}/watch?v=${components["v"]}`, 302)
|
||||
else
|
||||
response.Default(200, "OK")
|
||||
response.Default(204, "OK")
|
||||
end if
|
||||
return true
|
||||
end if
|
||||
|
||||
@@ -19,9 +19,10 @@ namespace Invidious
|
||||
const SEARCH_SUGGEST_ENDPOINT = "/api/v1/search/suggestions"
|
||||
const SEARCH_ENDPOINT = "/api/v1/search"
|
||||
|
||||
const AUTH_SCOPE = "GET:feed,GET:playlists"
|
||||
const AUTH_SCOPE = "GET:feed,GET:playlists,POST:tokens/unregister"
|
||||
const AUTH_FEED = "/api/v1/auth/feed"
|
||||
const AUTH_PLAYLISTS = "/api/v1/auth/playlists"
|
||||
const AUTH_TOKENS_UNREGISTER = "/api/v1/auth/tokens/unregister"
|
||||
|
||||
function DefaultArgs() as object
|
||||
return {
|
||||
@@ -200,4 +201,26 @@ namespace Invidious
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function Logout() as boolean
|
||||
headers = Invidious.GetAuthenticationHeaders()
|
||||
if headers = invalid
|
||||
return false
|
||||
end if
|
||||
|
||||
url = `${Invidious.API_URL}${Invidious.AUTH_TOKENS_UNREGISTER}`
|
||||
|
||||
' token is already valid json that contains the "session" key needed by the unregister endpoint
|
||||
token = RegistryUtils.Read("invidious_token")
|
||||
headers["Content-Type"] = "application/json"
|
||||
args = {
|
||||
headers: headers,
|
||||
data: token
|
||||
}
|
||||
|
||||
Requests().post(url, args)
|
||||
|
||||
RegistryUtils.Delete("invidious_token")
|
||||
return true
|
||||
end function
|
||||
end namespace
|
||||
+14
-5
@@ -17,8 +17,8 @@
|
||||
<input type="text" id="video-id" name="video-id" style="min-width:300px;">
|
||||
|
||||
<h4 id="logged-in">Logged In: </h4>
|
||||
<button style="visibility: hidden" id="login-button" onclick="Login()">Login</button>
|
||||
<button style="visibility: hidden" id="logout-button">Logout</button>
|
||||
<button style="display: none" id="login-button" onclick="Login()">Login</button>
|
||||
<button style="display: none" id="logout-button" onclick="Logout()">Logout</button>
|
||||
|
||||
<h5>Instructions</h5>
|
||||
<ul>
|
||||
@@ -43,6 +43,16 @@
|
||||
window.location = window.appState.invidious.auth_url
|
||||
}
|
||||
|
||||
function Logout() {
|
||||
fetch('/api/command/logout')
|
||||
.then(function (response) {
|
||||
window.location.reload();
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert(err)
|
||||
});
|
||||
}
|
||||
|
||||
function PlayVideo() {
|
||||
let v = document.getElementById('video-id').value
|
||||
if (IsValidHttpUrl(v)) {
|
||||
@@ -128,9 +138,8 @@ ${JSON.stringify(window.appState.device, null, 2)}
|
||||
document.getElementById("host").innerText = appState.invidious.host
|
||||
document.getElementById("host").href = appState.invidious.host
|
||||
|
||||
document.getElementById("login-button").style.visibility = appState.invidious.logged_in ? "hidden" : "visible";
|
||||
// TODO: log out feature
|
||||
// document.getElementById("logout-button").style.visibility = appState.invidious.logged_in ? "hidden" : "visible";
|
||||
document.getElementById("login-button").style.display = appState.invidious.logged_in ? "none" : "block";
|
||||
document.getElementById("logout-button").style.display = !appState.invidious.logged_in ? "none" : "block";
|
||||
|
||||
document.getElementById("feedback-url").href = CreateGithubIssueUrl()
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user