mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Security.Claims;
|
|
using Squidex.Infrastructure.Security;
|
|
|
|
namespace Squidex.Web
|
|
{
|
|
public static class Extensions
|
|
{
|
|
public static bool IsFrontendClient(this ClaimsPrincipal principal)
|
|
{
|
|
return principal.IsInClient(Constants.FrontendClient);
|
|
}
|
|
|
|
public static string GetClientId(this ClaimsPrincipal principal)
|
|
{
|
|
var clientId = principal.FindFirst(OpenIdClaims.ClientId)?.Value;
|
|
|
|
return clientId?.GetClientParts().ClientId;
|
|
}
|
|
|
|
public static (string App, string ClientId) GetClientParts(this string clientId)
|
|
{
|
|
var parts = clientId.Split(':', '~');
|
|
|
|
if (parts.Length == 1)
|
|
{
|
|
return (null, parts[0]);
|
|
}
|
|
|
|
if (parts.Length == 2)
|
|
{
|
|
return (parts[0], parts[1]);
|
|
}
|
|
|
|
return (null, null);
|
|
}
|
|
}
|
|
}
|
|
|