Skip to content

Commit

Permalink
Add deployment for Microsoft Account (#16806)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Mike Alhayek <mike@crestapps.com>
  • Loading branch information
hishamco and MikeAlhayek authored Oct 4, 2024
1 parent 17017e3 commit 412e257
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Microsoft.Identity.Web;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Microsoft.Authentication.Configuration;
using OrchardCore.Microsoft.Authentication.Deployment;
using OrchardCore.Microsoft.Authentication.Drivers;
using OrchardCore.Microsoft.Authentication.Recipes;
using OrchardCore.Microsoft.Authentication.Services;
using OrchardCore.Microsoft.Authentication.Settings;
using OrchardCore.Modules;
using OrchardCore.Navigation;
using OrchardCore.Recipes;
using OrchardCore.Security.Permissions;

namespace OrchardCore.Microsoft.Authentication;

[Feature(MicrosoftAuthenticationConstants.Features.AAD)]
public sealed class AzureADStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddPermissionProvider<Permissions>();

services.AddSingleton<IAzureADService, AzureADService>();
services.AddRecipeExecutionStep<AzureADSettingsStep>();

services.AddSiteDisplayDriver<AzureADSettingsDisplayDriver>();
services.AddNavigationProvider<AdminMenuAAD>();

services.AddTransient<IConfigureOptions<AzureADSettings>, AzureADSettingsConfiguration>();

services.AddTransient<IConfigureOptions<AuthenticationOptions>, AzureADOptionsConfiguration>();
services.AddTransient<IConfigureOptions<MicrosoftIdentityOptions>, AzureADOptionsConfiguration>();
services.AddTransient<IConfigureOptions<PolicySchemeOptions>, AzureADOptionsConfiguration>();
services.AddTransient<IConfigureOptions<OpenIdConnectOptions>, OpenIdConnectOptionsConfiguration>();

services.AddSingleton<IPostConfigureOptions<OpenIdConnectOptions>, OpenIdConnectPostConfigureOptions>();
}
}

[RequireFeatures("OrchardCore.Deployment")]
[Feature(MicrosoftAuthenticationConstants.Features.AAD)]
public sealed class AzureADDeploymentStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddDeployment<AzureADDeploymentSource, AzureADDeploymentStep, AzureADDeploymentStepDriver>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Text.Json.Nodes;
using OrchardCore.Deployment;
using OrchardCore.Microsoft.Authentication.Services;
using OrchardCore.Microsoft.Authentication.Settings;

namespace OrchardCore.Microsoft.Authentication.Deployment;

public sealed class MicrosoftAccountDeploymentSource : IDeploymentSource
{
private readonly IMicrosoftAccountService _microsoftAccountService;

public MicrosoftAccountDeploymentSource(IMicrosoftAccountService microsoftAccountService)
{
_microsoftAccountService = microsoftAccountService;
}

public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
{
if (step is not MicrosoftAccountDeploymentStep)
{
return;
}

var microsoftAccountSettings = await _microsoftAccountService.GetSettingsAsync();

result.Steps.Add(new JsonObject
{
["name"] = "Settings",
[nameof(MicrosoftAccountSettings)] = JObject.FromObject(microsoftAccountSettings),
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using OrchardCore.Deployment;

namespace OrchardCore.Microsoft.Authentication.Deployment;

public sealed class MicrosoftAccountDeploymentStep : DeploymentStep
{
public MicrosoftAccountDeploymentStep()
{
Name = "MicrosoftAccount";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;

namespace OrchardCore.Microsoft.Authentication.Deployment;

public sealed class MicrosoftAccountDeploymentStepDriver : DisplayDriver<DeploymentStep, MicrosoftAccountDeploymentStep>
{
public override Task<IDisplayResult> DisplayAsync(MicrosoftAccountDeploymentStep step, BuildDisplayContext context)
{
return CombineAsync(
View("MicrosoftAccountDeploymentStep_Summary", step).Location("Summary", "Content"),
View("MicrosoftAccountDeploymentStep_Thumbnail", step).Location("Thumbnail", "Content")
);
}

public override IDisplayResult Edit(MicrosoftAccountDeploymentStep step, BuildEditorContext context)
=> View("MicrosoftAccountDeploymentStep_Edit", step).Location("Content");
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.MicrosoftAccount;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Microsoft.Identity.Web;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Microsoft.Authentication.Configuration;
Expand Down Expand Up @@ -47,42 +45,12 @@ public override void ConfigureServices(IServiceCollection services)
}
}

[Feature(MicrosoftAuthenticationConstants.Features.AAD)]
public sealed class AzureADStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.TryAddEnumerable(new ServiceDescriptor(typeof(IPermissionProvider), typeof(Permissions), ServiceLifetime.Scoped));

services.AddSingleton<IAzureADService, AzureADService>();
services.AddRecipeExecutionStep<AzureADSettingsStep>();

services.AddSiteDisplayDriver<AzureADSettingsDisplayDriver>();
services.AddNavigationProvider<AdminMenuAAD>();

services.AddTransient<IConfigureOptions<AzureADSettings>, AzureADSettingsConfiguration>();

// Register the options initializers required by the Policy Scheme, Cookie and OpenId Connect Handler.
services.TryAddEnumerable(new[]
{
// Orchard-specific initializers.
ServiceDescriptor.Transient<IConfigureOptions<AuthenticationOptions>, AzureADOptionsConfiguration>(),
ServiceDescriptor.Transient<IConfigureOptions<MicrosoftIdentityOptions>, AzureADOptionsConfiguration>(),
ServiceDescriptor.Transient<IConfigureOptions<PolicySchemeOptions>, AzureADOptionsConfiguration>(),
ServiceDescriptor.Transient<IConfigureOptions<OpenIdConnectOptions>, OpenIdConnectOptionsConfiguration>(),

// Built-in initializers:
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIdConnectOptions>, OpenIdConnectPostConfigureOptions>(),
});
}
}

[RequireFeatures("OrchardCore.Deployment")]
[Feature(MicrosoftAuthenticationConstants.Features.AAD)]
public sealed class DeploymentStartup : StartupBase
[Feature(MicrosoftAuthenticationConstants.Features.MicrosoftAccount)]
public sealed class MicrosoftAccountDeploymentStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddDeployment<AzureADDeploymentSource, AzureADDeploymentStep, AzureADDeploymentStepDriver>();
services.AddDeployment<MicrosoftAccountDeploymentSource, MicrosoftAccountDeploymentStep, MicrosoftAccountDeploymentStepDriver>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h5>@T["Microsoft Account Settings"]</h5>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h5>@T["Microsoft Account Settings"]</h5>

<span class="hint">@T["Adds Microsoft Account settings to the plan."]</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h4 class="card-title">@T["Microsoft Account Settings"]</h4>
<p>@T["Exports the Microsoft Account settings."]</p>

0 comments on commit 412e257

Please sign in to comment.