Add logout support (#9)

* Add logout support

* Use token as json payload

* Comment
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2022-11-22 18:33:55 -05:00
1 parent 8aa1d1ae51
commit 22dfe785f1
4 files changed
+52 -7

No files matched your search

+24 -1
View File
@@ -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