我想知道是否可以在.NET Core上使用ServiceStack以及中间件。
我的用例是,我想使用ServiceStack实现API,并使用授权策略和OpenID Connect中间件,例如IdentityServer4.AccessTokenValidation。
如果不行,是否有任何替代方法可以设置ServiceStack以与OpenID Connect服务器一起工作?
我想知道是否可以在.NET Core上使用ServiceStack以及中间件。
我的用例是,我想使用ServiceStack实现API,并使用授权策略和OpenID Connect中间件,例如IdentityServer4.AccessTokenValidation。
如果不行,是否有任何替代方法可以设置ServiceStack以与OpenID Connect服务器一起工作?
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class AuthorizeAttribute : RequestFilterAsyncAttribute, IAuthorizeData
{
public AuthorizeAttribute(ApplyTo applyTo)
: base(applyTo)
{
Priority = -100;
}
public AuthorizeAttribute()
: this(ApplyTo.All)
{
}
public string Policy { get; set; }
public string Roles { get; set; }
public string AuthenticationSchemes { get; set; }
public override async Task ExecuteAsync(IRequest req, IResponse res, object requestDto)
{
var policyProvider = req.TryResolve<IAuthorizationPolicyProvider>();
var filter = new AuthorizeFilter(policyProvider, new[] {this});
var webRequest = req.OriginalRequest as HttpRequest;
var actionContext = new ActionContext(webRequest.HttpContext, new RouteData(), new ActionDescriptor());
var context = new AuthorizationFilterContext(actionContext, new List<IFilterMetadata>());
await filter.OnAuthorizationAsync(context);
if (context.Result is ChallengeResult)
{
res.StatusCode = 401;
res.EndRequest();
}
else if (context.Result is ForbidResult)
{
res.StatusCode = 403;
res.EndRequest();
}
}
}
(HttpRequest)req.OriginalRequest
在ServiceStack中访问底层的.NET Core请求。 - mythz