protected virtual Task <bool> IsRedirectUriValidWithDomainFormatsAsync(IEnumerable <string> uris, string requestedUri) { if (uris == null) { return(Task.FromResult(false)); } foreach (var url in uris) { var extractResult = FormattedStringValueExtracter.Extract(requestedUri, url, ignoreCase: true); if (extractResult.IsMatch) { return(Task.FromResult(extractResult.Matches .Aggregate(url, (current, nameValue) => current.Replace($"{{{nameValue.Name}}}", nameValue.Value)) .Contains(requestedUri, StringComparison.OrdinalIgnoreCase))); } if (url.Replace("{0}.", "").Contains(requestedUri, StringComparison.OrdinalIgnoreCase)) { return(Task.FromResult(true)); } } return(Task.FromResult(false)); }
protected override async Task <bool> IsOriginAllowedAsync(string[] allowedOrigins, string origin) { var isAllowed = await base.IsOriginAllowedAsync(allowedOrigins, origin); if (isAllowed) { return(true); } foreach (var url in allowedOrigins) { var extractResult = FormattedStringValueExtracter.Extract(origin, url, ignoreCase: true); if (extractResult.IsMatch) { return(extractResult.Matches.Aggregate(url, (current, nameValue) => current.Replace($"{{{nameValue.Name}}}", nameValue.Value)) .Contains(origin, StringComparison.OrdinalIgnoreCase)); } if (url.Replace("{0}.", "").Contains(origin, StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
protected override Task <string> GetTenantIdOrNameFromHttpContextOrNullAsync(ITenantResolveContext context, HttpContext httpContext) { var hostName = httpContext.Request.Host.Host.RemovePreFix(ProtocolPrefixes); var extractResult = FormattedStringValueExtracter.Extract(hostName, _domainFormat, ignoreCase: true); context.Handled = true; return(Task.FromResult(extractResult.IsMatch ? extractResult.Matches[0].Value : null)); }
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) { if (httpContext.Request?.Host == null) { return(null); } var hostName = httpContext.Request.Host.Host.RemovePreFix("http://", "https://"); var extractResult = FormattedStringValueExtracter.Extract(hostName, _domainFormat, ignoreCase: true); if (!extractResult.IsMatch) { return(null); } return(extractResult.Matches[0].Value); }
protected virtual Task <bool> IsRedirectUriValidWithDomainFormatsAsync(IEnumerable <string> uris, string requestedUri) { if (uris == null) { return(Task.FromResult(false)); } foreach (var url in uris) { var extractResult = FormattedStringValueExtracter.Extract(requestedUri, url, ignoreCase: true); if (extractResult.IsMatch) { return(Task.FromResult(true)); } } return(Task.FromResult(false)); }
protected virtual Task <bool> CheckWildcardDomainAsync(string url) { foreach (var domainFormat in WildcardDomainOptions.WildcardDomainsFormat) { var extractResult = FormattedStringValueExtracter.Extract(url, domainFormat, ignoreCase: true); if (extractResult.IsMatch) { return(Task.FromResult(true)); } } foreach (var domainFormat in WildcardDomainOptions.WildcardDomainsFormat) { if (domainFormat.Replace("{0}.", "").Equals(url, StringComparison.OrdinalIgnoreCase)) { return(Task.FromResult(true)); } } return(Task.FromResult(false)); }
private static void Test_Matched_Internal(string str, string format, params NameValue[] expectedPairs) { var result = FormattedStringValueExtracter.Extract(str, format); result.IsMatch.ShouldBe(true); if (expectedPairs == null) { result.Matches.Count.ShouldBe(0); return; } result.Matches.Count.ShouldBe(expectedPairs.Length); for (int i = 0; i < expectedPairs.Length; i++) { var actualMatch = result.Matches[i]; var expectedPair = expectedPairs[i]; actualMatch.Name.ShouldBe(expectedPair.Name); actualMatch.Value.ShouldBe(expectedPair.Value); } }
public static string GetSettingNameFormCacheKeyOrNull(string cacheKey) { var result = FormattedStringValueExtracter.Extract(cacheKey, CacheKeyFormat, true); return(result.IsMatch ? result.Matches.Last().Value : null); }
private void Test_Not_Matched_Internal(string str, string format) { var result = FormattedStringValueExtracter.Extract(str, format); result.IsMatch.ShouldBe(false); }