简体   繁体   English

适用于IOS的Web Api Rest服务Aunthentation

[英]Web Api Rest service Aunthentation for IOS


I have implemented basic aunthentation from url http://www.asp.net/web-api/overview/security/basic-authentication . 我已经从url http://www.asp.net/web-api/overview/security/basic-authentication实现了基本认证。 Now I have a question that how i send the basic aunthentation to user on login or on register action that is inside controller. 现在,我有一个问题,我如何在登录或控制器内部的注册操作中向用户发送基本的确认信息。

in short how i create a token and integrated in responsed header. 简而言之,我如何创建令牌并将其集成到响应的标头中。 Kindly help me i have spent more then 4 hours on it. 请帮助我,我已经花了超过4个小时。 Thanks 谢谢

The token is created manually from the credentials users provide. 令牌是根据用户提供的凭据手动创建的。

This means that you have to show a login form in your ios application, gather the username and password and then append the authentication header to each request. 这意味着您必须在ios应用程序中显示登录表单,收集用户名和密码,然后将身份验证标头附加到每个请求。

The name of the header is Authorization . 标头的名称为Authorization

The value is computed as follows. 该值的计算如下。 You take the username + ':' + password and encode such string to a byte array. 您使用用户名+':'+密码,并将此字符串编码为字节数组。 Then you get base64 out of the array. 然后,将base64从数组中取出。

The value of the header is basic [base64ofusernamepassword] where the [base64ofusernameandpassword] is replaced by the base64 of the username and password you just computed previously. 标头的值是basic [base64ofusernamepassword] ,其中[base64ofusernameandpassword]被您之前计算出的用户名和密码的base64代替。

The exact way of appending custom headers to requests can vary depending on the client technology but it should be easy, no matter which technology is used. 根据客户的技术,将自定义标头附加到请求的确切方法可能有所不同,但是无论使用哪种技术,它都应该很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM