Skip to content

Commit a732e3e

Browse files
committed
Fix auth session not being accepted via cookie anymore
1 parent 5068921 commit a732e3e

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

API/Controller/Account/Logout.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public async Task<IActionResult> Logout(
1616
[FromServices] ApiConfig apiConfig)
1717
{
1818
// Remove session if valid
19-
if (HttpContext.TryGetUserSessionCookie(out var sessionCookie))
19+
if (HttpContext.TryGetUserSession(out var sessionCookie))
2020
{
2121
await sessionService.DeleteSessionById(sessionCookie);
2222
}

Common/Authentication/AuthenticationHandlers/UserSessionAuthentication.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public UserSessionAuthentication(
4747

4848
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
4949
{
50-
if (!Context.TryGetUserSessionCookie(out var sessionKey))
50+
if (!Context.TryGetUserSession(out var sessionKey))
5151
{
5252
return AuthenticateResult.Fail(AuthResultError.CookieMissingOrInvalid.Type!);
5353
}

Common/Constants/AuthConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public static class AuthConstants
44
{
55
public const string UserSessionCookieName = "openShockSession";
6-
public const string SessionHeaderName = "OpenShockSession";
6+
public const string UserSessionHeaderName = "OpenShockSession";
77
public const string ApiTokenHeaderName = "OpenShockToken";
88
public const string HubTokenHeaderName = "DeviceToken";
99
}

Common/Hubs/ShareLinkHub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override async Task OnConnectedAsync()
4545

4646
GenericIni? user = null;
4747

48-
if (httpContext.TryGetUserSessionCookie(out var sessionCookie))
48+
if (httpContext.TryGetUserSession(out var sessionCookie))
4949
{
5050
user = await SessionAuth(sessionCookie);
5151
if (user == null)

Common/Utils/AuthUtils.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@ public static void RemoveSessionKeyCookie(this HttpContext context, string domai
3939
});
4040
}
4141

42-
public static bool TryGetUserSessionCookie(this HttpContext context, [NotNullWhen(true)] out string? sessionCookie)
42+
public static bool TryGetUserSession(this HttpContext context, [NotNullWhen(true)] out string? sessionToken)
4343
{
44-
if (context.Request.Cookies.TryGetValue(AuthConstants.UserSessionCookieName, out sessionCookie) && !string.IsNullOrEmpty(sessionCookie))
44+
if (context.Request.Cookies.TryGetValue(AuthConstants.UserSessionCookieName, out sessionToken) && !string.IsNullOrEmpty(sessionToken))
4545
{
4646
return true;
4747
}
48+
49+
if(context.Request.Headers.TryGetValue(AuthConstants.UserSessionHeaderName, out var headerSessionCookie) && !string.IsNullOrEmpty(headerSessionCookie))
50+
{
51+
sessionToken = headerSessionCookie.ToString();
52+
return true;
53+
}
4854

49-
sessionCookie = null;
55+
sessionToken = null;
5056

5157
return false;
5258
}

Cron/DashboardAdminAuth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public async Task<bool> AuthorizeAsync(DashboardContext context)
1919
var userSessions = redis.RedisCollection<LoginSession>(false);
2020
var db = httpContext.RequestServices.GetRequiredService<OpenShockContext>();
2121

22-
if (httpContext.TryGetUserSessionCookie(out var userSessionCookie))
22+
if (httpContext.TryGetUserSession(out var userSessionCookie))
2323
{
2424
if (await SessionAuthAdmin(userSessionCookie, userSessions, db))
2525
{

0 commit comments

Comments
 (0)