mirror of https://github.com/abpframework/eventhub
24 changed files with 211 additions and 24 deletions
@ -0,0 +1,6 @@ |
|||
apiVersion: v2 |
|||
name: api |
|||
appVersion: "1.0" |
|||
description: EventHub API Application |
|||
version: 1.0.0 |
|||
type: application |
|||
@ -0,0 +1,18 @@ |
|||
apiVersion: networking.k8s.io/v1 |
|||
kind: Ingress |
|||
metadata: |
|||
name: api-ingress |
|||
annotations: |
|||
nginx.ingress.kubernetes.io/rewrite-target: / |
|||
spec: |
|||
rules: |
|||
- host: "api.openeventhub.com" |
|||
http: |
|||
paths: |
|||
- path: / |
|||
pathType: Prefix |
|||
backend: |
|||
service: |
|||
name: api |
|||
port: |
|||
number: 80 |
|||
@ -0,0 +1,14 @@ |
|||
apiVersion: v1 |
|||
kind: Service |
|||
metadata: |
|||
labels: |
|||
name: api |
|||
name: api |
|||
spec: |
|||
ports: |
|||
- name: "80" |
|||
port: 80 |
|||
- name: "443" |
|||
port: 443 |
|||
selector: |
|||
app: api |
|||
@ -0,0 +1,22 @@ |
|||
apiVersion: apps/v1 |
|||
kind: Deployment |
|||
metadata: |
|||
name: api |
|||
spec: |
|||
selector: |
|||
matchLabels: |
|||
app: api |
|||
template: |
|||
metadata: |
|||
labels: |
|||
app: api |
|||
spec: |
|||
containers: |
|||
- image: eventhub.api |
|||
imagePullPolicy: Never |
|||
name: api |
|||
ports: |
|||
- name: apihttp |
|||
containerPort: 80 |
|||
- name: apihttps |
|||
containerPort: 443 |
|||
@ -0,0 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
FROM mcr.microsoft.com/dotnet/aspnet:5.0 |
|||
COPY bin/Release/net5.0/publish/ app/ |
|||
WORKDIR /app |
|||
ENTRYPOINT ["dotnet", "EventHub.HttpApi.Host.dll"] |
|||
@ -0,0 +1,70 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Http; |
|||
|
|||
namespace Microsoft.Extensions.DependencyInjection |
|||
{ |
|||
public static class SameSiteCookiesServiceCollectionExtensions |
|||
{ |
|||
public static IServiceCollection AddSameSiteCookiePolicy(this IServiceCollection services) |
|||
{ |
|||
services.Configure<CookiePolicyOptions>(options => |
|||
{ |
|||
options.MinimumSameSitePolicy = SameSiteMode.Unspecified; |
|||
options.OnAppendCookie = cookieContext => |
|||
CheckSameSite(cookieContext.Context, cookieContext.CookieOptions); |
|||
options.OnDeleteCookie = cookieContext => |
|||
CheckSameSite(cookieContext.Context, cookieContext.CookieOptions); |
|||
}); |
|||
|
|||
return services; |
|||
} |
|||
|
|||
private static void CheckSameSite(HttpContext httpContext, CookieOptions options) |
|||
{ |
|||
if (options.SameSite == SameSiteMode.None) |
|||
{ |
|||
var userAgent = httpContext.Request.Headers["User-Agent"].ToString(); |
|||
if (!httpContext.Request.IsHttps || DisallowsSameSiteNone(userAgent)) |
|||
{ |
|||
// For .NET Core < 3.1 set SameSite = (SameSiteMode)(-1)
|
|||
options.SameSite = SameSiteMode.Unspecified; |
|||
} |
|||
} |
|||
} |
|||
|
|||
private static bool DisallowsSameSiteNone(string userAgent) |
|||
{ |
|||
// Cover all iOS based browsers here. This includes:
|
|||
// - Safari on iOS 12 for iPhone, iPod Touch, iPad
|
|||
// - WkWebview on iOS 12 for iPhone, iPod Touch, iPad
|
|||
// - Chrome on iOS 12 for iPhone, iPod Touch, iPad
|
|||
// All of which are broken by SameSite=None, because they use the iOS networking stack
|
|||
if (userAgent.Contains("CPU iPhone OS 12") || userAgent.Contains("iPad; CPU OS 12")) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
// Cover Mac OS X based browsers that use the Mac OS networking stack. This includes:
|
|||
// - Safari on Mac OS X.
|
|||
// This does not include:
|
|||
// - Chrome on Mac OS X
|
|||
// Because they do not use the Mac OS networking stack.
|
|||
if (userAgent.Contains("Macintosh; Intel Mac OS X 10_14") && |
|||
userAgent.Contains("Version/") && userAgent.Contains("Safari")) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
// Cover Chrome 50-69, because some versions are broken by SameSite=None,
|
|||
// and none in this range require it.
|
|||
// Note: this covers some pre-Chromium Edge versions,
|
|||
// but pre-Chromium Edge does not require SameSite=None.
|
|||
if (userAgent.Contains("Chrome/5") || userAgent.Contains("Chrome/6")) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -1,2 +1,14 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" |
|||
}, |
|||
"Redis": { |
|||
"Configuration": "127.0.0.1" |
|||
}, |
|||
"AuthServer": { |
|||
"Authority": "https://localhost:44313", |
|||
"RequireHttpsMetadata": "true", |
|||
"SwaggerClientId": "EventHub_Swagger", |
|||
"SwaggerClientSecret": "1q2w3e*" |
|||
} |
|||
} |
|||
|
|||
@ -1,2 +1,8 @@ |
|||
{ |
|||
} |
|||
"ConnectionStrings": { |
|||
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" |
|||
}, |
|||
"Redis": { |
|||
"Configuration": "localhost" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue