为什么我的ServiceStack AuthProvider永远不会调用Authenticate(),即使IsAuthorized()返回false?

Dyl*_*tie 6 authentication servicestack

我正在为ServiceStack编写一个AuthProvider来对我们自己的OAuth2服务器进行身份验证,并且遇到ServiceStack与我的提供者交互方式的问题.

根据https://groups.google.com/d/msg/servicestack/e3kkh-qRDYs/DF9Y05ibl-MJ

通常有两种扩展方式,如果要提供自己的OAuth实现,则可以使用子类AuthProvider(或实现IAuthProvider)并覆盖包含服务的整个实现的Authenticate()方法.AuthService现在没有自己的实际实现,只是检查Auth Provider .IsAuthorized()方法以查看用户是否已经过身份验证,如果没有,则调用Authenticate()方法.[我的重点]

我现在的整个身份验证提供程序如下所示:

using System;
using ServiceStack.ServiceInterface;
using ServiceStack.ServiceInterface.Auth;

namespace SpotAuth.ResourceServer.Services {
    public class SpotlightOAUthProvider : AuthProvider {
        public override bool IsAuthorized(IAuthSession session, IOAuthTokens tokens, Auth request = null) {
            return (false);
        }

        public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request) {
            // A breakpoint on this line is never reached; the service just returns Unauthorized.
            throw new NotImplementedException();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么永远不会调用Authenticate方法?上面链接的论坛帖子已有近一年的历史,但我找不到任何暗示此行为已被弃用的内容.

Chr*_*cht 1

这个答案可能有点晚了,但我现在才偶然发现你的问题。

在您提出问题之前几周,我尝试实现自己的AuthProvider并遇到了类似的问题:
如何让 ServiceStack 身份验证发挥作用?(使用 iPhone 客户端)
(在问题底部附近,有我的MyBasicAuthProvider

最后我发现我做错了什么,我认为你犯了和我一样的错误:
我需要覆盖TryAuthenticate而不是Authenticate

一旦我改变了这一点,我的提供商就开始工作了。