基本身份验证(HTTP Basic Authentication)
互联网产品开发过程中,web应用系统公布的api包括2种
1.直接调用
2.需要验证
多用在公布API接口中。
基本身份验证是api在调用的时候,即发送http请求,在HTTP头中传入用户名与密码。
a. 官方例子:
class PostsController < ApplicationController
USER_NAME, PASSWORD = "dhh", "secret"
before_filter :authenticate, :except => [ :index ]
def index
render :text => "Everyone can see me!"
end
def edit
render :text => "I'm only accessible if you know the password"
end
private
def authenticate
authenticate_or_request_with_http_basic do |user_name, password|
user_name == USER_NAME && password == PASSWORD
end
end
end
b. 一个实例测试
Controller Code
before_filter :authenticatedef authenticate
authenticate_or_request_with_http_basic do |username, password|
@user = User.authenticate(username, password) # 替换成你自己的逻辑代码
end
end
Functional Test
def setup
@controller = AdminController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
set_basic_authentication
end
def test_basic_authentication_success
get :index
assert_response :success
end
def set_basic_authentication
@request.env['HTTP_AUTHORIZATION'] = ‘Basic ‘ + Base64::b64encode(”taito:123456”) # 这里换成你自己的用户名和密码
end
分享到:
相关推荐
Apache Tomcat 软件是Jakarta Servlet、 Jakarta Server Pages、 Jakarta Expression Language、 Jakarta WebSocket、 Jakarta Annotations和 Jakarta Authentication 规范的开源实现 。 压缩包内容: apache-...
Authentication- IO Capabilities.cywrk.Archive01.zip
此版本是个 bug 修复版本 安全更新 -------- * sshd(8): OpenSSH 7.0 contained a logic error in PermitRootLogin= prohibit-password/without-password that could, depending on compile-time configuration...
instantclient-basic-windows.x64-12.2.0.1.rar。数据库为oracle19C,客户端连接工具为plsql,报错显示ORA-28040: No matching authentication protocol,原因为数据库版本高于客户端,需要更新客户端程序。 使用...
cas-server-webapp-6.1.x.war Yelu大学研发的CAS(Central Authentication Server) , 单点登录服务器 , 将war包放置到tomcat/webapp中即可运行
cas-server mysql相关jar包(cas-server-support-jdbc-5.3.14.jar、cas-server-support-jdbc-authentication-5.3.14.jar、cas-server-support-jdbc-drivers-5.3.14.jar、mysql-connector-java-5.1.28.jar)
资源来自pypi官网。 资源全名:django-authentication-0.1.2.tar.gz
资源分类:Python库 所属语言:Python 资源全名:openlxp-authentication-1.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
802.1x Authentication
secure-boot-image-authentication-11.30.16
jwt-react-authentication-源码.rar
A.2. 持久登陆(Remember-Me)表 A.3. ACL表 A.3.1. Hypersonic SQL A.3.1.1. PostgreSQL B. 安全命名空间 B.1. Web应用安全 - <http> 元素 B.1.1. <http> 属性 B.1.1.1. servlet-api-provision B....
jar包,官方版本,自测可用
A.2. 持久登陆(Remember-Me)表 A.3. ACL表 A.3.1. Hypersonic SQL A.3.1.1. PostgreSQL B. 安全命名空间 B.1. Web应用安全 - <http>元素 B.1.1. <http>属性 B.1.1.1. servlet-api-provision B.1.1.2. path...
eos-fop-ca-debug-V1.29-184.apk
Aspnet-microsoft-authentication-graph-helpers.zip,库,其中显示了使用Microsoft Graph和ADAL对ASP.NET应用程序进行更轻松操作的功能。Microsoft Graph帮助程序,asp.net是一个开源的web框架,用于使用.net构建现代...
文档中没有添加新功能的介绍,但是将之前拼写错误的一些类名进行了修正,建议开发 者以这一版本的文档为参考。 另:Spring Security 从2010-01-01 以后,版本控制从SVN 换成了GIT,我们在翻译文档的 时候,...
OpenSSH is the premier connectivity tool for ... In addition, OpenSSH provides a large suite of secure tunneling capabilities, several authentication methods, and sophisticated configuration options.
资源来自pypi官网。 资源全名:trytond_ldap_authentication-4.2.0-py2-none-any.whl