24 changed files with 400 additions and 156 deletions
@ -0,0 +1,22 @@ |
|||||
|
/* |
||||
|
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
* See https://github.com/openiddict/core for more information concerning
|
||||
|
* the license and the contributors participating to this project. |
||||
|
*/ |
||||
|
|
||||
|
using System.Reflection; |
||||
|
using Microsoft.AspNet.FileProviders; |
||||
|
using Microsoft.AspNet.StaticFiles; |
||||
|
using Microsoft.Extensions.Internal; |
||||
|
|
||||
|
namespace Microsoft.AspNet.Builder { |
||||
|
public static class OpenIddictExtensions { |
||||
|
public static OpenIddictBuilder UseAssets([NotNull] this OpenIddictBuilder builder) { |
||||
|
return builder.AddModule(-20, app => app.UseStaticFiles(new StaticFileOptions { |
||||
|
FileProvider = new EmbeddedFileProvider( |
||||
|
assembly: Assembly.Load(new AssemblyName("OpenIddict.Assets")), |
||||
|
baseNamespace: "OpenIddict.Assets") |
||||
|
})); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using System; |
||||
|
using Microsoft.AspNet.Builder; |
||||
|
|
||||
|
namespace OpenIddict { |
||||
|
/// <summary>
|
||||
|
/// Defines an OpenIddict module.
|
||||
|
/// </summary>
|
||||
|
public class OpenIddictModule { |
||||
|
/// <summary>
|
||||
|
/// Gets or sets the position of the module in the ASP.NET pipeline.
|
||||
|
/// </summary>
|
||||
|
public int Position { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the delegate used to register
|
||||
|
/// the OpenIddict module in the ASP.NET pipeline.
|
||||
|
/// </summary>
|
||||
|
public Action<IApplicationBuilder> Registration { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -1,41 +1,26 @@ |
|||||
{ |
{ |
||||
"version": "1.0.0-alpha1-*", |
"version": "1.0.0-alpha1-*", |
||||
|
|
||||
"resource": "Views/**", |
"description": "Core components of OpenIddict.", |
||||
|
|
||||
"dependencies": { |
"dependencies": { |
||||
"Microsoft.AspNet.Cors": "6.0.0-*", |
"Microsoft.AspNet.Cors": "6.0.0-*", |
||||
"Microsoft.AspNet.FileProviders.Embedded": "1.0.0-*", |
"Microsoft.AspNet.FileProviders.Embedded": "1.0.0-*", |
||||
"Microsoft.AspNet.Identity": "3.0.0-*", |
"Microsoft.AspNet.Identity": "3.0.0-*", |
||||
"Microsoft.AspNet.Mvc": "6.0.0-*", |
|
||||
"Microsoft.AspNet.StaticFiles": "1.0.0-*", |
|
||||
|
|
||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-*", |
"Microsoft.Extensions.Configuration": "1.0.0-*", |
||||
|
"Microsoft.Extensions.Caching.Memory": "1.0.0-*", |
||||
|
|
||||
"Microsoft.Extensions.NotNullAttribute.Sources": { |
"Microsoft.Extensions.NotNullAttribute.Sources": { |
||||
"type": "build", |
"type": "build", |
||||
"version": "1.0.0-*" |
"version": "1.0.0-*" |
||||
}, |
}, |
||||
|
|
||||
"AspNet.Hosting.Extensions": "1.0.0-*", |
"AspNet.Security.OpenIdConnect.Server": "1.0.0-*" |
||||
"AspNet.Security.OpenIdConnect.Server": "1.0.0-*", |
|
||||
|
|
||||
"OpenIddict.Assets": "1.0.0-*" |
|
||||
}, |
}, |
||||
|
|
||||
"frameworks": { |
"frameworks": { |
||||
"dnx451": { |
"dnx451": { }, |
||||
"dependencies": { |
"dnxcore50": { } |
||||
"AspNet.Hosting.Katana.Extensions": "1.0.0-*", |
|
||||
"NWebsec.Owin": "1.0.0" |
|
||||
} |
|
||||
}, |
|
||||
|
|
||||
"dnxcore50": { |
|
||||
"dependencies": { |
|
||||
"System.Linq": "4.0.1-*", |
|
||||
"System.Runtime.Serialization.Primitives": "4.0.11-*" |
|
||||
} |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<PropertyGroup> |
||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> |
||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> |
||||
|
<PropertyGroup Label="Globals"> |
||||
|
<ProjectGuid>7ae46e2f-e93b-4ff9-b941-6cd7a3e1bf84</ProjectGuid> |
||||
|
<RootNamespace>OpenIddict.Mvc</RootNamespace> |
||||
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> |
||||
|
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<SchemaVersion>2.0</SchemaVersion> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> |
||||
|
</Project> |
||||
@ -0,0 +1,170 @@ |
|||||
|
/* |
||||
|
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
* See https://github.com/openiddict/core for more information concerning
|
||||
|
* the license and the contributors participating to this project. |
||||
|
*/ |
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Diagnostics; |
||||
|
using System.Reflection; |
||||
|
using Microsoft.AspNet.FileProviders; |
||||
|
using Microsoft.AspNet.Http; |
||||
|
using Microsoft.AspNet.Identity; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Internal; |
||||
|
using Microsoft.Extensions.Primitives; |
||||
|
using OpenIddict; |
||||
|
|
||||
|
#if DNX451
|
||||
|
using NWebsec.Owin; |
||||
|
#endif
|
||||
|
|
||||
|
namespace Microsoft.AspNet.Builder { |
||||
|
public static class OpenIddictExtensions { |
||||
|
public static OpenIddictBuilder UseMvc([NotNull] this OpenIddictBuilder builder) { |
||||
|
#if DNX451
|
||||
|
builder.AddModule(-20, app => app.UseKatana(owin => { |
||||
|
// Insert a new middleware responsible of setting the Content-Security-Policy header.
|
||||
|
// See https://nwebsec.codeplex.com/wikipage?title=Configuring%20Content%20Security%20Policy&referringTitle=NWebsec
|
||||
|
owin.UseCsp(options => options.DefaultSources(directive => directive.Self()) |
||||
|
.ImageSources(directive => directive.Self().CustomSources("*")) |
||||
|
.ScriptSources(directive => directive.UnsafeInline()) |
||||
|
.StyleSources(directive => directive.Self().UnsafeInline())); |
||||
|
|
||||
|
// Insert a new middleware responsible of setting the X-Content-Type-Options header.
|
||||
|
// See https://nwebsec.codeplex.com/wikipage?title=Configuring%20security%20headers&referringTitle=NWebsec
|
||||
|
owin.UseXContentTypeOptions(); |
||||
|
|
||||
|
// Insert a new middleware responsible of setting the X-Frame-Options header.
|
||||
|
// See https://nwebsec.codeplex.com/wikipage?title=Configuring%20security%20headers&referringTitle=NWebsec
|
||||
|
owin.UseXfo(options => options.Deny()); |
||||
|
|
||||
|
// Insert a new middleware responsible of setting the X-Xss-Protection header.
|
||||
|
// See https://nwebsec.codeplex.com/wikipage?title=Configuring%20security%20headers&referringTitle=NWebsec
|
||||
|
owin.UseXXssProtection(options => options.EnabledWithBlockMode()); |
||||
|
})); |
||||
|
#endif
|
||||
|
|
||||
|
// Run the rest of the pipeline in an isolated environment.
|
||||
|
builder.AddModule(10, app => app.Isolate(map => map.UseMvc(routes => { |
||||
|
// Register the actions corresponding to the authorization endpoint.
|
||||
|
if (builder.Options.AuthorizationEndpointPath.HasValue) { |
||||
|
routes.MapRoute("{D97891B4}", builder.Options.AuthorizationEndpointPath.Value.Substring(1), new { |
||||
|
controller = typeof(OpenIddictController<,>).Name, |
||||
|
action = nameof(OpenIddictController<dynamic, dynamic>.Authorize) |
||||
|
}); |
||||
|
|
||||
|
routes.MapRoute("{7148DB83}", builder.Options.AuthorizationEndpointPath.Value.Substring(1) + "/accept", new { |
||||
|
controller = typeof(OpenIddictController<,>).Name, |
||||
|
action = nameof(OpenIddictController<dynamic, dynamic>.Accept) |
||||
|
}); |
||||
|
|
||||
|
routes.MapRoute("{23438BCC}", builder.Options.AuthorizationEndpointPath.Value.Substring(1) + "/deny", new { |
||||
|
controller = typeof(OpenIddictController<,>).Name, |
||||
|
action = nameof(OpenIddictController<dynamic, dynamic>.Deny) |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
// Register the action corresponding to the logout endpoint.
|
||||
|
if (builder.Options.LogoutEndpointPath.HasValue) { |
||||
|
routes.MapRoute("{C7DB102A}", builder.Options.LogoutEndpointPath.Value.Substring(1), new { |
||||
|
controller = typeof(OpenIddictController<,>).Name, |
||||
|
action = nameof(OpenIddictController<dynamic, dynamic>.Logout) |
||||
|
}); |
||||
|
} |
||||
|
}), services => { |
||||
|
var registration = builder.Builder.ApplicationServices.GetRequiredService<OpenIddictServices>(); |
||||
|
|
||||
|
services.AddMvc() |
||||
|
// Register the OpenIddict controller.
|
||||
|
.AddControllersAsServices(new[] { |
||||
|
typeof(OpenIddictController<,>).MakeGenericType(registration.UserType, registration.ApplicationType) |
||||
|
}) |
||||
|
|
||||
|
.AddRazorOptions(options => { |
||||
|
// Update the Razor options to also use a combined provider that
|
||||
|
// falls back to the current assembly when searching for views.
|
||||
|
options.FileProvider = new CombinedFileSystemProvider(new[] { |
||||
|
options.FileProvider, |
||||
|
new EmbeddedFileProvider( |
||||
|
assembly: typeof(OpenIddictController<,>).GetTypeInfo().Assembly, |
||||
|
baseNamespace: "OpenIddict.Mvc") |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
// Register the sign-in manager in the isolated container.
|
||||
|
services.AddScoped(typeof(SignInManager<>).MakeGenericType(registration.UserType), provider => { |
||||
|
var accessor = provider.GetRequiredService<IHttpContextAccessor>(); |
||||
|
var container = (IServiceProvider) accessor.HttpContext.Items[typeof(IServiceProvider)]; |
||||
|
Debug.Assert(container != null); |
||||
|
|
||||
|
// Resolve the sign-in manager from the parent container.
|
||||
|
return container.GetRequiredService(typeof(SignInManager<>).MakeGenericType(registration.UserType)); |
||||
|
}); |
||||
|
|
||||
|
// Register the user manager in the isolated container.
|
||||
|
services.AddScoped(typeof(OpenIddictManager<,>).MakeGenericType(registration.UserType, registration.ApplicationType), provider => { |
||||
|
var accessor = provider.GetRequiredService<IHttpContextAccessor>(); |
||||
|
var container = (IServiceProvider) accessor.HttpContext.Items[typeof(IServiceProvider)]; |
||||
|
Debug.Assert(container != null); |
||||
|
|
||||
|
// Resolve the user manager from the parent container.
|
||||
|
return container.GetRequiredService(typeof(OpenIddictManager<,>).MakeGenericType(registration.UserType, registration.ApplicationType)); |
||||
|
}); |
||||
|
|
||||
|
// Register the options in the isolated container.
|
||||
|
services.AddScoped(provider => builder.Options); |
||||
|
})); |
||||
|
|
||||
|
return builder; |
||||
|
} |
||||
|
|
||||
|
private class CombinedFileSystemProvider : IFileProvider { |
||||
|
public CombinedFileSystemProvider(IList<IFileProvider> providers) { |
||||
|
Providers = providers; |
||||
|
} |
||||
|
|
||||
|
public IList<IFileProvider> Providers { get; } |
||||
|
|
||||
|
public IDirectoryContents GetDirectoryContents(string subpath) { |
||||
|
for (var index = 0; index < Providers.Count; index++) { |
||||
|
var provider = Providers[index]; |
||||
|
|
||||
|
var result = provider.GetDirectoryContents(subpath); |
||||
|
if (result != null && result.Exists) { |
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return new NotFoundDirectoryContents(); |
||||
|
} |
||||
|
|
||||
|
public IFileInfo GetFileInfo(string subpath) { |
||||
|
for (var index = 0; index < Providers.Count; index++) { |
||||
|
var provider = Providers[index]; |
||||
|
|
||||
|
var result = provider.GetFileInfo(subpath); |
||||
|
if (result != null && result.Exists) { |
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return new NotFoundFileInfo(subpath); |
||||
|
} |
||||
|
|
||||
|
public IChangeToken Watch(string filter) { |
||||
|
for (var index = 0; index < Providers.Count; index++) { |
||||
|
var provider = Providers[index]; |
||||
|
|
||||
|
var result = provider.Watch(filter); |
||||
|
if (result != null) { |
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return NoopChangeToken.Singleton; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
using System.Reflection; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
// General Information about an assembly is controlled through the following
|
||||
|
// set of attributes. Change these attribute values to modify the information
|
||||
|
// associated with an assembly.
|
||||
|
[assembly: AssemblyTitle("OpenIddict.Mvc")] |
||||
|
[assembly: AssemblyDescription("")] |
||||
|
[assembly: AssemblyConfiguration("")] |
||||
|
[assembly: AssemblyCompany("")] |
||||
|
[assembly: AssemblyProduct("OpenIddict.Mvc")] |
||||
|
[assembly: AssemblyCopyright("Copyright © 2015")] |
||||
|
[assembly: AssemblyTrademark("")] |
||||
|
[assembly: AssemblyCulture("")] |
||||
|
|
||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
|
// to COM components. If you need to access a type in this assembly from
|
||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||
|
[assembly: ComVisible(false)] |
||||
|
|
||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
|
[assembly: Guid("7ae46e2f-e93b-4ff9-b941-6cd7a3e1bf84")] |
||||
@ -0,0 +1,37 @@ |
|||||
|
{ |
||||
|
"version": "1.0.0-alpha1-*", |
||||
|
|
||||
|
"description": "MVC 6 module for OpenIddict.", |
||||
|
|
||||
|
"resource": "Views/**", |
||||
|
|
||||
|
"dependencies": { |
||||
|
"Microsoft.AspNet.FileProviders.Embedded": "1.0.0-*", |
||||
|
"Microsoft.AspNet.Mvc": "6.0.0-*", |
||||
|
|
||||
|
"Microsoft.AspNet.FileProviders.Sources": { |
||||
|
"type": "build", |
||||
|
"version": "1.0.0-*" |
||||
|
}, |
||||
|
|
||||
|
"Microsoft.Extensions.NotNullAttribute.Sources": { |
||||
|
"type": "build", |
||||
|
"version": "1.0.0-*" |
||||
|
}, |
||||
|
|
||||
|
"AspNet.Hosting.Extensions": "1.0.0-*", |
||||
|
|
||||
|
"OpenIddict.Core": "1.0.0-*" |
||||
|
}, |
||||
|
|
||||
|
"frameworks": { |
||||
|
"dnx451": { |
||||
|
"dependencies": { |
||||
|
"AspNet.Hosting.Katana.Extensions": "1.0.0-*", |
||||
|
"NWebsec.Owin": "1.0.0" |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
"dnxcore50": { } |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue