authentication - 为什么我的 ServiceStack AuthProvider 从不调用 Authenticate(),即使 IsAuthorized() 返回 false?

标签 authentication servicestack

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

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

There are generally 2 ways for extending, if you want to provide your own OAuth implementation you would sub class AuthProvider (or implement IAuthProvider) and override the Authenticate() method which holds the entire implementation of your service. The AuthService now has no real implementation of its own, it just checks the Auth Provider .IsAuthorized() method to see if the user is already authenticated, if not it calls the Authenticate() method. [my emphasis]



我现在的整个身份验证提供程序如下所示:
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 方法?上面链接的论坛帖子已有近一年的历史,但我找不到任何表明此行为已被弃用的信息。

最佳答案

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

在你问你的问题前几周,我尝试实现我自己的 AuthProvider并有类似的问题:
How to get ServiceStack authentication to work? (with iPhone clients)
(在问题底部附近,是我的 MyBasicAuthProvider )

到底I found out what I did wrong ,我认为你犯了和我一样的错误:
我需要覆盖 TryAuthenticate而不是 Authenticate .

一旦我改变了它,我的提供者就开始工作了。

关于authentication - 为什么我的 ServiceStack AuthProvider 从不调用 Authenticate(),即使 IsAuthorized() 返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18311483/

相关文章:

java - servlet 身份验证和对凭据的进一步引用

linux - 使用 ssh 启用无密码身份验证

servicestack - 在 ServiceStack 中创建 C# Amazon SQS 客户端

servicestack - 如何在 ServiceStack 中启用 CSRF 保护

servicestack - 使用 IServerEvents.NotifyChannel 丢失事件

java - 策略设计模式

Facebook C# SDK Canvas 授权

authentication - 热门网站如何允许您从 Facebook 等其他网站登录?

c# - 使用ServiceStack上传图片文件

http - 如何为从 ServiceStack 的虚拟文件系统下载的文件添加 header ?