mirror of
https://github.com/9p4/jellyfin-plugin-sso
synced 2026-10-25 22:39:18 +11:00
Merge pull request #74 from 9p4/custom-username-claim
feat: allow configuration of preferred username claim
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -109,7 +109,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)
|
||||
@@ -191,7 +191,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)
|
||||
|
||||
@@ -217,6 +217,11 @@ public class OidConfig
|
||||
}
|
||||
set => _canonicalLinks = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default username claim when creating new accounts.
|
||||
/// </summary>
|
||||
public string DefaultUsernameClaim { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -437,6 +437,25 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="inputContainer">
|
||||
<label
|
||||
class="inputLabel inputLabelUnfocused"
|
||||
for="DefaultUsernameClaim"
|
||||
>Set default username claim:</label
|
||||
>
|
||||
<input
|
||||
is="emby-input"
|
||||
id="DefaultUsernameClaim"
|
||||
type="text"
|
||||
class="sso-text"
|
||||
/>
|
||||
<div class="fieldDescription">
|
||||
The default username claim to use from OpenID by default. If
|
||||
it is not set, it defaults to
|
||||
<code>preferred_username</code>.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
id="SaveProvider"
|
||||
is="emby-button"
|
||||
|
||||
Reference in New Issue
Block a user