Skip to content

Commit

Permalink
Remove use of orgclaim in claims extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed Jun 5, 2024
1 parent e1e4d7f commit 56e91a1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static class ClaimsPrincipalExtensions
private const char IdDelimiter = ':';
private const string IdPrefix = "0192";
private const string AltinnClaimPrefix = "urn:altinn:";
private const string OrgClaim = "urn:altinn:org";
private const string IdportenAuthLevelClaim = "acr";
private const string AltinnAutorizationDetailsClaim = "authorization_details";
private const string AttributeIdSystemUser = "urn:altinn:systemuser";
Expand Down Expand Up @@ -224,7 +223,6 @@ public static IEnumerable<Claim> GetIdentifyingClaims(this List<Claim> claims) =
c.Type == PidClaim ||
c.Type == ConsumerClaim ||
c.Type == SupplierClaim ||
c.Type == OrgClaim ||
c.Type == IdportenAuthLevelClaim ||
c.Type.StartsWith(AltinnClaimPrefix, StringComparison.Ordinal)
).OrderBy(c => c.Type);
Expand Down Expand Up @@ -253,29 +251,17 @@ public static (UserIdType, string externalId) GetUserType(this ClaimsPrincipal c
}

if (claimsPrincipal.HasScope(ServiceProviderScope) &&
claimsPrincipal.TryGetServiceOwnerShortName(out externalId))
claimsPrincipal.TryGetOrganizationNumber(out externalId))
{
return (UserIdType.ServiceOwner, externalId);
}

return (UserIdType.Unknown, string.Empty);
}

private static bool TryGetServiceOwnerShortName(this ClaimsPrincipal claimsPrincipal, [NotNullWhen(true)] out string? orgShortName)
=> claimsPrincipal.FindFirst(OrgClaim).TryGetServiceOwnerShortName(out orgShortName);

private static bool TryGetServiceOwnerShortName(this Claim? orgClaim, [NotNullWhen(true)] out string? orgShortName)
{
orgShortName = orgClaim?.Value;
return orgShortName is not null;
}

internal static bool TryGetOrganizationNumber(this IUser user, [NotNullWhen(true)] out string? orgNumber) =>
user.GetPrincipal().TryGetOrganizationNumber(out orgNumber);

internal static bool TryGetServiceOwnerShortName(this IUser user, [NotNullWhen(true)] out string? orgShortName) =>
user.GetPrincipal().TryGetServiceOwnerShortName(out orgShortName);

internal static bool TryGetPid(this IUser user, [NotNullWhen(true)] out string? pid) =>
user.GetPrincipal().TryGetPid(out pid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public UserOrganizationRegistry(IUser user, IServiceOwnerNameRegistry serviceOwn

public async Task<string?> GetCurrentUserOrgShortName(CancellationToken cancellationToken)
{
if (_user.TryGetServiceOwnerShortName(out var orgShortName))
{
return orgShortName;
}

if (!_user.TryGetOrganizationNumber(out var orgNumber))
{
return null;
Expand Down

0 comments on commit 56e91a1

Please sign in to comment.