Browse Source

Separate url for authority

pull/95/head
Sebastian Stehle 9 years ago
parent
commit
5786566af4
  1. 15
      src/Squidex.Infrastructure/StringExtensions.cs
  2. 14
      src/Squidex/Config/Identity/IdentityUsage.cs
  3. 2
      src/Squidex/Config/Identity/MyIdentityOptions.cs
  4. 14
      src/Squidex/Config/MyUrlsOptions.cs
  5. 22
      tests/Squidex.Infrastructure.Tests/StringExtensionsTests.cs

15
src/Squidex.Infrastructure/StringExtensions.cs

@ -382,5 +382,20 @@ namespace Squidex.Infrastructure
return result.ToString().Trim(separator);
}
public static string BuildFullUrl(this string baseUrl, string path, bool trailingSlash = false)
{
var url = $"{baseUrl.TrimEnd('/')}/{path.Trim('/')}";
if (trailingSlash &&
url.IndexOf("#", StringComparison.OrdinalIgnoreCase) < 0 &&
url.IndexOf("?", StringComparison.OrdinalIgnoreCase) < 0 &&
url.IndexOf(";", StringComparison.OrdinalIgnoreCase) < 0)
{
url = url + "/";
}
return url;
}
}
}

14
src/Squidex/Config/Identity/IdentityUsage.cs

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Squidex.Domain.Users;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Log;
using Squidex.Shared.Identity;
using Squidex.Shared.Users;
@ -93,10 +94,19 @@ namespace Squidex.Config.Identity
if (!string.IsNullOrWhiteSpace(urlsOptions.BaseUrl))
{
var apiAuthorityUrl = urlsOptions.BuildUrl(Constants.IdentityPrefix);
var identityOptions = app.ApplicationServices.GetService<IOptions<MyIdentityOptions>>().Value;
string apiAuthorityUrl;
if (!string.IsNullOrWhiteSpace(identityOptions.AuthorityUrl))
{
apiAuthorityUrl = identityOptions.AuthorityUrl.BuildFullUrl(Constants.IdentityPrefix);
}
else
{
apiAuthorityUrl = urlsOptions.BuildUrl(Constants.IdentityPrefix);
}
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = apiAuthorityUrl,

2
src/Squidex/Config/Identity/MyIdentityOptions.cs

@ -26,6 +26,8 @@ namespace Squidex.Config.Identity
public string MicrosoftSecret { get; set; }
public string AuthorityUrl { get; set; }
public bool RequiresHttps { get; set; }
public bool AllowPasswordAuth { get; set; }

14
src/Squidex/Config/MyUrlsOptions.cs

@ -6,7 +6,6 @@
// All rights reserved.
// ==========================================================================
using System;
using Squidex.Infrastructure;
namespace Squidex.Config
@ -23,17 +22,8 @@ namespace Squidex.Config
{
throw new ConfigurationException("Configure BaseUrl with 'urls:baseUrl'.");
}
var url = $"{BaseUrl.TrimEnd('/')}/{path.Trim('/')}";
if (trailingSlash &&
url.IndexOf("?", StringComparison.OrdinalIgnoreCase) < 0 &&
url.IndexOf(";", StringComparison.OrdinalIgnoreCase) < 0)
{
url = url + "/";
}
return url;
return BaseUrl.BuildFullUrl(path, trailingSlash);
}
}
}

22
tests/Squidex.Infrastructure.Tests/StringExtensionsTests.cs

@ -103,5 +103,27 @@ namespace Squidex.Infrastructure
Assert.Equal(value, value.WithFallback("fallback"));
}
[Theory]
[InlineData("http://squidex.io/base/", "path/to/res", false, "http://squidex.io/base/path/to/res")]
[InlineData("http://squidex.io/base/", "path/to/res", true, "http://squidex.io/base/path/to/res/")]
[InlineData("http://squidex.io/base/", "/path/to/res", true, "http://squidex.io/base/path/to/res/")]
public void Should_provide_full_url_without_query_or_fragment(string baseUrl, string path, bool trailingSlash, string output)
{
var result = baseUrl.BuildFullUrl(path, trailingSlash);
Assert.Equal(output, result);
}
[Theory]
[InlineData("http://squidex.io/base/", "path/to/res?query=1", false, "http://squidex.io/base/path/to/res?query=1")]
[InlineData("http://squidex.io/base/", "path/to/res#query=1", true, "http://squidex.io/base/path/to/res#query=1")]
[InlineData("http://squidex.io/base/", "path/to/res;query=1", true, "http://squidex.io/base/path/to/res;query=1")]
public void Should_provide_full_url_wit_query_or_fragment(string baseUrl, string path, bool trailingSlash, string output)
{
var result = baseUrl.BuildFullUrl(path, trailingSlash);
Assert.Equal(output, result);
}
}
}

Loading…
Cancel
Save