Skip to content

Commit

Permalink
New : JWT Cookie security #106
Browse files Browse the repository at this point in the history
New : When logout remove cookie
  • Loading branch information
shps951023 committed Mar 30, 2024
1 parent 972082b commit 5e2b6cd
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 133 deletions.
2 changes: 2 additions & 0 deletions src/Frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ watch(() => route.name, (newVal) => {
const logout = () => {
localStorage.removeItem('X-MiniAuth-Token')
document.cookie = 'X-MiniAuth-Token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'
window.location.href = '/miniauth/login.html'
}
const loadingFlag = ref(false)
Expand Down
8 changes: 7 additions & 1 deletion src/MiniAuth/MiniAuthMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ public async Task Invoke(HttpContext context)
var roles = user["roles"] as string[];
var newToken = _jwtManager.GetToken(userName, userName, _options.ExpirationMinuteTime, roles);
context.Response.Headers.Add("X-MiniAuth-Token", newToken);
context.Response.Cookies.Append("X-MiniAuth-Token", newToken);
context.Response.Cookies.Append("X-MiniAuth-Token", newToken, new CookieOptions
{
Expires = DateTimeOffset.UtcNow.AddMinutes(_options.ExpirationMinuteTime),
HttpOnly = true,
Secure = true,
SameSite = SameSiteMode.Strict
});

await OkResult(context, $"{{\"X-MiniAuth-Token\":\"{newToken}\"}}").ConfigureAwait(false);
return;
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions src/MiniAuth/wwwroot/assets/EndpointsView-Y1bxbe_m.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.resizable[data-v-5c19e2ea]{height:30px!important;transition:height .3s ease;overflow:hidden}.resizable[data-v-5c19e2ea]:hover{height:130px!important}
6 changes: 0 additions & 6 deletions src/MiniAuth/wwwroot/assets/EndpointsView-hs1TY_ET.js

This file was deleted.

1 change: 1 addition & 0 deletions src/MiniAuth/wwwroot/assets/EndpointsView-pt1zu9Ey.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/MiniAuth/wwwroot/assets/HomeView-GtYJtQ7A.js

This file was deleted.

1 change: 0 additions & 1 deletion src/MiniAuth/wwwroot/assets/ProfileView-2sMRF31L.js

This file was deleted.

1 change: 1 addition & 0 deletions src/MiniAuth/wwwroot/assets/RolesView-K2BI6bQO.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/MiniAuth/wwwroot/assets/RolesView-dPFkXSBA.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
input[type=text][data-v-3699460b],input[type=mail][data-v-3699460b]{widows:100%;border:0;border-bottom:2px solid black;outline:0;background-color:#e2e2e2be}
Loading

0 comments on commit 5e2b6cd

Please sign in to comment.