/// <summary>
/// 验证客户端
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string clientId;
string clientSecret;
context.TryGetFormCredentials(out clientId, out clientSecret);
//context.TryGetBasicCredentials(out clientId, out clientSecret); //Basic认证
//TODO:读库,验证
if (clientId != "malfy" && clientSecret != "111111")
{
context.SetError("invalid_client", "client is not valid");
return;
}
context.OwinContext.Set("as:client_id", clientId);
context.Validated(clientId);
}
如上面的代码,微软提供了context.SetError(),但往往在实际开发中,我们要定义自己的错误信息格式,比如返回统一格式的json。
杨__羊羊