Add nouce to invidious login
This commit is contained in:
1 parent
eea5392d9d
commit
b02d5d6a10
10 files changed
+57
-23
No files matched your search
@@ -19,9 +19,9 @@ function OnNodeReady()
|
|||||||
isValidAddress = not StringUtils.IsNullOrEmpty(address)
|
isValidAddress = not StringUtils.IsNullOrEmpty(address)
|
||||||
if isValidAddress
|
if isValidAddress
|
||||||
url = `${address}/invidious/login`
|
url = `${address}/invidious/login`
|
||||||
serverUrl = m.top.serverUrl
|
profileId = m.top.profileId
|
||||||
if not StringUtils.IsNullOrEmpty(serverUrl)
|
if not StringUtils.IsNullOrEmpty(profileId)
|
||||||
url = UrlUtils.AppendQueryParams(url, { server: serverUrl })
|
url = UrlUtils.AppendQueryParams(url, { profile: profileId })
|
||||||
end if
|
end if
|
||||||
m.top.url = url
|
m.top.url = url
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<field id="webServer" type="node" bind="/WebServer" />
|
<field id="webServer" type="node" bind="/WebServer" />
|
||||||
<field id="profilesService" type="node" bind="/ProfilesService" />
|
<field id="profilesService" type="node" bind="/ProfilesService" />
|
||||||
<field id="url" type="string" onChange="OnUrlSet" />
|
<field id="url" type="string" onChange="OnUrlSet" />
|
||||||
<field id="serverUrl" type="string" />
|
<field id="profileId" type="string" />
|
||||||
<field id="alwaysOnTop" type="boolean" />
|
<field id="alwaysOnTop" type="boolean" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import "pkg:/source/utils/Types.bs"
|
|||||||
|
|
||||||
namespace LoginUtils
|
namespace LoginUtils
|
||||||
|
|
||||||
function ShowInvidiousLoginDialog(serverUrl = "" as string) as void
|
function ShowInvidiousLoginDialog(profileId = "" as string) as void
|
||||||
dialog = CreateObject("roSGNode", "InvidiousLoginDialog")
|
dialog = CreateObject("roSGNode", "InvidiousLoginDialog")
|
||||||
dialog.serverUrl = serverUrl
|
dialog.profileId = profileId
|
||||||
dialog@.BindNode()
|
dialog@.BindNode()
|
||||||
m.top.getScene().dialog = dialog
|
m.top.getScene().dialog = dialog
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ function Login() as void
|
|||||||
|
|
||||||
backendType = content.type
|
backendType = content.type
|
||||||
if backendType = "invidious"
|
if backendType = "invidious"
|
||||||
LoginUtils.ShowInvidiousLoginDialog(ValidString(content.serverUrl))
|
LoginUtils.ShowInvidiousLoginDialog(content.id)
|
||||||
else if backendType = "youtube"
|
else if backendType = "youtube"
|
||||||
LoginUtils.ShowYouTubeLoginDialog()
|
LoginUtils.ShowYouTubeLoginDialog()
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -12,7 +12,3 @@ end function
|
|||||||
function GetInvidiousInstance(_unused as dynamic) as string
|
function GetInvidiousInstance(_unused as dynamic) as string
|
||||||
return m.service.GetInvidiousInstance()
|
return m.service.GetInvidiousInstance()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetAuthorizeTokenLink(serverUrl as dynamic) as dynamic
|
|
||||||
return m.service.GetAuthorizeTokenLink(ValidString(serverUrl))
|
|
||||||
end function
|
|
||||||
@@ -9,6 +9,5 @@
|
|||||||
|
|
||||||
<function name="GetInstance" />
|
<function name="GetInstance" />
|
||||||
<function name="GetInvidiousInstance" />
|
<function name="GetInvidiousInstance" />
|
||||||
<function name="GetAuthorizeTokenLink" />
|
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -750,7 +750,7 @@ namespace Invidious
|
|||||||
return request.Await()
|
return request.Await()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetAuthorizeTokenLink(serverUrl = "" as string) as dynamic
|
function GetAuthorizeTokenLink(serverUrl as string, loginNonce as string) as dynamic
|
||||||
instance = serverUrl
|
instance = serverUrl
|
||||||
if StringUtils.IsNullOrEmpty(instance)
|
if StringUtils.IsNullOrEmpty(instance)
|
||||||
instance = m.GetInvidiousInstance()
|
instance = m.GetInvidiousInstance()
|
||||||
@@ -769,7 +769,7 @@ namespace Invidious
|
|||||||
|
|
||||||
expire = TimeUtils.Now().AsSeconds() + Invidious.TOKEN_TIMESPAN
|
expire = TimeUtils.Now().AsSeconds() + Invidious.TOKEN_TIMESPAN
|
||||||
|
|
||||||
callbackUrl = `${address}${Invidious.TOKEN_CALLBACK}?ref=${instance}`.EncodeUriComponent()
|
callbackUrl = `${address}${Invidious.TOKEN_CALLBACK}?ref=${instance}&nonce=${loginNonce}`.EncodeUriComponent()
|
||||||
scope = `${Invidious.AUTH_SCOPES}`.EncodeUriComponent()
|
scope = `${Invidious.AUTH_SCOPES}`.EncodeUriComponent()
|
||||||
return `${invidiousHost}/authorize_token?scopes=${scope}&callback_url=${callbackUrl}&expire=${expire}`
|
return `${invidiousHost}/authorize_token?scopes=${scope}&callback_url=${callbackUrl}&expire=${expire}`
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -21,9 +21,23 @@ namespace Http
|
|||||||
request = context.request
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
|
|
||||||
server = ValidString(request.query["server"])
|
' The login link carries the nonce, so its server comes from the
|
||||||
|
' device (a profile's, or the configured instance), never the URL.
|
||||||
|
server = ""
|
||||||
|
profileId = request.query["profile"]
|
||||||
|
if profileId <> invalid
|
||||||
|
server = m.GetProfileServer(ValidString(profileId))
|
||||||
|
if server = invalid
|
||||||
|
response.Default(400, "Unknown profile")
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
authLink = m.invidiousNode@.GetAuthorizeTokenLink(server)
|
if m.loginNonce = invalid
|
||||||
|
m.loginNonce = CreateObject("roDeviceInfo").GetRandomUUID()
|
||||||
|
end if
|
||||||
|
|
||||||
|
authLink = m.invidiousService.GetAuthorizeTokenLink(server, m.loginNonce)
|
||||||
if authLink = invalid
|
if authLink = invalid
|
||||||
response.Default(503, "Invidious server not configured")
|
response.Default(503, "Invidious server not configured")
|
||||||
return true
|
return true
|
||||||
@@ -37,7 +51,16 @@ namespace Http
|
|||||||
request = context.request
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
|
|
||||||
if request.query["token"] <> invalid and request.query["ref"] <> invalid
|
if request.query["token"] <> invalid and request.query["ref"] <> invalid and request.query["username"] <> invalid
|
||||||
|
' The callback is a plain GET any web page can trigger, so it only
|
||||||
|
' accepts a login that went through a link this device handed out.
|
||||||
|
nonce = request.query["nonce"]
|
||||||
|
if m.loginNonce = invalid or not IsString(nonce) or nonce <> m.loginNonce
|
||||||
|
response.Default(403, "Invalid login link. Please start the login again.")
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
m.loginNonce = invalid
|
||||||
|
|
||||||
' Invidious encodes token and username twice
|
' Invidious encodes token and username twice
|
||||||
token = request.query["token"].DecodeUriComponent().DecodeUriComponent()
|
token = request.query["token"].DecodeUriComponent().DecodeUriComponent()
|
||||||
username = request.query["username"].DecodeUriComponent().DecodeUriComponent()
|
username = request.query["username"].DecodeUriComponent().DecodeUriComponent()
|
||||||
@@ -54,6 +77,17 @@ namespace Http
|
|||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function GetProfileServer(profileId as string) as dynamic
|
||||||
|
profilesDto = m.profilesNode@.GetProfilesDto(false)
|
||||||
|
profiles = profilesDto.profiles
|
||||||
|
for each profile in profiles
|
||||||
|
if profile.id = profileId and profile.type = "invidious"
|
||||||
|
return profile.serverUrl
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
return invalid
|
||||||
|
end function
|
||||||
|
|
||||||
' This is an endpoint allowing the web app to make an authenticated request
|
' This is an endpoint allowing the web app to make an authenticated request
|
||||||
' without needing the Invidious token
|
' without needing the Invidious token
|
||||||
' This is a GET not a POST for better caching
|
' This is a GET not a POST for better caching
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ namespace Http
|
|||||||
state["invidious"] = {
|
state["invidious"] = {
|
||||||
instance: m.invidiousNode@.GetInstance()
|
instance: m.invidiousNode@.GetInstance()
|
||||||
invidious_instance: m.invidiousNode@.GetInvidiousInstance()
|
invidious_instance: m.invidiousNode@.GetInvidiousInstance()
|
||||||
auth_url: m.invidiousNode@.GetAuthorizeTokenLink()
|
|
||||||
}
|
}
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
|||||||
@@ -23,14 +23,12 @@
|
|||||||
let profiles = [];
|
let profiles = [];
|
||||||
let currentProfile;
|
let currentProfile;
|
||||||
|
|
||||||
let authUrl;
|
|
||||||
let currentInstance;
|
let currentInstance;
|
||||||
let currentInstanceName;
|
let currentInstanceName;
|
||||||
|
|
||||||
let accordionState = null;
|
let accordionState = null;
|
||||||
|
|
||||||
playletStateStore.subscribe((value) => {
|
playletStateStore.subscribe((value) => {
|
||||||
authUrl = value?.invidious?.auth_url;
|
|
||||||
currentInstance = value?.invidious?.invidious_instance || "";
|
currentInstance = value?.invidious?.invidious_instance || "";
|
||||||
if (!currentInstance) {
|
if (!currentInstance) {
|
||||||
const trFn = get(translate);
|
const trFn = get(translate);
|
||||||
@@ -72,12 +70,16 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!authUrl) {
|
window.location.href = "/invidious/login";
|
||||||
alert("Error with login, please refresh the page.");
|
}
|
||||||
|
|
||||||
|
function relogin(profile) {
|
||||||
|
if (profile.type === "youtube") {
|
||||||
|
loginToYoutube();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.location = authUrl;
|
window.location.href = `/invidious/login?profile=${encodeURIComponent(profile.id)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loginToYoutube() {
|
function loginToYoutube() {
|
||||||
@@ -133,6 +135,10 @@
|
|||||||
"The session has expired. Please sign in again with this profile, or switch to another profile."
|
"The session has expired. Please sign in again with this profile, or switch to another profile."
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
on:click={() => relogin(profile)}
|
||||||
|
class="btn btn-primary m-1">{$translate("Login")}</button
|
||||||
|
>
|
||||||
{/if}
|
{/if}
|
||||||
{#if profile.id !== currentProfile?.id}
|
{#if profile.id !== currentProfile?.id}
|
||||||
<button
|
<button
|
||||||
|
|||||||
Reference in new issue
Block a user