【问题标题】:ServiceStack request fails with error 401, but the Session is authenticatedServiceStack 请求失败并出现错误 401,但 Session 已通过身份验证
【发布时间】:2022-09-27 15:14:35
【问题描述】:

在 GlobalRequestFilters 我有这样的事情:

var session = new AuthUserSession()
{
    AuthProvider = \"credentials\",
    IsAuthenticated = true,
    Id = $\"a unique string\",
    ...
};
req.Items[Keywords.Session] = session;

我有这样的课:

[Authenticate]
[Route($\"/Test\", \"POST\" )]
public class CreateTest : ICreateDb<Test>, IReturn<CreateTestResponse>
{
    public string SomeField { get; set; }
}

还有一项服务:

public class TestService : ServiceStack.Service
{
   public object Post(CreateTest request)
   {
       // prints \"True\" (when we comment [Authenticate] in the DTO)
       Console.Write( Request.GetSession().IsAuthenticated ); 
   }
}

当我在 \"/ui\" 中测试此服务时,我收到错误 401。

如果我从 \"CreateTest\" 中评论 \"[Authenticate]\" 属性,它会按预期工作,并且我可以确认会话存在并且 \"IsAuthenticated\" 为 True。

我的理解是否足以为当前请求“分配”一个会话以验证该请求,但缺少一些东西。

如何解决此 401 错误?

    标签: servicestack


    【解决方案1】:

    您应该调试CredentialsAuthProvider 以找出您的会话无效的原因,例如您可能错过了填充它需要的 EmailUserAuthName 字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 2021-11-23
      • 2022-08-15
      相关资源
      最近更新 更多