lazy provider linking frontend

Use ApiClient.getUrl to get base urls for links

Per
https://github.com/9p4/jellyfin-plugin-sso/pull/34#discussion_r885060442
This commit is contained in:
Matthew Strasiotto
2022-08-14 13:13:06 +10:00
committed by Matthew Strasitoto
parent c5e1644d17
commit e7d70b8326
5 changed files with 133 additions and 0 deletions
+20
View File
@@ -306,6 +306,26 @@ public class SSOController : ControllerBase
return Ok(SSOPlugin.Instance.Configuration.OidConfigs); return Ok(SSOPlugin.Instance.Configuration.OidConfigs);
} }
/// <summary>
/// Lists the OpenID providers names only.
/// </summary>
/// <returns>The list of OpenID configurations.</returns>
[HttpGet("OID/GetNames")]
public ActionResult OidProviderNames()
{
return Ok(SSOPlugin.Instance.Configuration.OidConfigs.Keys);
}
/// <summary>
/// Lists the SAML providers names only.
/// </summary>
/// <returns>The list of OpenID configurations.</returns>
[HttpGet("SAML/GetNames")]
public ActionResult SamlProviderNames()
{
return Ok(SSOPlugin.Instance.Configuration.SamlConfigs.Keys);
}
/// <summary> /// <summary>
/// This is a debug endpoint to list all running OpenID flows. Requires administrator privileges. /// This is a debug endpoint to list all running OpenID flows. Requires administrator privileges.
/// </summary> /// </summary>
+54
View File
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>SSO</title>
</head>
<body>
<div
id="sso-config-page"
data-role="page"
class="page type-interior pluginConfigurationPage esqConfigurationPage"
data-controller="__plugin/SSO-Auth-linking.js"
>
<div data-role="content">
<div class="content-primary">
<div class="sectionTitleContainer flex align-items-center">
<h2 class="sectionTitle">SSO Settings:</h2>
<a
is="emby-button"
class="raised button-alt headerHelpButton"
target="_blank"
href="https://github.com/9p4/jellyfin-plugin-sso"
>${Help}</a
>
</div>
<p>
Use the following buttons to link your jellyfin account to any one
of the SSO providers. Please note that deletion is currently only
available by API.
</p>
<p>
See the
<a
is="emby-linkbutton"
href="https://github.com/9p4/jellyfin-plugin-sso"
class="button-link"
>help page</a
>
and
<a
is="emby-linkbutton"
href="https://github.com/9p4/jellyfin-plugin-sso/projects/1"
class="button-link"
>roadmap
</a>
for more information.
</p>
<div class="verticalSection" title="Link a provider">
<div id="sso-provider-list"></div>
</div>
</div>
</div>
</div>
</body>
</html>
+46
View File
@@ -0,0 +1,46 @@
const ssoConfigLinking = {
pluginUniqueId: "505ce9d1-d916-42fa-86ca-673ef241d7df",
loadProviders: (view) => {
const provider_list_id = "sso-provider-list";
var provider_list = view.querySelector("#" + provider_list_id);
provider_list.innerHTML = "";
fetch(new Request(ApiClient.getUrl("sso/OID/GetNames"))).then((resp) => {
resp.json().then((config_names) => {
ssoConfigLinking.loadProviderList(provider_list, config_names, "oid");
});
});
fetch(new Request(ApiClient.getUrl("sso/SAML/GetNames"))).then((resp) => {
resp.json().then((config_names) => {
ssoConfigLinking.loadProviderList(provider_list, config_names, "saml");
});
});
},
loadProviderList: (element, providers, provider_mode) => {
providers.forEach((provider_name) => {
var provider_link = document.createElement("a");
provider_link.classList.add("raised");
provider_link.classList.add("block");
provider_link.classList.add("emby-button");
//const provider_name_css = ssoConfigLinking.safeCSSId(provider_name);
//provider_link.id = "sso-provider-" + provider_name_css;
//provider_link.classList.add("sso-provider-" + provider_name_css);
provider_link.classList.add("sso-provider");
provider_link.text = provider_name;
provider_link.href = ApiClient.getUrl(
`/SSO/${provider_mode}/p/${provider_name}?isLinking=true`
);
element.appendChild(provider_link);
});
},
};
export default function (view) {
ssoConfigLinking.loadProviders(view);
}
+3
View File
@@ -13,9 +13,12 @@
<None Remove="Config\configPage.html" /> <None Remove="Config\configPage.html" />
<None Remove="Config\config.js" /> <None Remove="Config\config.js" />
<None Remove="Config\style.css" /> <None Remove="Config\style.css" />
<None Remove="Config\linking.html" />
<EmbeddedResource Include="Config\configPage.html" /> <EmbeddedResource Include="Config\configPage.html" />
<EmbeddedResource Include="Config\config.js" /> <EmbeddedResource Include="Config\config.js" />
<EmbeddedResource Include="Config\style.css" /> <EmbeddedResource Include="Config\style.css" />
<EmbeddedResource Include="Config\linking.html" />
<EmbeddedResource Include="Config\linking.js" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+10
View File
@@ -62,6 +62,16 @@ public class SSOPlugin : BasePlugin<PluginConfiguration>, IHasWebPages
Name = Name + ".css", Name = Name + ".css",
EmbeddedResourcePath = $"{GetType().Namespace}.Config.style.css" EmbeddedResourcePath = $"{GetType().Namespace}.Config.style.css"
}, },
new PluginPageInfo
{
Name = Name + "-linking",
EmbeddedResourcePath = $"{GetType().Namespace}.Config.linking.html"
},
new PluginPageInfo
{
Name = Name + "-linking.js",
EmbeddedResourcePath = $"{GetType().Namespace}.Config.linking.js"
},
}; };
} }
} }