From 332f62d76e2287c0359202fc2bd184ec0cd17f77 Mon Sep 17 00:00:00 2001 From: Sambhav Saggi <17993169+9p4@users.noreply.github.com> Date: Tue, 23 Aug 2022 18:18:42 -0400 Subject: [PATCH 1/4] feat: allow configuration of preferred username claim (#47) --- SSO-Auth/Api/SSOController.cs | 4 ++-- SSO-Auth/Config/PluginConfiguration.cs | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/SSO-Auth/Api/SSOController.cs b/SSO-Auth/Api/SSOController.cs index 85004c2..9896140 100644 --- a/SSO-Auth/Api/SSOController.cs +++ b/SSO-Auth/Api/SSOController.cs @@ -104,7 +104,7 @@ public class SSOController : ControllerBase foreach (var claim in result.User.Claims) { - if (claim.Type == "preferred_username") + if (claim.Type == (config.DefaultUsernameClaim ?? "preferred_username")) { StateManager[state].Username = claim.Value; if (config.Roles.Length == 0) @@ -186,7 +186,7 @@ public class SSOController : ControllerBase } } - // If the provider doesn't support preferred_username, then use sub + // If the provider doesn't support the preferred username claim, then use the sub claim if (!StateManager[state].Valid) { foreach (var claim in result.User.Claims) diff --git a/SSO-Auth/Config/PluginConfiguration.cs b/SSO-Auth/Config/PluginConfiguration.cs index bf9a43b..f254806 100644 --- a/SSO-Auth/Config/PluginConfiguration.cs +++ b/SSO-Auth/Config/PluginConfiguration.cs @@ -217,6 +217,11 @@ public class OidConfig } set => _canonicalLinks = value; } + + /// + /// Gets or sets the default username claim when creating new accounts. + /// + public string DefaultUsernameClaim { get; set; } } /// From a90e0359e461631ad14dae700ca961bf6ed29ec2 Mon Sep 17 00:00:00 2001 From: Sambhav Saggi <17993169+9p4@users.noreply.github.com> Date: Tue, 23 Aug 2022 18:26:58 -0400 Subject: [PATCH 2/4] feat: add config page for preferred username config --- SSO-Auth/Config/configPage.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/SSO-Auth/Config/configPage.html b/SSO-Auth/Config/configPage.html index 5d65dad..857dc6a 100644 --- a/SSO-Auth/Config/configPage.html +++ b/SSO-Auth/Config/configPage.html @@ -437,6 +437,24 @@ + + Set default username claim: + + + The default username claim to use from OpenID by default. + If it is not set, it defaults to preferred_username. + + + Date: Tue, 23 Aug 2022 18:57:57 -0400 Subject: [PATCH 3/4] style: run prettier --- SSO-Auth/Config/configPage.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SSO-Auth/Config/configPage.html b/SSO-Auth/Config/configPage.html index 857dc6a..a5b3d7d 100644 --- a/SSO-Auth/Config/configPage.html +++ b/SSO-Auth/Config/configPage.html @@ -450,8 +450,9 @@ class="sso-text" /> - The default username claim to use from OpenID by default. - If it is not set, it defaults to preferred_username. + The default username claim to use from OpenID by default. If + it is not set, it defaults to + preferred_username. From d5925fc1de0fce674f0fecdfb77ad3b7dce7c2d6 Mon Sep 17 00:00:00 2001 From: Sambhav Saggi <17993169+9p4@users.noreply.github.com> Date: Tue, 23 Aug 2022 19:38:01 -0400 Subject: [PATCH 4/4] docs: add custom username claim api doc --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c60a7c4..fa32af7 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,7 @@ These all require authorization. Append an API key to the end of the request: `c - For some OIDC providers (For example, [authelia](https://github.com/9p4/jellyfin-plugin-sso/issues/23#issuecomment-1112237616)), additional scopes may be required in order to validate group membership in role claim. - Leave empty to only request the default scopes. - `defaultProvider`: string. The set provider then gets assigned to the user after they have logged in. If it is not set, nothing is changed. With this, a user can login with SSO but is still able to log in via other providers later. See the `Unregister` endpoint. + - `defaultUsernameClaim`: string. The provider will use the claim to create the users' usernames. If not set, it fallbacks to `preferred_username`. - GET `OID/Del/PROVIDER_NAME`: This removes a configuration for OpenID for a given provider name. - GET `OID/Get`: Lists the configurations currently available. - GET `OID/States`: Lists currently active OpenID flows in progress.
preferred_username