Skip to content

Commit d09397e

Browse files
WIP
1 parent 5b12943 commit d09397e

27 files changed

Lines changed: 409 additions & 58 deletions

File tree

src/FastFed/SimpleIdServer.FastFed.ApplicationProvider.Authentication.Saml/Infrastructures/DynamicSamlAuthenticationSchemeProvider.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class DynamicSamlAuthenticationSchemeProvider : AuthenticationSchemeProvi
2626
private readonly IBusControl _busControl;
2727
private readonly IServiceProvider _serviceProvider;
2828
private readonly SamlAuthenticationOptions _samlAuthOptions;
29+
private readonly FastFedApplicationProviderOptions _fastFedApplicationProviderOptions;
2930
private DateTime? _nextExpirationTime;
3031
private IEnumerable<AuthSchemeProvider> _cachedAuthSchemeProviders;
3132
private object _lck = new object();
@@ -34,11 +35,13 @@ public DynamicSamlAuthenticationSchemeProvider(
3435
IBusControl busControl,
3536
IServiceProvider serviceProvider,
3637
IOptions<SamlAuthenticationOptions> samlAuthOptions,
38+
IOptions<FastFedApplicationProviderOptions> fastFedApplicationProviderOptions,
3739
IOptions<AuthenticationOptions> options) : base(options)
3840
{
3941
_busControl = busControl;
4042
_serviceProvider = serviceProvider;
4143
_samlAuthOptions = samlAuthOptions.Value;
44+
_fastFedApplicationProviderOptions = fastFedApplicationProviderOptions.Value;
4245
}
4346

4447
public async override Task<IEnumerable<AuthenticationScheme>> GetAllSchemesAsync()
@@ -57,6 +60,8 @@ public async override Task<IEnumerable<AuthenticationScheme>> GetAllSchemesAsync
5760
return rules;
5861
}
5962

63+
public override Task<IEnumerable<AuthenticationScheme>> GetRequestHandlerSchemesAsync() => GetAllSchemesAsync();
64+
6065
public override async Task<AuthenticationScheme> GetSchemeAsync(string name) => (await GetSamlSchemeAsync(name)).AuthScheme;
6166

6267
public async Task<SamlAuthenticationScheme> GetSamlSchemeAsync(string name)
@@ -79,11 +84,13 @@ private SamlAuthenticationScheme Convert(AuthSchemeProvider provider)
7984
{
8085
SPId = _samlAuthOptions.SpId,
8186
IdpMetadataUrl = provider.SamlMetadataUri,
82-
SigningCertificate = _samlAuthOptions.SigningCertificate
87+
SigningCertificate = _samlAuthOptions.SigningCertificate,
88+
SignInScheme = _fastFedApplicationProviderOptions.AuthScheme.Cookie
8389
};
90+
var monitoredOpts = new ConcreteOptionsMonitor<SamlSpOptions>(options);
8491
if (options.Backchannel == null)
8592
options.Backchannel = new HttpClient(_samlAuthOptions.BackchannelHttpHandler ?? new HttpClientHandler());
86-
return new SamlAuthenticationScheme(new AuthenticationScheme(provider.Name, provider.DisplayName, handlerType), options);
93+
return new SamlAuthenticationScheme(new AuthenticationScheme(provider.Name, provider.DisplayName, handlerType), monitoredOpts);
8794
}
8895
}
8996

@@ -128,4 +135,24 @@ private async Task<IEnumerable<AuthSchemeProvider>> GetAuthenticationSchemeProvi
128135
return authenticationSchemeProviders;
129136
}
130137
}
138+
139+
private class ConcreteOptionsMonitor<T> : IOptionsMonitor<T> where T : class
140+
{
141+
public ConcreteOptionsMonitor(T value)
142+
{
143+
CurrentValue = value;
144+
}
145+
146+
public T CurrentValue { get; private set; }
147+
148+
public T Get(string name)
149+
{
150+
return CurrentValue;
151+
}
152+
153+
public IDisposable OnChange(Action<T, string> listener)
154+
{
155+
return null;
156+
}
157+
}
131158
}

src/FastFed/SimpleIdServer.FastFed.ApplicationProvider.Authentication.Saml/Infrastructures/SamlAuthenticationScheme.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) SimpleIdServer. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33
using Microsoft.AspNetCore.Authentication;
4+
using Microsoft.Extensions.Options;
45
using SimpleIdServer.IdServer.Saml.Sp;
56

67
namespace SimpleIdServer.FastFed.ApplicationProvider.Authentication.Saml.Infrastructures;
@@ -12,12 +13,12 @@ public SamlAuthenticationScheme(AuthenticationScheme authScheme)
1213
AuthScheme = authScheme;
1314
}
1415

15-
public SamlAuthenticationScheme(AuthenticationScheme authScheme, SamlSpOptions samlSpOptions) : this(authScheme)
16+
public SamlAuthenticationScheme(AuthenticationScheme authScheme, IOptionsMonitor<SamlSpOptions> samlSpOptions) : this(authScheme)
1617
{
1718
SamlSpOptions = samlSpOptions;
1819
}
1920

2021

2122
public AuthenticationScheme AuthScheme { get; set; }
22-
public SamlSpOptions SamlSpOptions { get; set; }
23+
public IOptionsMonitor<SamlSpOptions> SamlSpOptions { get; set; }
2324
}

src/FastFed/SimpleIdServer.FastFed.ApplicationProvider.Authentication.Saml/SimpleIdServer.FastFed.ApplicationProvider.Authentication.Saml.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<ProjectReference Include="..\..\IdServer\SimpleIdServer.IdServer.Saml.Sp\SimpleIdServer.IdServer.Saml.Sp.csproj" />
8+
<ProjectReference Include="..\SimpleIdServer.FastFed.ApplicationProvider\SimpleIdServer.FastFed.ApplicationProvider.csproj" />
89
<ProjectReference Include="..\SimpleIdServer.FastFed.Authentication.Saml\SimpleIdServer.FastFed.Authentication.Saml.csproj" />
910
<ProjectReference Include="..\SimpleIdServer.FastFed\SimpleIdServer.FastFed.csproj" />
1011
</ItemGroup>

src/FastFed/SimpleIdServer.FastFed.ApplicationProvider.Startup/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
})
9191
.AddSamlAppProviderAuthenticationProfile(cb =>
9292
{
93-
cb.SamlMetadataUri = "https://localhost:5021/saml-metadata.xml";
93+
cb.SpId = "https://localhost:5021";
94+
cb.SamlMetadataUri = "https://localhost:5021/Metadata";
9495
cb.SigningCertificate = KeyGenerator.GenerateSelfSignedCertificate();
9596
cb.Mappings = new SamlEntrepriseMappingsResult
9697
{

src/FastFed/SimpleIdServer.FastFed.ApplicationProvider.Startup/Resources/AuthenticateResource.Designer.cs

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<data name="Title" xml:space="preserve">
121+
<value>Authenticate</value>
122+
</data>
123+
<data name="Authenticate" xml:space="preserve">
124+
<value>Authenticate</value>
125+
</data>
126+
</root>

src/FastFed/SimpleIdServer.FastFed.ApplicationProvider.Startup/SimpleIdServer.FastFed.ApplicationProvider.Startup.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
<AutoGen>True</AutoGen>
2626
<DependentUpon>HomeResource.resx</DependentUpon>
2727
</Compile>
28+
<Compile Update="Resources\AuthenticateResource.Designer.cs">
29+
<DesignTime>True</DesignTime>
30+
<AutoGen>True</AutoGen>
31+
<DependentUpon>AuthenticateResource.resx</DependentUpon>
32+
</Compile>
2833
<Compile Update="Resources\LayoutResource.Designer.cs">
2934
<DesignTime>True</DesignTime>
3035
<AutoGen>True</AutoGen>
@@ -53,5 +58,9 @@
5358
<Generator>PublicResXFileCodeGenerator</Generator>
5459
<LastGenOutput>IdentityProvidersResource.Designer.cs</LastGenOutput>
5560
</EmbeddedResource>
61+
<EmbeddedResource Update="Resources\AuthenticateResource.resx">
62+
<Generator>PublicResXFileCodeGenerator</Generator>
63+
<LastGenOutput>AuthenticateResource.Designer.cs</LastGenOutput>
64+
</EmbeddedResource>
5665
</ItemGroup>
5766
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@model SimpleIdServer.FastFed.ApplicationProvider.UIs.ViewModels.AuthenticateViewModel
2+
@using SimpleIdServer.FastFed.ApplicationProvider.Startup.Resources
3+
4+
@{
5+
ViewBag.Title = AuthenticateResource.Title;
6+
Layout = "~/Views/Shared/_Layout.cshtml";
7+
}
8+
9+
<div>
10+
<div class="card">
11+
<div class="card-body">
12+
<div>
13+
<a class="btn btn-secondary" href="@Url.Action("Login", "Home")">@AuthenticateResource.Authenticate</a>
14+
</div>
15+
<div class="divider">
16+
<p class="fw-bold text">OR</p>
17+
</div>
18+
<div>
19+
<ul class="extauth">
20+
@foreach(var provider in Model.ExternalIdProviders)
21+
{
22+
<li>
23+
<a class="btn btn-secondary" href="@Url.Action("ExternalLogin", "Home", new { scheme = provider.AuthenticationScheme })">@provider.DisplayName</a>
24+
</li>
25+
}
26+
</ul>
27+
</div>
28+
</div>
29+
</div>
30+
</div>

0 commit comments

Comments
 (0)