first commit
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Landmark.OLA.Models.OnlineBanking;
|
||||
|
||||
namespace Landmark.OLA.Application.Common.Security
|
||||
{
|
||||
public class CookieService
|
||||
{
|
||||
|
||||
public static void SetAuthenticationCookie(IResponseCookies cookies, string token)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
var expiry = new DateTimeOffset(DateTime.UtcNow.AddMinutes(15));
|
||||
var options = new CookieOptions
|
||||
{
|
||||
SameSite = SameSiteMode.Lax,
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
Expires = expiry,
|
||||
Domain = "landmarkcu.com"
|
||||
};
|
||||
cookies
|
||||
.Append(Constants.TokenPayload, token, options);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetAuthorizationCookie(IResponseCookies cookies, string authorization)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(authorization))
|
||||
{
|
||||
var expiry = new DateTimeOffset(DateTime.UtcNow.AddMinutes(15));
|
||||
var options = new CookieOptions
|
||||
{
|
||||
SameSite = SameSiteMode.Lax,
|
||||
HttpOnly = false,
|
||||
Secure = true,
|
||||
Expires = expiry,
|
||||
Domain = "landmarkcu.com",
|
||||
};
|
||||
cookies
|
||||
.Append(Constants.TokenAuthorization, authorization, options);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExpireCookies(HttpContext context)
|
||||
{
|
||||
var currentCookies = context.Request.Cookies;
|
||||
var expiry = new DateTimeOffset(DateTime.UtcNow.AddDays(-1));
|
||||
var options = new CookieOptions
|
||||
{
|
||||
HttpOnly = false,
|
||||
Secure = true,
|
||||
Expires = expiry,
|
||||
Domain = ".landmarkcu.com"
|
||||
};
|
||||
if (currentCookies[Constants.TokenPayload] != null)
|
||||
{
|
||||
context.Response.Cookies
|
||||
.Delete(Constants.TokenPayload, options);
|
||||
}
|
||||
|
||||
if (currentCookies[Constants.TokenAuthorization] != null)
|
||||
{
|
||||
context.Response.Cookies
|
||||
.Delete(Constants.TokenAuthorization, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user