diff options
| author | Claus Vium <cvium@users.noreply.github.com> | 2020-11-08 08:20:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-08 08:20:50 +0100 |
| commit | c17f84ae484b9018953bfc2904819f30222b9c32 (patch) | |
| tree | 405b770e78681b04eabb091f476c85c06635a17e /Jellyfin.Api/Helpers/ClaimHelpers.cs | |
| parent | 1bd5f780250993b01e551699f54f703032a0d1dd (diff) | |
| parent | 8b83e4e972243db618972e33705b959bf98ca9f4 (diff) | |
Merge pull request #4330 from crobibero/api-key-auth
Fix ApiKey authentication
Diffstat (limited to 'Jellyfin.Api/Helpers/ClaimHelpers.cs')
| -rw-r--r-- | Jellyfin.Api/Helpers/ClaimHelpers.cs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Jellyfin.Api/Helpers/ClaimHelpers.cs b/Jellyfin.Api/Helpers/ClaimHelpers.cs index df235ced2..29e6b4193 100644 --- a/Jellyfin.Api/Helpers/ClaimHelpers.cs +++ b/Jellyfin.Api/Helpers/ClaimHelpers.cs @@ -63,6 +63,19 @@ namespace Jellyfin.Api.Helpers public static string? GetToken(in ClaimsPrincipal user) => GetClaimValue(user, InternalClaimTypes.Token); + /// <summary> + /// Gets a flag specifying whether the request is using an api key. + /// </summary> + /// <param name="user">Current claims principal.</param> + /// <returns>The flag specifying whether the request is using an api key.</returns> + public static bool GetIsApiKey(in ClaimsPrincipal user) + { + var claimValue = GetClaimValue(user, InternalClaimTypes.IsApiKey); + return !string.IsNullOrEmpty(claimValue) + && bool.TryParse(claimValue, out var parsedClaimValue) + && parsedClaimValue; + } + private static string? GetClaimValue(in ClaimsPrincipal user, string name) { return user?.Identities |
