Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# web Api 2移动认证_C#_Javascript_Jquery_Asp.net_Html - Fatal编程技术网

C# web Api 2移动认证

C# web Api 2移动认证,c#,javascript,jquery,asp.net,html,C#,Javascript,Jquery,Asp.net,Html,我在Web API2中有一个服务器,带有Owin承载身份验证令牌 config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); 如何使用/启用移动本机应用程序使用Web API2服务进行身份验证。要注册用户: Send a POST request to /api/account/register wi

我在Web API2中有一个服务器,带有Owin承载身份验证令牌

config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
如何使用/启用移动本机应用程序使用Web API2服务进行身份验证。

要注册用户:

Send a POST request to /api/account/register with:
header: Content-Type: application/json
body: { 'UserName': 'xxx', 'Password': 'yyy', 'ConfirmPassword': 'yyy' }
现在您有了一个注册用户,您必须“让他们登录”并获得一个令牌,您将在后续的每个请求中使用该令牌来识别发出请求的用户:

Send a POST request to /token with:
header Content-Type: application/x-www-form-urlencoded
body: { grant_type=password&username=Alice&password=password123 }
将返回类似以下内容的JSON:

{
    'access_token':'boQtj0SCGz2GFGz,
    'token_type':'bearer',
    'expires_in':1209599,
    'userName':'xxx',
    '.issued":'Mon, 14 Oct 2013 06:53:32 GMT',
    '.expires":'Mon, 28 Oct 2013 06:53:32 GMT'
}
该访问令牌是您识别发出请求的用户所需的,因此请将其存储在某个位置。当您以用户“xxx”的身份发出另一个请求时,您需要将该令牌作为标头包括在内,如下所示:

Authorization: Bearer boQtj0SCGz2GFGz
请注意,令牌将更长。就这些。每次发出请求时,您只需要将令牌作为头包含在内


但是Jquery没有向服务发送授权请求,状态为Cancelled失败。我不确定您的意思。您能详细说明一下吗?对于登录用户,我如何从本机移动应用程序向Web Api服务器传递凭据?我编辑了我的答案,以便更深入地解释。我还没有做过任何移动开发,所以您需要研究如何使用您开发的任何平台发出http请求并解析返回的json。不过这应该很容易。