582cc54189
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>
30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
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('/');
|
|
}
|
|
}
|