我正在为ServiceStack编写一个AuthProvider来对我们自己的OAuth2服务器进行身份验证,并且遇到ServiceStack与我的提供商交互方式的问题。
根据https://groups.google.com/d/msg/servicestack/e3kkh-qRDYs/DF9Y05ibl-MJ
通常有两种扩展方式,如果要提供自己的OAuth实现,则可以使用子类AuthProvider(或实现IAuthProvider)并覆盖包含服务整个实现的Authenticate()方法。 AuthService现在没有自己的实际实现,它只检查Auth Provider .IsAuthorized()方法以查看用户是否已经过身份验证,如果不是,则调用Authenticate()方法。 [my强调]
我的整个身份验证提供程序现在看起来像这样:
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();
}
}
}
为什么永远不会调用Authenticate方法?上面链接的论坛帖子已有近一年的历史,但我找不到任何暗示此行为已被弃用的内容。
答案 0 :(得分:1)
这个答案可能有点迟了,但我现在偶然发现了你的问题。
在您提出问题前几周,我尝试实施自己的AuthProvider
并遇到类似问题:
How to get ServiceStack authentication to work? (with iPhone clients)
(靠近问题的底部,有我的MyBasicAuthProvider
)
最后I found out what I did wrong,我认为你犯了同样的错误:
我需要覆盖TryAuthenticate
而不是Authenticate
。
一旦我改变了,我的提供者就会工作。