massive work on user auth
This commit is contained in:
parent
35331a87f1
commit
c2bcaf0832
17 changed files with 186 additions and 19 deletions
32
SurveyBackend/SurveyBackend.Infrastructure/AuthOptions.cs
Normal file
32
SurveyBackend/SurveyBackend.Infrastructure/AuthOptions.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System.Text;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace SurveyBackend.Infrastructure;
|
||||
|
||||
public static class AuthOptions
|
||||
{
|
||||
public static string Issuer;
|
||||
public static string Audience;
|
||||
public static TimeSpan TokenLifetime;
|
||||
private static string? SecurityKey { get; set; }
|
||||
|
||||
public static SymmetricSecurityKey SymmetricSecurityKey
|
||||
{
|
||||
get
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(SecurityKey);
|
||||
|
||||
return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SecurityKey));
|
||||
}
|
||||
}
|
||||
|
||||
public static void MakeOptions(IConfigurationManager configurationManager, string? securityKey = null)
|
||||
{
|
||||
var jwtSettings = configurationManager.GetSection("JwtSettings");
|
||||
Issuer = jwtSettings["Issuer"] ?? "DefaultIssuer";
|
||||
Audience = jwtSettings["Audience"] ?? "DefaultAudience";
|
||||
TokenLifetime = TimeSpan.FromMinutes(int.Parse(jwtSettings["TokenLifetime"] ?? "60"));
|
||||
SecurityKey = securityKey ?? jwtSettings["SecretKey"];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue