Owin上下文用户名为空

时间:2019-05-30 13:14:34

标签: c# .net asp.net-web-api owin

我有以下将在我的网络api中调用的方法

 public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)

我需要将角色设置为基于上下文的声明。

但是context.username没有值

我需要知道用户名的设置位置。

请查看完整的上下文

Writing context
ClientId:; UserName:; Password:; Scope:System.String[]; Ticket:; IsValidated:False; HasError:False; Error:; ErrorDescription:; ErrorUri:; OwinContext:Microsoft.Owin.OwinContext; Options:Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerOptions; Request:Microsoft.Owin.OwinRequest; Response:Microsoft.Owin.OwinResponse; 

Writing Request
Environment:Microsoft.Owin.Host.SystemWeb.CallEnvironment.AspNetDictionary; Context:Microsoft.Owin.OwinContext; Method:POST; Scheme:https; IsSecure:True; Host:holmesdev.nam.nsroot.net:4321; PathBase:/hisapi; Path:/token; QueryString:; Query:Microsoft.Owin.ReadableStringCollection; Uri:https://server.nam.nsroot.net:4321/hisapi/token; Protocol:HTTP/1.1; Headers:Microsoft.Owin.HeaderDictionary; Cookies:Microsoft.Owin.RequestCookieCollection; ContentType:application/x-www-form-urlencoded; CacheControl:; MediaType:; Accept:application/json, text/plain, */*; Body:Microsoft.Owin.Host.SystemWeb.CallStreams.InputStream; CallCancelled:System.Threading.CancellationToken; LocalIpAddress:1XX.171.XX.XX5; LocalPort:4321; RemoteIpAddress:10.XX.XX3.XX1; RemotePort:591XX; User:; 

Writing Response
Environment:Microsoft.Owin.Host.SystemWeb.CallEnvironment.AspNetDictionary; Context:Microsoft.Owin.OwinContext; StatusCode:200; ReasonPhrase:OK; Protocol:; Headers:Microsoft.Owin.HeaderDictionary; Cookies:Microsoft.Owin.ResponseCookieCollection; ContentLength:; ContentType:text/html; Expires:; ETag:; Body:Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream; 

如何填充“用户名”?

只有我获得userid的值的地方是在api控制器中。如下所示:

 [Route("api/User/UpdateUserDetail")]
  [HttpPost]
  public HttpResponseMessage UpdateUserDetail(User userData)

SimpleAuthorizationServerProvider.cs中没有可用的用户名,我该如何将用户ID从控制器带到SimpleAuthorizationServerProvider。

0 个答案:

没有答案