Skip to content

Commit ac4e305

Browse files
committed
Fix Tenant Restriction even in normal Requests
1 parent 8b911c2 commit ac4e305

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/CodeBeam.UltimateAuth.Core/MultiTenancy/UAuthTenantContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ private UAuthTenantContext(TenantKey tenant)
2020

2121
public static UAuthTenantContext SingleTenant() => new(TenantKey.Single);
2222
public static UAuthTenantContext System() => new(TenantKey.System);
23+
public static UAuthTenantContext Unresolved() => new(TenantKey.Unresolved);
2324
public static UAuthTenantContext Resolved(TenantKey tenant) => new(tenant);
2425
}

src/CodeBeam.UltimateAuth.Core/Options/UAuthClientProfile.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
public enum UAuthClientProfile
44
{
5-
NotSpecified,
6-
BlazorWasm,
7-
BlazorServer,
8-
Maui,
9-
WebServer,
10-
Api,
11-
UAuthHub = 1000
5+
NotSpecified = 0,
6+
BlazorWasm = 10,
7+
BlazorServer = 20,
8+
Maui = 30,
9+
WebServer = 40,
10+
Api = 50,
11+
UAuthHub = 100
1212
}

src/CodeBeam.UltimateAuth.Server/Middlewares/TenantMiddleware.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,12 @@ public async Task InvokeAsync(HttpContext context, ITenantResolver resolver, IOp
3030

3131
resolution = await resolver.ResolveAsync(context);
3232

33+
// Middleware must allow unresolved tenants for non-auth requests.
34+
// Exception should be handled only in AuthFlowContextFactory, where we can check if the request is for auth endpoints or not.
3335
if (!resolution.IsResolved)
3436
{
35-
//if (opts.RequireTenant)
36-
//{
37-
// context.Response.StatusCode = StatusCodes.Status400BadRequest;
38-
// await context.Response.WriteAsync("Tenant is required.");
39-
// return;
40-
//}
41-
42-
context.Response.StatusCode = StatusCodes.Status400BadRequest;
43-
await context.Response.WriteAsync("Tenant could not be resolved.");
37+
context.Items[UAuthConstants.HttpItems.TenantContextKey] = UAuthTenantContext.Unresolved();
38+
await _next(context);
4439
return;
4540
}
4641

0 commit comments

Comments
 (0)