/// <summary> /// 驗(yàn)證客戶端 /// </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認(rèn)證 //TODO:讀庫(kù),驗(yàn)證 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(),但往往在實(shí)際開(kāi)發(fā)中,我們要定義自己的錯(cuò)誤信息格式,比如返回統(tǒng)一格式的json。
- 1 回答
- 0 關(guān)注
- 1619 瀏覽
添加回答
舉報(bào)
0/150
提交
取消