moved service to separate project (Kontur developer said "WTF WHY ARE U STORING SERVICES IN INFRASTRUCTURE SLAVA D")
This commit is contained in:
parent
147fb683f7
commit
41ff1555f8
11 changed files with 33 additions and 9 deletions
32
SurveyBackend/SurveyBackend.Services/AuthOptions.cs
Normal file
32
SurveyBackend/SurveyBackend.Services/AuthOptions.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System.Text;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace SurveyBackend.Services;
|
||||
|
||||
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