Add App__Domain config to derive connect redirect URI
Let deployments set a single App__Domain (e.g. sptb.example.com) instead of spelling out the full ClientConnect__RedirectUri. The SharePoint-connect callback is derived as <domain>/connect/callback; an explicit RedirectUri still wins for back-compat. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
namespace SharepointToolbox.Web.Core.Config;
|
||||
|
||||
/// <summary>
|
||||
/// The app's public domain (e.g. <c>sptb.example.com</c> or <c>https://sptb.example.com</c>),
|
||||
/// configured via <c>App__Domain</c>. Used to derive the SharePoint-connect redirect URI when
|
||||
/// <see cref="ClientConnectOptions.RedirectUri"/> isn't set explicitly.
|
||||
/// </summary>
|
||||
public class AppDomainOptions
|
||||
{
|
||||
public string Domain { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Builds an absolute URL for <paramref name="path"/> rooted at the configured domain, or
|
||||
/// <c>null</c> when no domain is set. Defaults to <c>https</c> when the domain has no scheme,
|
||||
/// and tolerates accidental surrounding quotes / trailing slashes (docker-compose's list-form
|
||||
/// env values can embed literal quotes).
|
||||
/// </summary>
|
||||
public string? BuildUrl(string path)
|
||||
{
|
||||
var domain = Domain?.Trim().Trim('"', '\'').TrimEnd('/');
|
||||
if (string.IsNullOrEmpty(domain))
|
||||
return null;
|
||||
|
||||
if (!domain.Contains("://", StringComparison.Ordinal))
|
||||
domain = "https://" + domain;
|
||||
|
||||
return domain + "/" + path.TrimStart('/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user