forked from OrchardCMS/OrchardCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.AspNetCore.Modules; | ||
using Microsoft.AspNetCore.Mvc.ApplicationModels; | ||
using Microsoft.AspNetCore.Mvc.Cors; | ||
using Microsoft.AspNetCore.Mvc.Cors.Internal; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
namespace Orchard.Cors | ||
{ | ||
[Feature("Orchard.Cors.Mvc")] | ||
public class CorsMvcStartup : StartupBase | ||
{ | ||
public override void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.TryAddEnumerable(ServiceDescriptor.Transient<IApplicationModelProvider, CorsApplicationModelProvider>()); | ||
services.TryAddTransient<CorsAuthorizationFilter, CorsAuthorizationFilter>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.AspNetCore.Modules; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Orchard.Cors | ||
{ | ||
public class CorsStartup : StartupBase | ||
{ | ||
public override void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddCors(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Name: Cors | ||
AntiForgery: enabled | ||
Author: The Orchard Team | ||
Website: http://orchardproject.net | ||
Version: 2.0.x | ||
OrchardVersion: 2.0.x | ||
Description: Adds Cross-Origin Resource Sharing | ||
Priority: 1 | ||
Category: Security | ||
Features: | ||
Orchard.Cors: | ||
Name: Cors | ||
Description: Feature Adds CORS services. | ||
Category: Security | ||
Orchard.Cors.Mvc: | ||
Name: Cors Mvc | ||
Description: Feature allows apply CORS policies per Mvc Controller or Action. | ||
Dependencies: Orchard.Cors | ||
Category: Security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard1.6</TargetFramework> | ||
<Description>Cross-Origin Resource Sharing Feature</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="1.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\OrchardCore\OrchardCore.AsModule\OrchardCore.AsModule.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Orchard.OpenId | ||
{ | ||
public class Constants | ||
{ | ||
public const string OpenIdConnectPolicy = "OpenIdConnectPolicy"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/OrchardCore.Modules/Orchard.OpenId/Services/OpenIdCorsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Cors.Infrastructure; | ||
using Microsoft.AspNetCore.Modules; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Orchard.OpenId.Services | ||
{ | ||
[RequireFeatures("Orchard.Cors.Mvc")] | ||
public class OpenIdCorsConfiguration : IConfigureOptions<CorsOptions> | ||
{ | ||
private readonly IOpenIdService _openIdService; | ||
|
||
public OpenIdCorsConfiguration(IOpenIdService openIdService) | ||
{ | ||
_openIdService = openIdService; | ||
} | ||
|
||
public void Configure(CorsOptions options) | ||
{ | ||
var openIdSettings = _openIdService.GetOpenIdSettingsAsync().GetAwaiter().GetResult(); | ||
if (openIdSettings.Audiences != null && openIdSettings.Audiences.Any()) | ||
options.AddPolicy(Constants.OpenIdConnectPolicy, builder => builder | ||
.WithOrigins(openIdSettings.Audiences.ToArray()) | ||
.AllowAnyHeader() | ||
.AllowAnyMethod() | ||
.AllowCredentials() | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters