我花了几天时间试图掌握 ServiceStack,它看起来很棒。唯一的问题是身份验证,这似乎是很多摩擦、辛勤工作和眼泪。
我希望 MonoTouch 注册用户,针对 ServiceStack 进行身份验证/针对 OAuth 进行身份验证,并且通常在进行身份验证时尽量减少对数据库的调用。
到目前为止,我得到了这个:
var client = new JsonServiceClient(newbaseUri);
// register a new user:
var registration = new Registration {
FirstName = "john"
UserName = "user" ,
Password = "pass",
Email = "john@john.com",
};
var registerResponse = client.Send<RegistrationResponse>(registration);
--------------------------------
// user registered...later on I authenticate:
var authResponse = client.Send<AuthResponse>(new Auth {
UserName = "user",
Password = "pass",
RememberMe = true
});
var authResponse = clientlogin.Send<AuthResponse>(auth);
--------------------------------
// somehow I need to store 'authresponse' for later calls, not sure how without a browser
// tried manually setting the cookies and credentials parameters later but no joy
// but now I need to call a secured ([Authenticate] decorated) service method:
var client = new JsonServiceClient(newbaseUri);
var response = client.Send<HelloResponse>(new Hello { Name = "World!" });
return response.Result;
-----------------------------------------
// heres the configuration
var appSettings = new AppSettings();
//Default route: /auth/{provider}
Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(appSettings), // never seems to get called
//new FacebookAuthProvider(appSettings), // not sure how to get this to work on monotouch
//new TwitterAuthProvider(appSettings), // same issue as facebook
new BasicAuthProvider(appSettings) // works but what about caching/tokens/cookies?
}));
//Default route: /register
Plugins.Add(new RegistrationFeature()); // how do i send extra params to this as created in mongodb collection
var mongoClient = new MongoClient("mongodb://localhost");
var server = mongoClient.GetServer();
var db = server.GetDatabase("users");
container.Register<ICacheClient>(new MemoryCacheClient());
container.Register<IUserAuthRepository>(new MongoDBAuthRepository(db, true));
我的问题是:
1)我如何启用额外的字段与注册一起传递(因为 mongodb [Servicestack.Authentication.Mongodb] 有很多空字段,即出生日期、第一行、城市、时区等)在 ServiceStack.Common 中不存在.ServiceClient.Web.Registration 对象?
2)如何将“authresponse”中发送的cookie(甚至可能是令牌系统)传输到后续调用,以允许ServiceStack与会话匹配以进行持续身份验证,而不是更多正在进行的数据库调用,这似乎是问题使用“基本身份验证”方法(即不会在服务器端调用 CredentialsAuthProvider)?
请帮助...我已经阅读了文档,运行测试,检查了社交引导程序,现在我为此严重浪费了几天时间,并考虑将 SS 与 simplemembership 集成,甚至完全抛弃 ServiceStack 以获得旧的 skool soap/wcf,这要容易得多通过它的外观来实现:(