Repository navigation
Expand file tree
/
Copy pathClaimActionCollectionUniqueExtensions.cs
More file actions
39 lines (36 loc) · 2.09 KB
/
Copy pathClaimActionCollectionUniqueExtensions.cs
File metadata and controls
39 lines (36 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication.OAuth.Claims;
using Microsoft.AspNetCore.Authentication.OpenIdConnect.Claims;
namespace Microsoft.AspNetCore.Authentication
{
public static class ClaimActionCollectionUniqueExtensions
{
/// <summary>
/// Selects a top level value from the json user data with the given key name and adds it as a Claim.
/// This no-ops if the ClaimsIdentity already contains a Claim with the given ClaimType.
/// This no-ops if the key is not found or the value is empty.
/// </summary>
/// <param name="collection"></param>
/// <param name="claimType">The value to use for Claim.Type when creating a Claim.</param>
/// <param name="jsonKey">The top level key to look for in the json user data.</param>
public static void MapUniqueJsonKey(this ClaimActionCollection collection, string claimType, string jsonKey)
{
collection.MapUniqueJsonKey(claimType, jsonKey, ClaimValueTypes.String);
}
/// <summary>
/// Selects a top level value from the json user data with the given key name and adds it as a Claim.
/// This no-ops if the ClaimsIdentity already contains a Claim with the given ClaimType.
/// This no-ops if the key is not found or the value is empty.
/// </summary>
/// <param name="collection"></param>
/// <param name="claimType">The value to use for Claim.Type when creating a Claim.</param>
/// <param name="jsonKey">The top level key to look for in the json user data.</param>
/// <param name="valueType">The value to use for Claim.ValueType when creating a Claim.</param>
public static void MapUniqueJsonKey(this ClaimActionCollection collection, string claimType, string jsonKey, string valueType)
{
collection.Add(new UniqueJsonKeyClaimAction(claimType, valueType, jsonKey));
}
}
}