【发布时间】:2017-11-01 04:58:50
【问题描述】:
我正在覆盖 OAuthAuthorizationServerProvider 的两种方法,但我正在对数据进行硬编码,如下所示。我如何使用等待?我可以在哪里申请,以便编译可以构建它
public class MyAutorization : OAuthAuthorizationServerProvider
{
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.Validated();
}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
if (context.UserName == "admin" && context.Password == "admin")
{
identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));
identity.AddClaim(new Claim("username", "admin"));
identity.AddClaim(new Claim(ClaimTypes.Name, "Mulla"));
context.Validated(identity);
}
else if (context.UserName == "user" && context.Password == "user")
{
identity.AddClaim(new Claim(ClaimTypes.Role, "user"));
identity.AddClaim(new Claim("username", "user"));
identity.AddClaim(new Claim(ClaimTypes.Name, "Boland"));
context.Validated(identity);
}
else
{
context.SetError("Access Denied", "Invalid User Name And Password");
return;
}
}
}
【问题讨论】:
-
您可以删除
async关键字并为旧框架版本添加return Task.CompletedTask或Task.FromResult(0) -
@JSteward 可以在旧版本中编辑以上代码
-
我不明白你的意思?
-
@JSteward 它对我有用,谢谢你的帮助
-
Task.FromResult(0) 完成了我的工作
标签: asp.net asynchronous oauth-2.0 async-await owin