【发布时间】:2013-02-13 00:33:35
【问题描述】:
我正在尝试使用 ServiceStack 创建一个简单的 Web 服务。在服务器(服务)端,我首先创建了一个用户“管理员”并为其分配了“管理员”角色。我正在使用 ServiceStack 内置的凭据身份验证,并且它很好地进行了身份验证。但是,对任何使用 [Authenticate] 属性修饰的 Web 服务的任何后续调用都会返回以下错误:
没有为 OAuth 提供者“基本”添加配置
仅供参考:数据库是 RavenDb - 使用 ServiceStack.Authentication.RavenDb。我还在 App_Start.AppHost.Configure() 中注册了一个 MemoryCacheClient。如果您需要查看 App_Start.AppHost 类中的所有代码,请告诉我。
服务器代码(摘录):
namespace MyTest
{
[Route("/hello")]
[Route("/hello/{Name}")]
[Authenticate]
public class Hello
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
public class HelloService : Service
{
public IUserAuthRepository UserAuthRepo { get; set; }
public object Any(Hello request)
{
return new HelloResponse { Result = "Hello, " + request.Name };
}
}
}
客户端:
var client = new JsonServiceClient("http://127.0.0.1:65385/auth/credentials?format=json");
var auth = new Auth { UserName = "administrator", Password = "12345" };
var authResponse = client.Post(auth);
if (authResponse.ResponseStatus.ErrorCode == null)
{
client = new JsonServiceClient("http://127.0.0.1:65385/hello");
client.UserName = "administrator";
client.Password = "12345";
// When sending the request - it returns "Not Found"
var helloResponse = client.Send(new Hello { Name = "John" });
}
编辑:
我的服务的 web.config 看起来与the Hello World tutorial 的第 2a 部分中所写的完全一样
这是我的 AppHost 的配置:
public override void Configure(Funq.Container container)
{
container.Register(new MemoryCacheClient { FlushOnDispose = false });
container.Register(new EmbeddableDocumentStore { DataDirectory = "Data" }.Initialize());
ConfigureAuth(container);
}
private void ConfigureAuth(Funq.Container container)
{
var appSettings = new AppSettings();
Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(appSettings)}));
Plugins.Add(new RegistrationFeature());
container.Register(
new RavenUserAuthRepository(c.Resolve()));
}
【问题讨论】:
标签: c# c#-4.0 asp.net-mvc-4 servicestack