diff --git a/CHANGELOG.md b/CHANGELOG.md index fa432b8e..7102d5c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/components/WebServer/Middleware/CommandsApiRouter.bs b/src/components/WebServer/Middleware/CommandsApiRouter.bs index 357abd55..5e4c2aea 100644 --- a/src/components/WebServer/Middleware/CommandsApiRouter.bs +++ b/src/components/WebServer/Middleware/CommandsApiRouter.bs @@ -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 diff --git a/src/source/services/Invidious.bs b/src/source/services/Invidious.bs index 7a2b5744..36065550 100644 --- a/src/source/services/Invidious.bs +++ b/src/source/services/Invidious.bs @@ -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 diff --git a/src/www/index.html b/src/www/index.html index c25f5563..fc96543e 100644 --- a/src/www/index.html +++ b/src/www/index.html @@ -17,8 +17,8 @@