Skip to content

Commit cc16a19

Browse files
authored
Merge pull request #6 from mihirdilip/5.1.0
5.1.0
2 parents 9a0b17b + 7e0c305 commit cc16a19

26 files changed

+2557
-58
lines changed

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Mihir Dilip
3+
Copyright (c) 2021 Mihir Dilip
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+130-37
Large diffs are not rendered by default.

samples/SampleWebApi_2_0/SampleWebApi_2_0.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="AspNetCore.Authentication.Basic" Version="5.0.0" />
15+
<PackageReference Include="AspNetCore.Authentication.Basic" Version="5.1.0" />
1616
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
1717
</ItemGroup>
1818

samples/SampleWebApi_2_2/SampleWebApi_2_2.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="AspNetCore.Authentication.Basic" Version="5.0.0" />
9+
<PackageReference Include="AspNetCore.Authentication.Basic" Version="5.1.0" />
1010
<PackageReference Include="Microsoft.AspNetCore.App" />
1111
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
1212
</ItemGroup>

samples/SampleWebApi_3_1/SampleWebApi_3_1.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Import Project="..\SampleWebApi.Shared\SampleWebApi.Shared.projitems" Label="Shared" />
88

99
<ItemGroup>
10-
<PackageReference Include="AspNetCore.Authentication.Basic" Version="5.0.0" />
10+
<PackageReference Include="AspNetCore.Authentication.Basic" Version="5.1.0" />
1111
</ItemGroup>
1212

1313
<!--<ItemGroup>

samples/SampleWebApi_5_0/SampleWebApi_5_0.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Import Project="..\SampleWebApi.Shared\SampleWebApi.Shared.projitems" Label="Shared" />
88

99
<ItemGroup>
10-
<PackageReference Include="AspNetCore.Authentication.Basic" Version="5.0.0" />
10+
<PackageReference Include="AspNetCore.Authentication.Basic" Version="5.1.0" />
1111
</ItemGroup>
1212

1313
<!--<ItemGroup>

src/AspNetCore.Authentication.Basic.sln

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi_2_0", "..\samp
2222
EndProject
2323
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi_3_1", "..\samples\SampleWebApi_3_1\SampleWebApi_3_1.csproj", "{2705DB4C-3BCE-4CFC-9A30-B4BFD1F28C56}"
2424
EndProject
25-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApi_5_0", "..\samples\SampleWebApi_5_0\SampleWebApi_5_0.csproj", "{B82830A0-FDFC-469D-B2A8-D657CD216451}"
25+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi_5_0", "..\samples\SampleWebApi_5_0\SampleWebApi_5_0.csproj", "{B82830A0-FDFC-469D-B2A8-D657CD216451}"
26+
EndProject
27+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{F7494366-ED1D-4342-AE5D-DD6BE67C63DF}"
28+
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore.Authentication.Basic.Tests", "..\test\AspNetCore.Authentication.Basic.Tests\AspNetCore.Authentication.Basic.Tests.csproj", "{335B0D1F-A428-4D2E-AF87-269C75F5F138}"
2630
EndProject
2731
Global
2832
GlobalSection(SharedMSBuildProjectFiles) = preSolution
@@ -57,6 +61,10 @@ Global
5761
{B82830A0-FDFC-469D-B2A8-D657CD216451}.Debug|Any CPU.Build.0 = Debug|Any CPU
5862
{B82830A0-FDFC-469D-B2A8-D657CD216451}.Release|Any CPU.ActiveCfg = Release|Any CPU
5963
{B82830A0-FDFC-469D-B2A8-D657CD216451}.Release|Any CPU.Build.0 = Release|Any CPU
64+
{335B0D1F-A428-4D2E-AF87-269C75F5F138}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
65+
{335B0D1F-A428-4D2E-AF87-269C75F5F138}.Debug|Any CPU.Build.0 = Debug|Any CPU
66+
{335B0D1F-A428-4D2E-AF87-269C75F5F138}.Release|Any CPU.ActiveCfg = Release|Any CPU
67+
{335B0D1F-A428-4D2E-AF87-269C75F5F138}.Release|Any CPU.Build.0 = Release|Any CPU
6068
EndGlobalSection
6169
GlobalSection(SolutionProperties) = preSolution
6270
HideSolutionNode = FALSE
@@ -67,6 +75,7 @@ Global
6775
{897E5C9C-8C0A-4FB6-960C-4D11AAFD4491} = {CF13271D-BF3F-4167-BEBA-DD02D33992F2}
6876
{2705DB4C-3BCE-4CFC-9A30-B4BFD1F28C56} = {CF13271D-BF3F-4167-BEBA-DD02D33992F2}
6977
{B82830A0-FDFC-469D-B2A8-D657CD216451} = {CF13271D-BF3F-4167-BEBA-DD02D33992F2}
78+
{335B0D1F-A428-4D2E-AF87-269C75F5F138} = {F7494366-ED1D-4342-AE5D-DD6BE67C63DF}
7079
EndGlobalSection
7180
GlobalSection(ExtensibilityGlobals) = postSolution
7281
SolutionGuid = {70815049-1680-480A-BF5A-00536D6C9C20}

src/AspNetCore.Authentication.Basic/AspNetCore.Authentication.Basic.csproj

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp3.0;netstandard2.0;net461</TargetFrameworks>
5-
<Version>5.0.0</Version>
5+
<Version>5.1.0</Version>
66
<RepositoryUrl>https://github.com/mihirdilip/aspnetcore-authentication-basic/tree/$(Version)</RepositoryUrl>
77
<PackageProjectUrl>https://github.com/mihirdilip/aspnetcore-authentication-basic/tree/$(Version)</PackageProjectUrl>
88
<PackageTags>aspnetcore, security, authentication, microsoft, microsoft.aspnetcore.authentication, microsoft-aspnetcore-authentication, microsoft.aspnetcore.authentication.basic, microsoft-aspnetcore-authentication-basic, asp-net-core, netstandard, netstandard20, basic-authentication, basicauthentication, dotnetcore, dotnetcore3.1, net5, net5.0, asp-net-core-basic-authentication, aspnetcore-basic-authentication, net5-basic-authentication, asp-net-core-authentication, aspnetcore-authentication, net5-authentication, asp, aspnet, basic, authentication-scheme</PackageTags>
9-
<PackageReleaseNotes>- .Net 5.0 target framework added
10-
- IgnoreAuthenticationIfAllowAnonymous added to the BasicOptions from netcoreapp3.0 onwards
9+
<PackageReleaseNotes>- Visibility of all the handlers changed to public
1110
</PackageReleaseNotes>
1211
<Description>Easy to use and very light weight Microsoft style Basic Scheme Authentication implementation for ASP.NET Core.</Description>
1312
<Authors>Mihir Dilip</Authors>
1413
<Company>Mihir Dilip</Company>
15-
<Copyright>Copyright (c) 2020 Mihir Dilip</Copyright>
14+
<Copyright>Copyright (c) 2021 Mihir Dilip</Copyright>
1615
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1716
<Title>$(AssemblyName)</Title>
1817
<RepositoryType>git</RepositoryType>
@@ -44,6 +43,14 @@
4443
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
4544
</ItemGroup>
4645

46+
<ItemGroup>
47+
<!-- Unit Testing - To make internal visible to tests -->
48+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
49+
<_Parameter1>
50+
$(MSBuildProjectName).Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100196de3cf1767e4651bd29928a1dfdc149897770adb2439fd0f42a480f0f0c955606d6e6cae87cbdcdfbd1686ec7775789b82fa869387c31dcc740991f3d3d2db407b0a28d772fe343cdf8f1b12ee53bb625aee854f56e0be93f11c307c0dbc54aad277111fc04db0eed2513a20d5663c50412afd34e8c8fb98459d8f4d90e5b6</_Parameter1>
51+
</AssemblyAttribute>
52+
</ItemGroup>
53+
4754
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
4855
<DocumentationFile>bin\Release\$(TargetFramework)\AspNetCore.Authentication.Basic.xml</DocumentationFile>
4956
</PropertyGroup>

src/AspNetCore.Authentication.Basic/BasicHandler.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace AspNetCore.Authentication.Basic
1818
/// <summary>
1919
/// Inherited from <see cref="AuthenticationHandler{TOptions}"/> for basic authentication.
2020
/// </summary>
21-
internal class BasicHandler : AuthenticationHandler<BasicOptions>
21+
public class BasicHandler : AuthenticationHandler<BasicOptions>
2222
{
2323
/// <summary>
2424
/// Basic Handler Constructor.
@@ -253,9 +253,9 @@ private BasicCredentials DecodeBasicCredentials(string credentials)
253253
username = usernameAndPasswordSplit[0];
254254
password = usernameAndPasswordSplit[1];
255255
}
256-
catch (Exception)
256+
catch (Exception e)
257257
{
258-
throw new Exception($"Problem decoding '{BasicDefaults.AuthenticationScheme}' scheme credentials.");
258+
throw new Exception($"Problem decoding '{BasicDefaults.AuthenticationScheme}' scheme credentials.", e);
259259
}
260260

261261
if (string.IsNullOrWhiteSpace(username))

src/AspNetCore.Authentication.Basic/BasicPostConfigureOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void PostConfigure(string name, BasicOptions options)
1515
{
1616
if (!options.SuppressWWWAuthenticateHeader && string.IsNullOrWhiteSpace(options.Realm))
1717
{
18-
throw new InvalidOperationException("Realm must be set in basic options");
18+
throw new InvalidOperationException($"{nameof(BasicOptions.Realm)} must be set in {typeof(BasicOptions).Name} when setting up the authentication.");
1919
}
2020

2121
if (options.Events?.OnValidateCredentials == null && options.EventsType == null && options.BasicUserValidationServiceType == null)

src/AspNetCore.Authentication.Basic/BasicUtils.cs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Mihir Dilip. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Linq;
67
using System.Security.Claims;
@@ -24,18 +25,22 @@ internal static class BasicUtils
2425
/// <returns></returns>
2526
internal static ClaimsPrincipal BuildClaimsPrincipal(string username, string schemeName, string claimsIssuer, IEnumerable<Claim> claims = null)
2627
{
27-
var claimsList = new List<Claim>();
28+
if (string.IsNullOrWhiteSpace(schemeName)) throw new ArgumentNullException(nameof(schemeName));
2829

30+
var claimsList = new List<Claim>();
2931
if (claims != null) claimsList.AddRange(claims);
3032

31-
if (!claimsList.Any(c => c.Type == ClaimTypes.NameIdentifier))
33+
if (!string.IsNullOrWhiteSpace(username))
3234
{
33-
claimsList.Add(new Claim(ClaimTypes.NameIdentifier, username, ClaimValueTypes.String, claimsIssuer));
34-
}
35+
if (!claimsList.Any(c => c.Type == ClaimTypes.NameIdentifier))
36+
{
37+
claimsList.Add(new Claim(ClaimTypes.NameIdentifier, username, ClaimValueTypes.String, claimsIssuer));
38+
}
3539

36-
if (!claimsList.Any(c => c.Type == ClaimTypes.Name))
37-
{
38-
claimsList.Add(new Claim(ClaimTypes.Name, username, ClaimValueTypes.String, claimsIssuer));
40+
if (!claimsList.Any(c => c.Type == ClaimTypes.Name))
41+
{
42+
claimsList.Add(new Claim(ClaimTypes.Name, username, ClaimValueTypes.String, claimsIssuer));
43+
}
3944
}
4045

4146
return new ClaimsPrincipal(new ClaimsIdentity(claimsList, schemeName));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp3.0;netcoreapp2.1;net461</TargetFrameworks>
5+
<IsPackable>false</IsPackable>
6+
<LangVersion>latest</LangVersion>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<!-- Strong Name Key -->
11+
<SignAssembly>true</SignAssembly>
12+
<AssemblyOriginatorKeyFile>$(SolutionDir)key.snk</AssemblyOriginatorKeyFile>
13+
<DelaySign>false</DelaySign>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
18+
<PackageReference Include="xunit" Version="2.4.1" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
<PrivateAssets>all</PrivateAssets>
22+
</PackageReference>
23+
<PackageReference Include="coverlet.collector" Version="3.0.3">
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25+
<PrivateAssets>all</PrivateAssets>
26+
</PackageReference>
27+
</ItemGroup>
28+
29+
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
30+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.3" />
31+
</ItemGroup>
32+
33+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
34+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.11" />
35+
</ItemGroup>
36+
37+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
38+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.3" />
39+
</ItemGroup>
40+
41+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
42+
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="5.0.3" />
43+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
44+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
45+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
46+
</ItemGroup>
47+
48+
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
49+
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="5.0.3" />
50+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
51+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
52+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
53+
</ItemGroup>
54+
55+
<ItemGroup>
56+
<ProjectReference Include="..\..\src\AspNetCore.Authentication.Basic\AspNetCore.Authentication.Basic.csproj" />
57+
</ItemGroup>
58+
59+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Mihir Dilip. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Xunit;
5+
6+
namespace AspNetCore.Authentication.Basic.Tests
7+
{
8+
public class BasicDefaultsTests
9+
{
10+
[Fact]
11+
public void AuthenticationSchemeValueTest()
12+
{
13+
Assert.Equal("Basic", BasicDefaults.AuthenticationScheme);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)