Skip to content

Commit

Permalink
Merge pull request #814 from ITfoxtec/dev_swagger_base
Browse files Browse the repository at this point in the history
Dev swagger base
  • Loading branch information
Revsgaard authored Jun 4, 2024
2 parents 931183b + 3f989dc commit 6aee537
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 37 deletions.
2 changes: 2 additions & 0 deletions Kubernetes/k8s-foxids-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ spec:
value: "http://+"
- name: "Settings__UseHttp"
value: "true"
- name: "Settings__TrustProxySchemeHeader"
value: "true"
- name: "Settings__FoxIDsEndpoint"
value: "https://id.itfoxtec.com" # change to your domain - https://id.my-domain.com
- name: "Settings__FoxIDsBackendEndpoint"
Expand Down
1 change: 1 addition & 0 deletions azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@
"DOCKER_ENABLE_CI": true,
"ASPNETCORE_URLS": "http://+",
"Settings__UseHttp": true,
"Settings__TrustProxySchemeHeader": true,
"Settings__FoxIDsEndpoint": "[variables('foxidsSiteEndpoint')]",
"Settings__FoxIDsControlEndpoint": "[variables('foxidsControlSiteEndpoint')]",
"Settings__Options__Log": "ApplicationInsights",
Expand Down
2 changes: 1 addition & 1 deletion docs/reverse-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The FoxIDs site support reading the [custom domain](custom-domain.md) (host name

> The host header is only read if access is restricted by the `X-FoxIDs-Secret` HTTP header or the `Settings__TrustProxyHeaders` setting is set to `true`.
The FoxIDs site support to read the HTTP/HTTPS scheme if the `Settings__TrustProxySchemeHeader` setting is set to `true`. In the following HTTP headers in order of priority:
The FoxIDs site and FoxIDs Control site support to read the HTTP/HTTPS scheme if the `Settings__TrustProxySchemeHeader` setting is set to `true`. In the following HTTP headers in order of priority:

1. `X-Forwarded-Scheme`
2. `X-Forwarded-Proto`
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.Control/FoxIDs.Control.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.4.15</Version>
<Version>1.4.16</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static IServiceCollection AddApiSwagger(this IServiceCollection services)
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer",
BearerFormat = "JWT"
BearerFormat = "JWT"
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.ControlClient/FoxIDs.ControlClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.4.15</Version>
<Version>1.4.16</Version>
<RootNamespace>FoxIDs.Client</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.ControlShared/FoxIDs.ControlShared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.4.15</Version>
<Version>1.4.16</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.Shared/FoxIDs.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.4.15</Version>
<Version>1.4.16</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
25 changes: 25 additions & 0 deletions src/FoxIDs.Shared/Infrastructure/Hosting/ProxyHeadersMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public virtual async Task Invoke(HttpContext context)
if (!(IsHealthCheck(context) || IsLoopback(context)))
{
ReadClientIp(context);
ReadSchemeFromHeader(context);
_ = ValidateProxySecret(context);
}

Expand Down Expand Up @@ -85,5 +86,29 @@ protected void ReadClientIp(HttpContext context)
}
}
}

protected void ReadSchemeFromHeader(HttpContext context)
{
var settings = context.RequestServices.GetService<Settings>();
if (settings.TrustProxySchemeHeader)
{
string schemeHeader = context.Request.Headers["X-Forwarded-Scheme"];
if (schemeHeader.IsNullOrWhiteSpace())
{
schemeHeader = context.Request.Headers["X-Forwarded-Proto"];
}
if (!schemeHeader.IsNullOrWhiteSpace())
{
if (schemeHeader.Equals(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase))
{
context.Request.Scheme = Uri.UriSchemeHttp;
}
else if (schemeHeader.Equals(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
{
context.Request.Scheme = Uri.UriSchemeHttps;
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions src/FoxIDs.Shared/Models/Config/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public class Settings : IValidatableObject
/// </summary>
public string ProxySecret { get; set; }

/// <summary>
/// Optional trust proxy scheme header (HTTP/HTTPS). Default false.
/// </summary>
public bool TrustProxySchemeHeader { get; set; }

public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var results = new List<ValidationResult>();
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.SharedBase/FoxIDs.SharedBase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.4.15</Version>
<Version>1.4.16</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs/FoxIDs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.4.15</Version>
<Version>1.4.16</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
24 changes: 0 additions & 24 deletions src/FoxIDs/Infrastructure/Hosting/FoxIDsProxyHeadersMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,5 @@ private string ReadHostFromHeader(HttpContext context)

return string.Empty;
}

private void ReadSchemeFromHeader(HttpContext context)
{
var settings = context.RequestServices.GetService<FoxIDsSettings>();
if (settings.TrustProxySchemeHeader)
{
string schemeHeader = context.Request.Headers["X-Forwarded-Scheme"];
if (schemeHeader.IsNullOrWhiteSpace())
{
schemeHeader = context.Request.Headers["X-Forwarded-Proto"];
}
if (!schemeHeader.IsNullOrWhiteSpace())
{
if (schemeHeader.Equals(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase))
{
context.Request.Scheme = Uri.UriSchemeHttp;
}
else if(schemeHeader.Equals(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
{
context.Request.Scheme = Uri.UriSchemeHttps;
}
}
}
}
}
}
5 changes: 0 additions & 5 deletions src/FoxIDs/Models/Config/FoxIDsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ public class FoxIDsSettings : Settings
/// </summary>
public bool TrustProxyHeaders { get; set; }

/// <summary>
/// Optional trust proxy scheme header (HTTP/HTTPS). Default false.
/// </summary>
public bool TrustProxySchemeHeader { get; set; }

/// <summary>
/// Read the HTTP request domain and use it as custom domain if configured on a tenant.
/// </summary>
Expand Down

0 comments on commit 6aee537

Please sign in to comment.