-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f75d86
commit 0eeb95a
Showing
21 changed files
with
160 additions
and
109 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
...sting.Authentication.ClaimInjector/AspNetCore.Testing.Authentication.ClaimInjector.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<RootNamespace>AspNetCore.Testing.Authentication.ClaimInjector</RootNamespace> | ||
<IsPackable>True</IsPackable> | ||
<Authors>jabbera</Authors> | ||
<PackageDescription>Easy testing of role based authentication during integration testing for ASP.NET core applications.</PackageDescription> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageProjectUrl>https://github.com/jabbera/aspnetcore-testing-role-handler</PackageProjectUrl> | ||
<PackageIconUrl></PackageIconUrl> | ||
<PackageTags>aspnetcore;aspnetcoremvc;aspnetcoremvctesting;role;authentication;jwt;bearer</PackageTags> | ||
|
||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> | ||
|
||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05" PrivateAssets="All"/> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
AspNetCore.Testing.Authentication.ClaimInjector/ClaimInjectorHandlerHeaderConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using Newtonsoft.Json; | ||
|
||
namespace AspNetCore.Testing.Authentication.ClaimInjector | ||
{ | ||
public class ClaimInjectorHandlerHeaderConfig | ||
{ | ||
[JsonProperty] private Dictionary<string, List<string>> _claims = new Dictionary<string, List<string>>(); | ||
|
||
public ClaimInjectorHandlerHeaderConfig() => Reset(); | ||
|
||
[JsonProperty] | ||
public bool AnonymousRequest { get; set; } | ||
|
||
public string Name | ||
{ | ||
set | ||
{ | ||
if (value == null) throw new ArgumentNullException(nameof(value)); | ||
|
||
_claims.Remove(ClaimTypes.Name); | ||
|
||
_claims.Add(ClaimTypes.Name, new List<string> {value}); | ||
} | ||
} | ||
|
||
public string[] Roles | ||
{ | ||
set | ||
{ | ||
if (value == null || value.Any(x => x == null)) { | ||
throw new ArgumentNullException(nameof(value)); | ||
} | ||
|
||
_claims.Remove(ClaimTypes.Role); | ||
|
||
foreach(var role in value) { | ||
AddClaim(ClaimTypes.Role, role); | ||
} | ||
} | ||
} | ||
|
||
public void AddClaim(string claimType, string value) | ||
{ | ||
if (!this._claims.TryGetValue(claimType, out var values)) | ||
{ | ||
values = new List<string>(); | ||
this._claims.Add(claimType, values); | ||
} | ||
|
||
values.Add(value); | ||
} | ||
|
||
public void AddClaim(Claim claim) => AddClaim(claim.Type, claim.Value); | ||
|
||
internal IEnumerable<Claim> Claims => _claims.SelectMany(x => x.Value.Select(y => new Claim(x.Key, y))); | ||
|
||
public void Reset() | ||
{ | ||
this._claims.Clear(); | ||
this.AnonymousRequest = false; | ||
this.Name = "Authenticated User"; | ||
this.Roles = new string[0]; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
AspNetCore.Testing.Authentication.ClaimInjector/ClaimInjectorHandlerOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.AspNetCore.Authentication; | ||
|
||
namespace AspNetCore.Testing.Authentication.ClaimInjector | ||
{ | ||
public class ClaimInjectorHandlerOptions : AuthenticationSchemeOptions | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
AspNetCore.Testing.RoleHandler/AspNetCore.Testing.RoleHandler.csproj
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
AspNetCore.Testing.RoleHandler/CustomRoleHandlerHeaderConfig.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<LangVersion>7.3</LangVersion> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters