Skip to content

Commit

Permalink
Merge pull request #14 from aguacongas/develop
Browse files Browse the repository at this point in the history
Remove callback path check
  • Loading branch information
aguacongas authored Dec 22, 2018
2 parents 6c1e968 + c30cb6b commit d728370
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 154 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Store and manage Microsoft.AspNetCore.Authentication providers.

Nuget packages
--------------
|Aguacongas.AspNetCore.Authentication|Aguacongas.AspNetCore.Authentication.EntityFramework|Aguacongas.AspNetCore.Authentication.TestBase|
|:------:|:------:|:------:|
|[![][Aguacongas.AspNetCore.Authentication-badge]][Aguacongas.AspNetCore.Authentication-nuget]|[![][Aguacongas.AspNetCore.Authentication.EntityFramework-badge]][Aguacongas.AspNetCore.Authentication.EntityFramework-nuget]|[![][Aguacongas.AspNetCore.Authentication.TestBase-badge]][Aguacongas.AspNetCore.Authentication.TestBase-nuget]|
|[![][Aguacongas.AspNetCore.Authentication-downloadbadge]][Aguacongas.AspNetCore.Authentication-nuget]|[![][Aguacongas.AspNetCore.Authentication.EntityFramework-downloadbadge]][Aguacongas.AspNetCore.Authentication.EntityFramework-nuget]|[![][Aguacongas.AspNetCore.Authentication.TestBase-downloadbadge]][Aguacongas.AspNetCore.Authentication.TestBase-nuget]|
|Dynamic Provider|EntityFramework Store|Redis Store|Tests Suite|
|:------:|:------:|:------:|:------:|
|[![][Aguacongas.AspNetCore.Authentication-badge]][Aguacongas.AspNetCore.Authentication-nuget]|[![][Aguacongas.AspNetCore.Authentication.EntityFramework-badge]][Aguacongas.AspNetCore.Authentication.EntityFramework-nuget]|[![][Aguacongas.AspNetCore.Authentication.Redis-badge]][Aguacongas.AspNetCore.Authentication.Redis-nuget]|[![][Aguacongas.AspNetCore.Authentication.TestBase-badge]][Aguacongas.AspNetCore.Authentication.TestBase-nuget]|
|[![][Aguacongas.AspNetCore.Authentication-downloadbadge]][Aguacongas.AspNetCore.Authentication-nuget]|[![][Aguacongas.AspNetCore.Authentication.EntityFramework-downloadbadge]][Aguacongas.AspNetCore.Authentication.EntityFramework-nuget]|[![][Aguacongas.AspNetCore.Authentication.Redis-downloadbadge]][Aguacongas.AspNetCore.Authentication.Redis-nuget]|[![][Aguacongas.AspNetCore.Authentication.TestBase-downloadbadge]][Aguacongas.AspNetCore.Authentication.TestBase-nuget]|

[Aguacongas.AspNetCore.Authentication-badge]: https://img.shields.io/nuget/v/Aguacongas.AspNetCore.Authentication.svg
[Aguacongas.AspNetCore.Authentication-downloadbadge]: https://img.shields.io/nuget/dt/Aguacongas.AspNetCore.Authentication.svg
Expand All @@ -20,6 +20,10 @@ Nuget packages
[Aguacongas.AspNetCore.Authentication.EntityFramework-downloadbadge]: https://img.shields.io/nuget/dt/Aguacongas.AspNetCore.Authentication.EntityFramework.svg
[Aguacongas.AspNetCore.Authentication.EntityFramework-nuget]: https://www.nuget.org/packages/Aguacongas.AspNetCore.Authentication.EntityFramework/

[Aguacongas.AspNetCore.Authentication.Redis-badge]: https://img.shields.io/nuget/v/Aguacongas.AspNetCore.Authentication.Redis.svg
[Aguacongas.AspNetCore.Authentication.Redis-downloadbadge]: https://img.shields.io/nuget/dt/Aguacongas.AspNetCore.Authentication.Redis.svg
[Aguacongas.AspNetCore.Authentication.Redis-nuget]: https://www.nuget.org/packages/Aguacongas.AspNetCore.Authentication.Redis/

[Aguacongas.AspNetCore.Authentication.TestBase-badge]: https://img.shields.io/nuget/v/Aguacongas.AspNetCore.Authentication.TestBase.svg
[Aguacongas.AspNetCore.Authentication.TestBase-downloadbadge]: https://img.shields.io/nuget/dt/Aguacongas.AspNetCore.Authentication.TestBase.svg
[Aguacongas.AspNetCore.Authentication.TestBase-nuget]: https://www.nuget.org/packages/Aguacongas.AspNetCore.Authentication.TestBase/
Expand Down
106 changes: 51 additions & 55 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,53 @@ environment:
GH_TOKEN:
secure: 0NJdORJRFjpB0dwUYv7bVNsbkldkoBhnvWik/CTOwAF/k9kP+/uTWMFnDcpEpt8E
init:
- cmd: git config --global core.autocrlf true
- cmd: git config --global core.autocrlf true
install:
- sh: wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
- sh: sudo dpkg -i packages-microsoft-prod.deb
- sh: sudo apt-get -y install apt-transport-https
- sh: sudo apt-get update
- sh: sudo apt-get -y install dotnet-sdk-2.2
- sh: sudo apt -y install nuget
- sh: nuget install GitVersion.CommandLine -ExcludeVersion
- sh: mono GitVersion.CommandLine/tools/GitVersion.exe /l console /output buildserver
- ps: if ($isWindows) { .\dotnet-install.ps1 -Version 2.2.100 }
- cmd: nuget install redis-64 -excludeversion
- cmd: redis-64\tools\redis-server.exe --service-install
- cmd: redis-64\tools\redis-server.exe --service-start
- cmd: gitversion /l console /output buildserver
- cmd: nuget install ReportGenerator -ExcludeVersion
- ps: ./appveyorinit.ps1
- sh: wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
- sh: sudo dpkg -i packages-microsoft-prod.deb
- sh: sudo apt-get -y install apt-transport-https
- sh: sudo apt-get update
- sh: sudo apt-get -y install dotnet-sdk-2.2
- sh: sudo apt -y install nuget
- sh: nuget install GitVersion.CommandLine -ExcludeVersion
- sh: mono GitVersion.CommandLine/tools/GitVersion.exe /l console /output buildserver
- ps: if ($isWindows) { .\dotnet-install.ps1 -Version 2.2.100 }
- cmd: nuget install redis-64 -excludeversion
- cmd: redis-64\tools\redis-server.exe --service-install
- cmd: redis-64\tools\redis-server.exe --service-start
- cmd: gitversion /l console /output buildserver
- cmd: nuget install ReportGenerator -ExcludeVersion
- ps: ./appveyorinit.ps1
build_script:
- ps: ./build.ps1
- ps: ./build.ps1
test_script:
- cmd: publish.cmd
- cmd: publish.cmd
artifacts:
- path: artifacts/**/*.nupkg
name: nuget
- path: artifacts/**/*.nupkg
name: nuget
deploy:
- provider: NuGet
api_key:
secure: 23wPDdRicGt2vZuJ8vd9TRBKmqjHkx5WjzZmKvyxd5j0fNPedjUScRTj/rT0ObJa
on:
branch:
- /preview\/*/
- /release\/*/
CI_WINDOWS: true
- provider: GitHub
auth_token: $(GH_TOKEN)
draft: true
prerelease: true
release: $(Version)
on:
branch:
- /preview*/
CI_WINDOWS: true
- provider: NuGet
api_key:
secure: 23wPDdRicGt2vZuJ8vd9TRBKmqjHkx5WjzZmKvyxd5j0fNPedjUScRTj/rT0ObJa
on:
branch:
- /preview\/*/
- /release\/*/
CI_WINDOWS: true
- provider: GitHub
auth_token: $(GH_TOKEN)
draft: true
prerelease: true
release: $(Version)
on:
branch:
- /preview*/
CI_WINDOWS: true
for:
-
branches:
only:
- master
- master
on_success:
- cmd: git config --global credential.helper store
- ps: if ($isWindows) { Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:GH_TOKEN):[email protected]`n" }
Expand All @@ -77,21 +77,17 @@ for:
-
branches:
only:
- /release>\/*/
- /release>\/*/
on_success:
- cmd: semantic-release -b %APPVEYOR_REPO_BRANCH%
- cmd: git config --global credential.helper store
- ps: if ($isWindows) { Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:GH_TOKEN):[email protected]`n" }
- cmd: git config --global user.email "[email protected]"
- cmd: git config --global user.name "Aguacongas"
- cmd: git checkout gh-pages
- cmd: git stash
- cmd: mkdir %Version%
- cmd: move coverage\docs %Version%
- cmd: git add %Version%
- cmd: git commit %Version% -m "Appveyor build succed %APPVEYOR_BUILD_NUMBER%"
- cmd: git push
-
branches:
except:
- master
- cmd: semantic-release -b %APPVEYOR_REPO_BRANCH%
- cmd: git config --global credential.helper store
- ps: if ($isWindows) { Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:GH_TOKEN):[email protected]`n" }
- cmd: git config --global user.email "[email protected]"
- cmd: git config --global user.name "Aguacongas"
- cmd: git checkout gh-pages
- cmd: git stash
- cmd: mkdir %Version%
- cmd: move coverage\docs %Version%
- cmd: git add %Version%
- cmd: git commit %Version% -m "Appveyor build succed %APPVEYOR_BUILD_NUMBER%"
- cmd: git push
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
<PackageTags>aspnetcore authentication security sample</PackageTags>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Include="Aguacongas.AspNetCore.Authentication.EntityFramework" Version="1.0.0-preview*" />
<PackageReference Include="Aguacongas.AspNetCore.Authentication.Redis" Version="1.0.0-preview*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Project: aguacongas/DymamicAuthProviders
// Copyright (c) 2018 @Olivier Lefebvre
using Aguacongas.AspNetCore.Authentication.EntityFramework;
using Aguacongas.AspNetCore.Authentication.Sample.Helpers;
using Aguacongas.AspNetCore.Authentication.Sample.Models;
using Microsoft.AspNetCore.Authentication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Aguacongas.AspNetCore.Authentication.EntityFramework;
using System.Threading.Tasks;

namespace Aguacongas.AspNetCore.Authentication.Sample
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
<RepositoryUrl>https://github.com/aguacongas/DymamicAuthProviders</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>aspnetcore;authentication;security;entityframeworkcore</PackageTags>
<Description>Provider for DinamicAuthProviders that uses Entity Framework Core.
<Description>Provider for DinamicAuthProviders that uses Entity Framework Core.</Description>
<DebugType>Full</DebugType>
</Description>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Project: aguacongas/DymamicAuthProviders
// Copyright (c) 2018 @Olivier Lefebvre
using Aguacongas.AspNetCore.Authentication.EntityFramework;

namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// IApplicationBuilder extensions
/// </summary>
public static class ApplicationBuilderExtensions
{
/// <summary>
/// Loads the dynamic authentication configuration.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns></returns>
public static IApplicationBuilder LoadDynamicAuthenticationConfiguration(this IApplicationBuilder builder)
{
builder.ApplicationServices.LoadDynamicAuthenticationConfiguration<SchemeDefinition>();
return builder;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Project: aguacongas/DymamicAuthProviders
// Copyright (c) 2018 @Olivier Lefebvre
namespace Aguacongas.AspNetCore.Authentication
namespace Aguacongas.AspNetCore.Authentication.EntityFramework
{
/// <summary>
/// Scheme definition for entity framework store
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>Olivier Lefebvre</Authors>
<Copyright>Copyright (c) 2018 @Olivier Lefebvre</Copyright>
<PackageLicenseUrl>https://raw.githubusercontent.com/aguacongas/DymamicAuthProviders/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/aguacongas/DymamicAuthProviders/tree/master/sample/Aguacongas.AspNetCore.Redis</PackageProjectUrl>
<RepositoryUrl>https://github.com/aguacongas/DymamicAuthProviders</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>aspnetcore;authentication;security;redis</PackageTags>
<Description>Provider for DinamicAuthProviders that uses Redis.</Description>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Project: aguacongas/DymamicAuthProviders
// Copyright (c) 2018 @Olivier Lefebvre
using Aguacongas.AspNetCore.Authentication.Redis;

namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// IApplicationBuilder extensions
/// </summary>
public static class ApplicationBuilderExtensions
{
/// <summary>
/// Loads the dynamic authentication configuration.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns></returns>
public static IApplicationBuilder LoadDynamicAuthenticationConfiguration(this IApplicationBuilder builder)
{
builder.ApplicationServices.LoadDynamicAuthenticationConfiguration<SchemeDefinition>();
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -465,44 +465,6 @@ Task onTicketReceived(TicketReceivedContext context)
Assert.True(eventCalled);
}

/// <summary>
/// AddAsync method should ensure uniq callback path.
/// </summary>
/// <returns></returns>
[Fact]
public async Task AddAsync_should_ensure_uniq_callback_path()
{
var provider = CreateServiceProvider(options =>
{
options.AddTwitter();
});

var twittertOptions = new TwitterOptions
{
ConsumerKey = "test",
ConsumerSecret = "test"
};

var scheme = Guid.NewGuid().ToString();
var definition = new TSchemeDefinition
{
Scheme = scheme,
DisplayName = "test",
HandlerType = typeof(TwitterHandler),
Options = twittertOptions
};

var sut = provider.GetRequiredService<PersistentDynamicManager<TSchemeDefinition>>();
Assert.Contains(typeof(TwitterHandler), sut.ManagedHandlerType);

await sut.AddAsync(definition);
var state = await VerifyAddedAsync<TwitterOptions>(scheme, provider);

definition.Scheme = Guid.NewGuid().ToString();

await Assert.ThrowsAsync<InvalidOperationException>(() => sut.AddAsync(definition));
}

/// <summary>
/// AddAsync method should add ws federation handler.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,6 @@ public DynamicAuthenticationBuilder(IServiceCollection services, Type definition
DefinitionType = definitionType;
}

/// <summary>
/// Adds a <see cref="T:Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1" /> based <see cref="T:Microsoft.AspNetCore.Authentication.AuthenticationScheme" /> that supports remote authentication
/// which can be used by <see cref="T:Microsoft.AspNetCore.Authentication.IAuthenticationService" />.
/// </summary>
/// <typeparam name="TOptions">The <see cref="T:Microsoft.AspNetCore.Authentication.RemoteAuthenticationOptions" /> type to configure the handler."/&gt;.</typeparam>
/// <typeparam name="THandler">The <see cref="T:Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1" /> used to handle this scheme.</typeparam>
/// <param name="authenticationScheme">The name of this scheme.</param>
/// <param name="displayName">The display name of this scheme.</param>
/// <param name="configureOptions">Used to configure the scheme options.</param>
/// <returns>
/// The builder.
/// </returns>
public override AuthenticationBuilder AddRemoteScheme<TOptions, THandler>(string authenticationScheme, string displayName, Action<TOptions> configureOptions)
{
Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<TOptions>, EnsureUniqCallbackPath<TOptions, THandler>>());
return base.AddRemoteScheme<TOptions, THandler>(authenticationScheme, displayName, configureOptions);
}

/// <summary>
/// Adds a <see cref="T:Microsoft.AspNetCore.Authentication.AuthenticationScheme" /> which can be used by <see cref="T:Microsoft.AspNetCore.Authentication.IAuthenticationService" />.
/// </summary>
Expand Down Expand Up @@ -88,34 +70,5 @@ public override AuthenticationBuilder AddScheme<TOptions, THandler>(string authe
);
return this;
}

private class EnsureUniqCallbackPath<TOptions, THandler> : IPostConfigureOptions<TOptions> where TOptions : RemoteAuthenticationOptions
{
private readonly IAuthenticationSchemeProvider _schemeProvider;
private readonly IOptionsMonitorCache<AuthenticationSchemeOptions> _monitorCache;

public EnsureUniqCallbackPath(IAuthenticationSchemeProvider schemeProvider, IOptionsMonitorCache<AuthenticationSchemeOptions> monitorCache)
{
_schemeProvider = schemeProvider;
_monitorCache = monitorCache;
}

public void PostConfigure(string name, TOptions options)
{
var schemes = _schemeProvider.GetAllSchemesAsync().GetAwaiter().GetResult();
foreach(var scheme in schemes)
{
if (name == scheme.Name)
{
continue;
}
var other = _monitorCache.GetOrAdd(scheme.Name, () => options);
if (other is RemoteAuthenticationOptions otherRemote && otherRemote.CallbackPath == options.CallbackPath)
{
throw new InvalidOperationException($"Callbacks paths for schemes {name} and {scheme.Name} are equals: {options.CallbackPath}");
}
}
}
}
}
}
3 changes: 0 additions & 3 deletions src/Aguacongas.AspNetCore.Authentication/DynamicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ public virtual Task<TSchemeDefinition> FindBySchemeAsync(string scheme)
/// </summary>
public virtual void Load()
{
var platform = Environment.OSVersion.Platform.ToString();
var runtimeAssemblyNames = DependencyContext.Default.GetRuntimeAssemblyNames(platform);

foreach (var definition in _store.SchemeDefinitions)
{
if (ManagedHandlerType.Contains(definition.HandlerType))
Expand Down

0 comments on commit d728370

Please sign in to comment.