mirror of https://github.com/abpframework/abp.git
committed by
GitHub
7 changed files with 155 additions and 6 deletions
@ -0,0 +1,28 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.AntiForgery; |
|||
using Volo.Abp.Auditing; |
|||
|
|||
namespace Volo.Abp.Swashbuckle |
|||
{ |
|||
[Area("Abp")] |
|||
[Route("Abp/Swashbuckle/[action]")]
|
|||
[DisableAuditing] |
|||
[RemoteService(false)] |
|||
[ApiExplorerSettings(IgnoreApi = true)] |
|||
public class AbpSwashbuckleController : AbpController |
|||
{ |
|||
private readonly IAbpAntiForgeryManager _antiForgeryManager; |
|||
|
|||
public AbpSwashbuckleController(IAbpAntiForgeryManager antiForgeryManager) |
|||
{ |
|||
_antiForgeryManager = antiForgeryManager; |
|||
} |
|||
|
|||
[HttpGet] |
|||
public void SetCsrfCookie() |
|||
{ |
|||
_antiForgeryManager.SetCookie(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
var abp = abp || {}; |
|||
(function () { |
|||
|
|||
/* Application paths *****************************************/ |
|||
|
|||
//Current application root path (including virtual directory if exists).
|
|||
abp.appPath = abp.appPath || '/'; |
|||
|
|||
/* UTILS ***************************************************/ |
|||
|
|||
abp.utils = abp.utils || {}; |
|||
|
|||
/** |
|||
* Sets a cookie value for given key. |
|||
* This is a simple implementation created to be used by ABP. |
|||
* Please use a complete cookie library if you need. |
|||
* @param {string} key |
|||
* @param {string} value |
|||
* @param {Date} expireDate (optional). If not specified the cookie will expire at the end of session. |
|||
* @param {string} path (optional) |
|||
*/ |
|||
abp.utils.setCookieValue = function (key, value, expireDate, path) { |
|||
var cookieValue = encodeURIComponent(key) + '='; |
|||
|
|||
if (value) { |
|||
cookieValue = cookieValue + encodeURIComponent(value); |
|||
} |
|||
|
|||
if (expireDate) { |
|||
cookieValue = cookieValue + "; expires=" + expireDate.toUTCString(); |
|||
} |
|||
|
|||
if (path) { |
|||
cookieValue = cookieValue + "; path=" + path; |
|||
} |
|||
|
|||
document.cookie = cookieValue; |
|||
}; |
|||
|
|||
/** |
|||
* Gets a cookie with given key. |
|||
* This is a simple implementation created to be used by ABP. |
|||
* Please use a complete cookie library if you need. |
|||
* @param {string} key |
|||
* @returns {string} Cookie value or null |
|||
*/ |
|||
abp.utils.getCookieValue = function (key) { |
|||
var equalities = document.cookie.split('; '); |
|||
for (var i = 0; i < equalities.length; i++) { |
|||
if (!equalities[i]) { |
|||
continue; |
|||
} |
|||
|
|||
var splitted = equalities[i].split('='); |
|||
if (splitted.length != 2) { |
|||
continue; |
|||
} |
|||
|
|||
if (decodeURIComponent(splitted[0]) === key) { |
|||
return decodeURIComponent(splitted[1] || ''); |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
}; |
|||
|
|||
/** |
|||
* Deletes cookie for given key. |
|||
* This is a simple implementation created to be used by ABP. |
|||
* Please use a complete cookie library if you need. |
|||
* @param {string} key |
|||
* @param {string} path (optional) |
|||
*/ |
|||
abp.utils.deleteCookie = function (key, path) { |
|||
var cookieValue = encodeURIComponent(key) + '='; |
|||
|
|||
cookieValue = cookieValue + "; expires=" + (new Date(new Date().getTime() - 86400000)).toUTCString(); |
|||
|
|||
if (path) { |
|||
cookieValue = cookieValue + "; path=" + path; |
|||
} |
|||
|
|||
document.cookie = cookieValue; |
|||
} |
|||
|
|||
/* SECURITY ***************************************/ |
|||
abp.security = abp.security || {}; |
|||
abp.security.antiForgery = abp.security.antiForgery || {}; |
|||
|
|||
abp.security.antiForgery.tokenCookieName = 'XSRF-TOKEN'; |
|||
abp.security.antiForgery.tokenHeaderName = 'RequestVerificationToken'; |
|||
|
|||
abp.security.antiForgery.getToken = function () { |
|||
return abp.utils.getCookieValue(abp.security.antiForgery.tokenCookieName); |
|||
}; |
|||
|
|||
})(); |
|||
Loading…
Reference in new issue