禁用Servicestack登录中的获取关键字

时间:2019-03-04 08:32:56

标签: servicestack

当前在auth / login中,您可以使用任何Get。如何限制某些内置服务的GET关键字。我们有一个最透彻的发现,指出不应通过Get关键字允许auth / login,而只能通过put或post。

1 个答案:

答案 0 :(得分:1)

如果您引用的是HTTP GET请求,则可以使用以下命令注册Global Request Filter来短路Authenticate HTTP GET请求:

GlobalRequestFilters.Add((req, res, requestDto) => {
    if (requestDto is Authenticate auth && req.Verb == HttpMethods.Get)
    {
        res.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
        res.EndRequest();
    }
});

默认情况下,我还在this commitavailable on MyGetenter image description here中禁用了{{3}}中的GET Authenticate请求(对于非OAuth提供商),可以通过以下方式重新启用它:

Plugins.Add(new AuthFeature(...) {
    AllowGetAuthenticateRequests = req => true
});