Skip to content

Commit

Permalink
rename and format saml2 authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnkwlp committed Sep 19, 2023
1 parent 3bb8a46 commit 8505c57
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 58 deletions.
14 changes: 7 additions & 7 deletions Passingwind.CommonLibs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{31171FC1-4
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Passingwind.SwaggerExtensions", "src\Passingwind.SwaggerExtensions\Passingwind.SwaggerExtensions.csproj", "{300C8EF1-B040-4F50-BA65-175EE5A82A0F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Passingwind.AspNetCore.Authentication.Saml2", "src\Passingwind.AspNetCore.Authentication.Saml2\Passingwind.AspNetCore.Authentication.Saml2.csproj", "{4ED083F0-7B73-4380-A4F5-164474FDCF82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Passingwind.AspNetCore.Authentication.ApiKey", "src\Authentication.ApiKey\source\Passingwind.AspNetCore.Authentication.ApiKey.csproj", "{F7FE0AD3-B69F-4F10-8EA4-E581EBE4A2AC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Passingwind.AspNetCore.Authentication.Saml2", "src\Authentication.Saml2\source\Passingwind.AspNetCore.Authentication.Saml2.csproj", "{6C1D2746-FE37-4AD4-9E40-DF28536472B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -31,23 +31,23 @@ Global
{300C8EF1-B040-4F50-BA65-175EE5A82A0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{300C8EF1-B040-4F50-BA65-175EE5A82A0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{300C8EF1-B040-4F50-BA65-175EE5A82A0F}.Release|Any CPU.Build.0 = Release|Any CPU
{4ED083F0-7B73-4380-A4F5-164474FDCF82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4ED083F0-7B73-4380-A4F5-164474FDCF82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4ED083F0-7B73-4380-A4F5-164474FDCF82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4ED083F0-7B73-4380-A4F5-164474FDCF82}.Release|Any CPU.Build.0 = Release|Any CPU
{F7FE0AD3-B69F-4F10-8EA4-E581EBE4A2AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7FE0AD3-B69F-4F10-8EA4-E581EBE4A2AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7FE0AD3-B69F-4F10-8EA4-E581EBE4A2AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7FE0AD3-B69F-4F10-8EA4-E581EBE4A2AC}.Release|Any CPU.Build.0 = Release|Any CPU
{6C1D2746-FE37-4AD4-9E40-DF28536472B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C1D2746-FE37-4AD4-9E40-DF28536472B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C1D2746-FE37-4AD4-9E40-DF28536472B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C1D2746-FE37-4AD4-9E40-DF28536472B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{41CC2AD6-8FDC-4F00-8CF1-94C89666137E} = {D7A92342-2C8A-4121-8824-95AEF5856AAF}
{300C8EF1-B040-4F50-BA65-175EE5A82A0F} = {CE8B3FAE-E7B7-4EB6-BEB5-716F2B91A315}
{4ED083F0-7B73-4380-A4F5-164474FDCF82} = {CE8B3FAE-E7B7-4EB6-BEB5-716F2B91A315}
{F7FE0AD3-B69F-4F10-8EA4-E581EBE4A2AC} = {CE8B3FAE-E7B7-4EB6-BEB5-716F2B91A315}
{6C1D2746-FE37-4AD4-9E40-DF28536472B1} = {CE8B3FAE-E7B7-4EB6-BEB5-716F2B91A315}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AB481C2D-55C1-486C-873D-408B11F77F30}
Expand Down
2 changes: 2 additions & 0 deletions src/Authentication.ApiKey/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

ASP.NET Core authentication handler for the ApiKey protocol

[![NuGet](https://img.shields.io/nuget/v/Passingwind.AspNetCore.Authentication.ApiKey?style=flat-square)](https://www.nuget.org/packages/Passingwind.AspNetCore.Authentication.ApiKey)

## Quickstart

``` cs
Expand Down
5 changes: 5 additions & 0 deletions src/Authentication.Saml2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# AspNetCore.Authentication.Saml2

ASP.NET Core authentication handler for the SAML2 protocol

[![NuGet](https://img.shields.io/nuget/v/Passingwind.AspNetCore.Authentication.Saml2?style=flat-square)](https://www.nuget.org/packages/Passingwind.AspNetCore.Authentication.Saml2)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
using ITfoxtec.Identity.Saml2;
using ITfoxtec.Identity.Saml2.Schemas.Metadata;

namespace Passingwind.Authentication.Saml2.Configuration;
namespace Passingwind.AspNetCore.Authentication.Saml2.Configuration;

/// <summary>
///
/// </summary>
public class ConfigurationManager : IConfigurationManager
{
private Saml2Configuration? _saml2Configuration;
Expand All @@ -16,13 +19,24 @@ public class ConfigurationManager : IConfigurationManager
private readonly Uri _idpMetadataUri;
private readonly HttpClient _httpClient;

/// <summary>
///
/// </summary>
/// <param name="options"></param>
/// <param name="idpMetadataUrl"></param>
/// <param name="httpClient"></param>
public ConfigurationManager(Saml2Options options, Uri idpMetadataUrl, HttpClient httpClient)
{
_options = options;
_idpMetadataUri = idpMetadataUrl;
_httpClient = httpClient;
}

/// <summary>
///
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<Saml2Configuration> GetConfigurationAsync(CancellationToken cancellationToken = default)
{
if (_saml2Configuration != null)
Expand Down Expand Up @@ -51,7 +65,7 @@ public async Task<Saml2Configuration> GetConfigurationAsync(CancellationToken ca
var metadataGetResponse = await _httpClient.GetAsync(_idpMetadataUri, cancellationToken);
metadataGetResponse.EnsureSuccessStatusCode();

var metadataString = await metadataGetResponse.Content.ReadAsStringAsync();
var metadataString = await metadataGetResponse.Content.ReadAsStringAsync(cancellationToken);
entityDescriptor.ReadIdPSsoDescriptor(metadataString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
using System.Threading.Tasks;
using ITfoxtec.Identity.Saml2;

namespace Passingwind.Authentication.Saml2.Configuration;
namespace Passingwind.AspNetCore.Authentication.Saml2.Configuration;

/// <summary>
///
/// </summary>
public interface IConfigurationManager
{
/// <summary>
///
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<Saml2Configuration> GetConfigurationAsync(CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@
using System.Threading.Tasks;
using ITfoxtec.Identity.Saml2;

namespace Passingwind.Authentication.Saml2.Configuration;
namespace Passingwind.AspNetCore.Authentication.Saml2.Configuration;

/// <summary>
///
/// </summary>
public class StaticConfigurationManager : IConfigurationManager
{
private readonly Saml2Configuration _saml2Configuration;

/// <summary>
///
/// </summary>
/// <param name="saml2Configuration"></param>
public StaticConfigurationManager(Saml2Configuration saml2Configuration)
{
_saml2Configuration = saml2Configuration;
}

/// <summary>
///
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<Saml2Configuration> GetConfigurationAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(_saml2Configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;

namespace Passingwind.Authentication.Saml2;
namespace Passingwind.AspNetCore.Authentication.Saml2;

static class Extensions
internal static class Extensions
{
public static ITfoxtec.Identity.Saml2.Http.HttpRequest ToGenericHttpRequest(this HttpRequest request, bool readBodyAsString = false)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6;net7</TargetFrameworks>
<Nullable>enable</Nullable>
<RootNamespace>Passingwind.AspNetCore.Authentication.Saml2</RootNamespace>
<AnalysisLevel>latest-minimum</AnalysisLevel>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<FileVersion>$(AssemblyVersion)</FileVersion>
<AssemblyVersion>0.1</AssemblyVersion>
</PropertyGroup>

<PropertyGroup>
<PackageId>Passingwind.AspNetCore.Authentication.Saml2</PackageId>
<Title>Passingwind.AspNetCore.Authentication.Saml2</Title>
<Authors>Passingwind</Authors>
<PackageProjectUrl>https://github.com/jxnkwlp/Passingwind.CommonLibs</PackageProjectUrl>
<RepositoryUrl>https://github.com/jxnkwlp/Passingwind.CommonLibs</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>authentication, SAML2</PackageTags>
<Description>ASP.NET Core authentication handler for the SAML2 protocol</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageVersion>0.1.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ITfoxtec.Identity.Saml2" Version="4.8.8" />
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions src/Authentication.Saml2/source/Saml2Defaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Passingwind.AspNetCore.Authentication.Saml2;

/// <summary>
///
/// </summary>
public static class Saml2Defaults
{
/// <summary>
///
/// </summary>
public const string AuthenticationScheme = "Saml2";

/// <summary>
///
/// </summary>
public const string DisplayName = "Saml2";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;

namespace Passingwind.Authentication.Saml2;
namespace Passingwind.AspNetCore.Authentication.Saml2;

/// <summary>
///
/// </summary>
public class Saml2Events : RemoteAuthenticationEvents
{
/// <summary>
Expand Down Expand Up @@ -76,14 +79,30 @@ public class Saml2Events : RemoteAuthenticationEvents
public virtual Task SecurityTokenValidated(SecurityTokenValidatedContext context) => OnSecurityTokenValidated(context);
}

/// <summary>
///
/// </summary>
public class RedirectContext : PropertiesContext<Saml2Options>
{
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="scheme"></param>
/// <param name="options"></param>
/// <param name="properties"></param>
public RedirectContext(HttpContext context, AuthenticationScheme scheme, Saml2Options options, AuthenticationProperties? properties) : base(context, scheme, options, properties)
{
}

/// <summary>
///
/// </summary>
public Saml2AuthnRequest Saml2AuthnRequest { get; set; } = default!;

/// <summary>
///
/// </summary>
public Saml2RedirectBinding RedirectBinding { get; set; } = default!;

/// <summary>
Expand All @@ -97,50 +116,118 @@ public RedirectContext(HttpContext context, AuthenticationScheme scheme, Saml2Op
public void HandleResponse() => Handled = true;
}

/// <summary>
///
/// </summary>
public class RemoteSignOutContext : RemoteAuthenticationContext<Saml2Options>
{
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="scheme"></param>
/// <param name="options"></param>
/// <param name="properties"></param>
public RemoteSignOutContext(HttpContext context, AuthenticationScheme scheme, Saml2Options options, AuthenticationProperties? properties) : base(context, scheme, options, properties)
{
}

/// <summary>
///
/// </summary>
public Saml2AuthnResponse Saml2AuthnResponse { get; set; } = default!;
}

/// <summary>
///
/// </summary>
public class MessageReceivedContext : RemoteAuthenticationContext<Saml2Options>
{
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="scheme"></param>
/// <param name="options"></param>
/// <param name="properties"></param>
public MessageReceivedContext(HttpContext context, AuthenticationScheme scheme, Saml2Options options, AuthenticationProperties? properties) : base(context, scheme, options, properties)
{
}

/// <summary>
///
/// </summary>
public Saml2AuthnResponse Saml2AuthnResponse { get; set; } = default!;
}

/// <summary>
///
/// </summary>
public class SecurityTokenReceivedContext : RemoteAuthenticationContext<Saml2Options>
{
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="scheme"></param>
/// <param name="options"></param>
/// <param name="properties"></param>
public SecurityTokenReceivedContext(HttpContext context, AuthenticationScheme scheme, Saml2Options options, AuthenticationProperties? properties) : base(context, scheme, options, properties)
{
}

/// <summary>
///
/// </summary>
public Saml2AuthnResponse Saml2AuthnResponse { get; set; } = default!;
}

/// <summary>
///
/// </summary>
public class SecurityTokenValidatedContext : RemoteAuthenticationContext<Saml2Options>
{
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="scheme"></param>
/// <param name="options"></param>
/// <param name="principal"></param>
/// <param name="properties"></param>
public SecurityTokenValidatedContext(HttpContext context, AuthenticationScheme scheme, Saml2Options options, ClaimsPrincipal principal, AuthenticationProperties? properties) : base(context, scheme, options, properties)
{
Principal = principal;
}

/// <summary>
///
/// </summary>
public Saml2AuthnResponse Saml2AuthnResponse { get; set; } = default!;
}

/// <summary>
///
/// </summary>
public class AuthenticationFailedContext : RemoteAuthenticationContext<Saml2Options>
{
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="scheme"></param>
/// <param name="options"></param>
public AuthenticationFailedContext(HttpContext context, AuthenticationScheme scheme, Saml2Options options) : base(context, scheme, options, null)
{
}

/// <summary>
///
/// </summary>
public Saml2AuthnResponse Saml2AuthnResponse { get; set; } = default!;

/// <summary>
///
/// </summary>
public Exception Exception { get; set; } = default!;
}
Loading

0 comments on commit 8505c57

Please sign in to comment.