我尝试使用南希无状态身份验证示例,但我收到了IUserIdentity
错误,我不明白。以下是Nancy的样本代码
using Nancy;
using Nancy.Security;
using Models;
public class SecureModule : NancyModule
{
//by this time, the api key should have already been pulled out of our querystring
//and, using the api key, an identity assigned to our NancyContext
public SecureModule()
{
this.RequiresAuthentication();
Get["secure"] = x =>
{
//Context.CurrentUser was set by StatelessAuthentication earlier in the pipeline
var identity = this.Context.CurrentUser;
//return the secure information in a json response
var userModel = new UserModel(identity.Identity.Name);
return this.Response.AsJson(new
{
SecureContent = "here's some secure content that you can only see if you provide a correct apiKey",
User = userModel
});
};
}
}
这是我看到的错误。
错误CS1061
IUserIdentity
不包含Identity
的定义,也无法找到接受类型为Identity
的第一个参数的扩展方法IUserIdentity
。
当我从Nancy的示例项目中检查this.Context.CurrentUser
时,它说currentuser
来自ClaimsPrincipal
,但当我将示例代码放入我的项目时,它会说currentuser
来自IUserIdentity
。
任何帮助将/将不胜感激。感谢。
答案 0 :(得分:0)
在将Context
CurrentUser
设置为IPrinciple
的{{3}}中。你有一个可以调整CurrentUser
属性的引导程序吗?
以下是他们在演示引导程序中使用的代码(上面链接):
ctx.CurrentUser = new ClaimsPrincipal(new ClaimsIdentity(BuildClaims(username), "querystring"));