Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.Json.Nodes;
using Microsoft.AspNetCore.DataProtection;
using OrchardCore.OpenId.Configuration;
using OrchardCore.OpenId.Services;
using OrchardCore.OpenId.Settings;
using OrchardCore.Recipes.Models;
Expand All @@ -12,23 +14,37 @@ namespace OrchardCore.OpenId.Recipes;
public sealed class OpenIdClientSettingsStep : NamedRecipeStepHandler
{
private readonly IOpenIdClientService _clientService;
private readonly IDataProtectionProvider _dataProtectionProvider;

public OpenIdClientSettingsStep(IOpenIdClientService clientService)
private static readonly char[] ScopeDelimiters = [' ', ','];

public OpenIdClientSettingsStep(
IOpenIdClientService clientService,
IDataProtectionProvider dataProtectionProvider)
: base("OpenIdClientSettings")
{
_clientService = clientService;
_dataProtectionProvider = dataProtectionProvider;
}

protected override async Task HandleAsync(RecipeExecutionContext context)
{
var model = context.Step.ToObject<OpenIdClientSettingsStepModel>();
var settings = await _clientService.LoadSettingsAsync();

settings.Scopes = model.Scopes.Split(' ', ',');
settings.Scopes = model.Scopes?.Split(ScopeDelimiters, StringSplitOptions.RemoveEmptyEntries);
settings.Authority = !string.IsNullOrEmpty(model.Authority) ? new Uri(model.Authority, UriKind.Absolute) : null;
settings.CallbackPath = model.CallbackPath;
settings.ClientId = model.ClientId;
settings.ClientSecret = model.ClientSecret;
if (!string.IsNullOrEmpty(model.ClientSecret))
{
settings.ClientSecret = model.ClientSecret;
}
else if (!string.IsNullOrEmpty(model.ClientSecretPlainText))
{
var protector = _dataProtectionProvider.CreateProtector(nameof(OpenIdClientConfiguration));
settings.ClientSecret = protector.Protect(model.ClientSecret);
}
settings.DisplayName = model.DisplayName;
settings.ResponseMode = model.ResponseMode;
settings.ResponseType = model.ResponseType;
Expand All @@ -50,6 +66,7 @@ public sealed class OpenIdClientSettingsStepModel

public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string ClientSecretPlainText { get; set; }
public string CallbackPath { get; set; }
public string SignedOutRedirectUri { get; set; }
public string SignedOutCallbackPath { get; set; }
Expand Down
Loading