如果您有受基本身份验证保护的站点,则在 url 中添加用户名和密码后即可自动登录
http://foo:bar@localhost
Run Code Online (Sandbox Code Playgroud)
然而,在 Firefox 中,您仍然会看到一个弹出窗口
Firefox 有没有办法告诉它不要显示此对话框。例如,我可以想象“配置文件”部分中有一个设置来信任此站点(这可能会解决此问题)。任何帮助,将不胜感激!
更新:经过更多搜索后,我发现network.http.phishy-userpass-length可能可行,但是当我检查此内容时,about:config我找不到它。所以这个选项可能已被删除
我的文件中有以下配置.htaccess,它在 Apache 2.2 中工作,但在 2.4 中不起作用:
SetEnvIf Request_URI ^/admin require_auth=true
AuthUserFile /var/www/site.htpasswd
AuthName "Admin Access"
AuthType Basic
Require all denied
Satisfy any
Require valid-user
Allow from env=!require_auth
Run Code Online (Sandbox Code Playgroud)
我如何将其转换为在 Apache 2.4 中工作?基本上,如果 URI 以 开头/admin,则应要求他们提供密码。
我有一个我想要访问的 php 页面,该页面受基本身份验证保护。我知道网址和用户名/密码,它们在代码中列出如下:
url = 'https://henry.php' # note that it is a php website
username = 'foo'
password = 'bar'
Run Code Online (Sandbox Code Playgroud)
Faraday 提供基本的身份验证功能,他们的文档说我应该使用以下代码:
connection = Faraday.new(url: url) do |conn|
conn.basic_auth(username, password)
end
Run Code Online (Sandbox Code Playgroud)
我想获取上述网址的响应正文,以确保基本身份验证确实成功并且我可以访问内容,但我不知道如何操作。我尝试了以下每种方法,但都不起作用:
connection.body
connection.response.body
connection.env.response.body
# or
r = connection.get
r.body
r.response.body
r.env.response.body
# or
r = connection.get '/'
r.body
r.response.body
r.env.response.body
Run Code Online (Sandbox Code Playgroud)
获得尸体的正确方法是什么?
笔记:
在浏览器中,我直接访问https://henry.php,浏览器提示我一个框,询问我的用户名和密码,我输入它们,我可以看到内容 - 我可以看到我拥有的详细信息是正确的,它应该可以工作(这是因为浏览器知道如何进行基本身份验证),但我只是不知道如何使用 Faraday 在代码中执行此操作。
我正在尝试使用 Python 3 获取 POST 请求,它将向使用基本身份验证的平台提交 json 有效负载。我收到 405 状态错误,并认为这可能是由于我的负载格式造成的。我正在学习Python,但仍然不确定何时使用“与”、对象与数组以及某些请求的语法。搜索时,我无法找到使用基本身份验证发布数组的类似问题。以下是我现在有:
import requests
import json
url = 'https://sampleurl.com'
payload = [{'value': '100','utcRectime': '09/23/2018 11:59:00 PM','comment': "test",'correctionValue': '0.0','unit': 'C'}]
headers = {'content-type': 'application/json'}
r = requests.post(url, auth=('username','password'), data=json.dumps(payload), headers=headers)
print (r)
Run Code Online (Sandbox Code Playgroud)
在 API swagger 中测试,CURL 包含以下格式:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '[{"value": "100","utcRectime": "9/23/2018 11:59:00 PM","comment": "test","correctionValue": "0.0","unit": "C"}]'
Run Code Online (Sandbox Code Playgroud) 当我尝试使用这种结构的默认 Selenium 身份验证时,我遇到了一个非常具体的问题username:password@siteurl.com
所以这里有一个问题:如果我使用这样的密码"''asd'asd';123asd'(带有特定符号)traceback会说这URL是不正确的。但如果密码只是数字和字母——一切都可以。下面是正确工作的代码示例,但对于我的示例,我需要用许多特定符号填充密码,并且我无权更改它。
import unittest
from selenium import webdriver
class LoggedTest(unittest.TestCase):
@classmethod
def setUp(inst):
# create a new Chrome session """
inst.driver = webdriver.Chrome()
inst.driver.implicitly_wait(30)
inst.driver.maximize_window()
# navigate to the application home page """
inst.driver.get("http://admin:admin@theinternet.herokuapp.com/basic_auth")
Run Code Online (Sandbox Code Playgroud) python selenium windows-authentication basic-authentication selenium-webdriver
在我的项目中,我有两个不同的身份验证路径:第一个用于普通用户登录,第二个用于雇主登录。因此,我首先使用 AuthenticationProvider 为用户创建一个身份验证过滤器,并且它工作正常。对于第二次身份验证,我创建了其身份验证过滤器,当我为雇主创建另一个身份验证提供程序时,这就是问题所在。当我尝试使用authenticationmanager.authenticate(userPassAuthToken) .\xc2\xa0中的AuthenticationManager实例来验证用户的用户名和密码时,出现java.lang.StackOverflowError: null
\n我不明白当我创建另一个身份验证提供程序时发生了什么,也不明白为什么身份验证管理器会抛出此异常。我认为身份验证管理器对使用哪个提供程序感到困惑。
\n首先,我使用其过滤器和身份验证提供程序为普通用户创建第一个身份验证,如以下代码所示:
\n@Component\npublic class UserPassAuthFilter extends OncePerRequestFilter {\n\n @Autowired\n @Lazy\n private AuthenticationManager authManager;\n @Autowired\n private AuthPath authPath;\n @Autowired\n AuthFilterUtil authFilterUtil;\n @Autowired\n private UserMapper userMapper;\n\n @Override\n protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {\n\n char[] username=request.getHeader("username").toCharArray();\n char[] password=request.getHeader("password").toCharArray();\n\n UserPassAuthToken authentication= new UserPassAuthToken(String.valueOf(username),String.valueOf(password));\n UserPassAuthToken currentAuth =(UserPassAuthToken)authManager.authenticate(authentication);\n if (!currentAuth.isAuthenticated()){\n authFilterUtil.onFailureAuth(response,request,null);\n }\n else {\n SecurityContextHolder.getContext().setAuthentication(currentAuth);\n if(request.getServletPath().equals(authPath.getUserPasswordFilter_pathShouldDo().get(0))) {\n UserDto responseBody = userMapper.mapUserToDto(currentAuth.getUsersDetails().getUsers());\n responseBody.setToken(authFilterUtil.prepareTokenToAuthResponse(\n currentAuth.getAuthorities(),\n currentAuth.getName().toCharArray()\n …Run Code Online (Sandbox Code Playgroud) 一旦你使用无效的凭据作为用户名:密码在rails上插入,我正在努力改变默认消息.authenticate_or_request_with_http_basic
例如,如果我对需要此身份验证的方法发出curl请求,则一旦我插入错误的用户名和密码,它就会返回 HTTP Basic: Access denied.
因此,在这种情况下,我希望能够使用特定的XML格式字符串自定义此消息(就像twitter API一样).那可能吗?
提前致谢
我已配置基本身份验证(在控制器中)
在控制器文件中的所有内容
before_filter :check_logged_in, :only => [:edit, :update, :destroy]
Run Code Online (Sandbox Code Playgroud)
在文件的底部:
private
def check_logged_in
authenticate_or_request_with_http_basic("Ads") do |username, password|
username == "admin" && password == "apple"
end
end
Run Code Online (Sandbox Code Playgroud)
它就像一个魅力,但有一件事我不明白 - 当我提供用户名和密码时,它会长时间保持登录状态,当我点击"删除"或"更新"特定条目时我会我没有得到再次提示.我认为出了问题,但是当我打开另一个浏览器时 - 它再次提示我,但只有一次,我没有;我必须对其余的进行身份验证.然后我认为这是一个cookie问题,但即使我删除了Chrome中的所有Cookie,也没有任何改变.所以我有几个问题:
:check_logged_in, :only => [:edit, :update, :destroy]吗?我正在使用nginx在嵌入式系统中提供静态文件,没有CGI后端.我有多个用户名/密码的基本身份验证.我希望有一个特定的URI根据当前经过身份验证的用户的名称提供不同的内容.
例如,假设浏览器请求URI /index.html.如果浏览器被认证为用户"developer",则可以将其提供给文件/index_developer.html.如果浏览器被认证为"管理员",则可以将其提供给文件/index_administrator.html.
我只希望这个重定向发生在一小组文件上; 大多数将按原样提供.我还需要阻止对实际文件的直接访问,以便没有人可以在系统中进行最终运行.
我试图在JQuery中的服务器上发出一个简单的GET请求.
$.ajax({
headers: {
"Authorization": "Basic " + btoa("hello" + ":" + "world")
},
url: "http://hello.world?Id=1",
method: "GET",
success: function () {
},
}).then(function () {
});
Run Code Online (Sandbox Code Playgroud)
问题是,当请求被发送时,身份验证标头不会正确地放入请求中:
Host: hello.world
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Access-Control-Request-Method: GET
Access-Control-Request-Headers: authorization
Origin: null
Connection: keep-alive
Cache-Control: max-age=0
Run Code Online (Sandbox Code Playgroud)