添加OAuth2认证相关配置文件和服务实现,包括环境变量配置、PKCE流程支持、token管理等功能。主要变更: - 新增OAuth2配置文件 - 实现OAuth2服务层 - 更新请求拦截器支持token自动刷新 - 修改认证API和store以支持OAuth2流程
31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Mvc.Abstractions;
|
|
using Microsoft.AspNetCore.Mvc.ActionConstraints;
|
|
|
|
namespace Fengling.AuthService.Configuration;
|
|
|
|
public sealed class FormValueRequiredAttribute(string name) : ActionMethodSelectorAttribute
|
|
{
|
|
public override bool IsValidForRequest(RouteContext context, ActionDescriptor action)
|
|
{
|
|
if (string.Equals(context.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase) ||
|
|
string.Equals(context.HttpContext.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) ||
|
|
string.Equals(context.HttpContext.Request.Method, "DELETE", StringComparison.OrdinalIgnoreCase) ||
|
|
string.Equals(context.HttpContext.Request.Method, "TRACE", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(context.HttpContext.Request.ContentType))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!context.HttpContext.Request.ContentType.StartsWith("application/x-www-form-urlencoded",
|
|
StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return !string.IsNullOrEmpty(context.HttpContext.Request.Form[name]);
|
|
}
|
|
} |