我是从他们的文档中读到的,上面写着:
然后您需要注册您的自定义凭据身份验证提供程序:
//Register all Authentication methods you want to enable for this web app.
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[] {
new CustomCredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
}
));
我的问题是: 我把这个放在哪里?此外,评论“用户名/密码凭据的 HTML 表单帖子”是什么意思?
目前,我有一个 ServiceStack 服务,它在调用时返回 JSON。我想在它上面添加一个 Authorize 属性,这样只有授权用户才能访问它。
我按照他们的建议创建了一个类:
public class CustomCredentialsAuthProvider : CredentialsAuthProvider
{
public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
{
//Add here your custom auth logic (database calls etc)
//Return true if credentials are valid, otherwise false
return false;
}
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
//Fill the IAuthSession with data which you want to retrieve in the app eg:
session.FirstName = "some_firstname_from_db";
//...
//Important: You need to save the session!
authService.SaveSession(session, SessionExpiry);
}
}
如何“注册您的自定义凭据身份验证提供程序”?