Auth optimization

This commit is contained in:
Andre Beging
2022-04-04 15:19:58 +02:00
parent 83fb4a3c5e
commit 1513ed9169
8 changed files with 100 additions and 44 deletions

View File

@@ -5,6 +5,7 @@ using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Server.Data;
using FoodsharingSiegen.Server.Data.Service;
using FoodsharingSiegen.Server.Service;
using FoodsharingSiegen.Shared.Helper;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
@@ -92,25 +93,7 @@ namespace FoodsharingSiegen.Server.Auth
if (User != null)
{
// Daten korrekt
var tokenHandler = new JwtSecurityTokenHandler();
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.NameIdentifier, User.Id.ToString()),
}),
Expires = DateTime.UtcNow.AddDays(30),
Issuer = "FS-Siegen",
Audience = "FS-Siegen",
SigningCredentials = new SigningCredentials(AuthHelper.GetSigningKey(), SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var serializedToken = tokenHandler.WriteToken(token);
var serializedToken = AuthHelper.CreateToken(User.Id);
await _localStorageService.SetItem(StorageKeys.TokenKey, serializedToken);
return new OperationResult();