Http Authentication

1. 基本认证:

首先转一下 小坦克写的http基本认证的流程,写的非常好,我就不再多啰嗦了

转自  http://www.cnblogs.com/TankXiao/archive/2012/09/26/2695955.html

什么是HTTP基本认证

桌面应用程序也通过HTTP协议跟Web服务器交互, 桌面应用程序一般不会使用cookie, 而是把 "用户名+冒号+密码"用BASE64编码的字符串放在http request 中的header Authorization中发送给服务端, 这种方式叫HTTP基本认证(Basic Authentication)

当浏览器访问使用基本认证的网站的时候, 浏览器会提示你输入用户名和密码,如下图

假如用户名密码错误的话, 服务器会返回401 如下图

HTTP基本认证的过程

第一步:  客户端发送http request 给服务器,

第二步:  因为request中没有包含Authorization header,  服务器会返回一个401 Unauthozied 给客户端,并且在Response 的 header "WWW-Authenticate" 中添加信息。

第三步:客户端把用户名和密码用BASE64编码后,放在Authorization header中发送给服务器, 认证成功。

第四步:服务器将Authorization header中的用户名密码取出,进行验证, 如果验证通过,将根据请求,发送资源给客户端

使用Fiddler Inspectors 下的Auth 选项卡,可以很方便的看到用户名和密码:

HTTP基本认证的优点

HTTP基本认证,简单明了。Rest API 就是经常使用基本认证的

每次都要进行认证

http协议是无状态的, 同一个客户端对 服务器的每个请求都要求认证

HTTP基本认证和HTTPS

把 "用户名+冒号+密码" 用BASE64编码后的string虽然用肉眼看不出来, 但用程序很容易解密,上图可以看到Fiddler就直接给解密了。 所以这样的http request 在网络上,如果用HTTP传输是很不安全的。 一般都是会用HTTPS传输, HTTPS是加密的, 所以比较安全.

使用python进行http基本认证

这边使用 requests 这个库

1 >>> from requests.auth import HTTPBasicAuth
2 >>> requests.get(‘https://api.github.com/user‘, auth=HTTPBasicAuth(‘user‘, ‘pass‘))
3 <Response [200]>

由于基本认证非常普遍,还有更简单的方法

1 >>> requests.get(‘https://api.github.com/user‘, auth=(‘user‘, ‘pass‘))
2 <Response [200]>
				
时间: 2024-07-31 11:22:49

Http Authentication的相关文章

CAS Authentication failed!

在本机测试CAS与phpCAS客户端集成正常,但是部署到其他服务器上就不能正常运行了,提示"CAS Authentication failed!",如下图所示 才开始百思不得其解啊,然后重新检查一遍部署的配置文件,然后检查CAS的官方文档,查看配置是否少配置的了属性什么的,还检查了php的ext插件,发现php5只需要curl和openssl的php插件就足够了,最后终于在phpCAS的日志文件中发现了问题. 重日志中可以看到是由于连接超时照成的,然后登录的casPHP所在的主机,使用

使用su - root出现Authentication failure

使用su - root出现 Password: su: Authentication failure 原因:ubtun系统默认是没有激活root用户的 解决方法: 输入命令:sudo passwd root 显示 Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully 注意: (Enter new UNIX password: )不能和(Password: )输入的相同,如果

Google Authentication的实现 - Odoo 安全登录

在前边的一篇文章中,我们提到了利用二次验证增强Odoo登录的可靠性:http://www.cnblogs.com/kfx2007/p/6023991.html 今天我们来具体实现这一步: 后端的实现 我们需要一个地方来存储二次验证的安全码,拓展用户字段: class res_users(models.Model): _inherit='res.users' enable_google_auth = fields.Boolean(u'启用Google两步验证') otp_str = fields.

解决passwd: Authentication token manipulation error

passwd 命令修改用户密码出现passwd: Authentication token manipulation error 今天,在测试用户文件属性的时候,修改用户密码发现报此错误. 百度上搜结果: /etc/passwd 文件被锁定 /etc/passwd  /etc/shadow 文件不同步 磁盘空间不足 inode 满了 /etc/pam.d/passwd 相关动态库文件问题 结果,我都试过了,最后发现问题了,我之前不小心把 /etc/pam.d/文件夹内容全部删除过,后来进入恢复模

Disconnected: No supported authentication methods available (server sent: publickey)

安装Git客户端后,进行PULL时报如下错误 disconnected no supported authentication methods available(server sent: publickey,keyboard interactive)解决方案 因为TortoiseGit和Git的冲突 我们需要把TortoiseGit设置改正如下. 1.找到TortoiseGit -> Settings -> Network 2.将SSH client指向~\Git\usr\bin\ssh.e

SharePoint Claim base authentication EnsureUser 不带claim(i:0#.w|)user Failed

环境信息: 带有Form base authentication(FBA).Active Directory Federation Services(ADFS).以及windows Authentication的混合认证的SharePoint环境. 问题具体描述: 在该环境中,调用EnsureUser添加一个普通的AD user,sharepoint 会throw "The specified user userLoginName could not be found.",当然此处的u

Web API 基于ASP.NET Identity的Basic Authentication

今天给大家分享在Web API下,如何利用ASP.NET Identity实现基本认证(Basic Authentication),在博客园子搜索了一圈Web API的基本认证,基本都是做的Forms认证,很少有Claims认证(声明式认证),而我们在用ASP.NET Identity实现登录,认证,授权的时候采用的是Claims认证. 在Web API2.0中认证接口为IAuthenticationFilter,我们只需实现该接口就行.创建BasicAuthenticationAttribut

Global Azure启用Multi-factor Authentication配置介绍

说到Azure下的Multi-factor Authentication服务,其实很直观的可以大概了解其意思,在azure上的Multi-factor Authentication服务可以提供用户登录Azure portal进行多重身份验证的功能,用户除了输入正确的密码信息还需要设置需要验证一些自定义信息: 自定义信息分为:Mobile apps.Phone calls.Text messages等,具体见下吧: 我们首先登录azure portal,打开Multi-factor Authent

TortoiseGit disconnected: no supported authentication methods available(server sent:publickey)

之前一直用命令行,现在想用图形工具,TortoiseGit,安装后遇到错误 TortoiseGit disconnected: no supported authentication methods available(server sent:publickey) 解决方法 因为TortoiseGit和Git的冲突 我们需要把TortoiseGit设置改正如下. 1.找到TortoiseGit -> Settings -> Network 2.将SSH client指向~\Git\bin\ss

ubuntu 突然不能 sudo成功,报错su: Authentication failure

通过查看日志: /var/log/auth.log 报错: su[9959]: PAM unable to dlopen(pam_rootok.so): /lib/security/pam_rootok.so: cannot open shared object file: No such file or directory su[9959]: PAM adding faulty module: pam_rootok.so su[9959]: PAM unable to dlopen(pam_u