-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathOpenIdClientSettingsStep.cs
More file actions
78 lines (68 loc) · 2.97 KB
/
OpenIdClientSettingsStep.cs
File metadata and controls
78 lines (68 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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;
using OrchardCore.Recipes.Services;
namespace OrchardCore.OpenId.Recipes;
/// <summary>
/// This recipe step sets general OpenID Connect Client settings.
/// </summary>
public sealed class OpenIdClientSettingsStep : NamedRecipeStepHandler
{
private readonly IOpenIdClientService _clientService;
private readonly IDataProtectionProvider _dataProtectionProvider;
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(ScopeDelimiters, StringSplitOptions.RemoveEmptyEntries);
settings.Authority = !string.IsNullOrEmpty(model.Authority) ? new Uri(model.Authority, UriKind.Absolute) : null;
settings.CallbackPath = model.CallbackPath;
settings.ClientId = model.ClientId;
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;
settings.SignedOutCallbackPath = model.SignedOutCallbackPath;
settings.SignedOutRedirectUri = model.SignedOutRedirectUri;
settings.StoreExternalTokens = model.StoreExternalTokens;
settings.Parameters = model.Parameters;
await _clientService.UpdateSettingsAsync(settings);
}
}
public sealed class OpenIdClientSettingsStepModel
{
public string DisplayName { get; set; }
[Url]
public string Authority { get; set; }
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; }
public string Scopes { get; set; }
public string ResponseType { get; set; }
public string ResponseMode { get; set; }
public bool StoreExternalTokens { get; set; }
public ParameterSetting[] Parameters { get; set; }
}