使用Safari Capybara Selenium的基本浏览器身份验证 [英] Basic browser authentication with Safari Capybara Selenium

查看:237
本文介绍了使用Safari Capybara Selenium的基本浏览器身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Capybara / Selenium的Safari上进行浏览器身份验证时遇到问题。

I've got a problem with browser authentication on Safari using Capybara/Selenium.

我正在使用此代码进行身份验证:

I'm using this code to authenticate:

visit "https://#{ENV['AUTH_USERNAME']}:#{ENV['AUTH_PASSWORD']}@my-staging-app.heroku.com"

这在Chrome和FF上很好用,但在Safari上却不行。

This works just fine on Chrome and FF but not on Safari.

有什么想法可以绕开它吗? p>

Any ideas how to bypass this?

推荐答案

Okey,我找到了解决方案。我不得不使用例如反向代理Nginx并发送适当的标题:)

Okey, I've found the solution for this. I had to use reversed proxy using e.g. Nginx and send proper headers :)

这是我的操作方式:

在此示例中,我将使用凭证登录名:admin 密码:secret123

In this example I'll be using creds login: admin and password: secret123.

转到 https://www.base64encode.org 并对您的信用进行编码 admin:secret123

Go to https://www.base64encode.org and encode your creds admin:secret123.

在此示例中为 YWRtaW46c2VjcmV0MTIz

brew install nginx

sudo vim /usr/local/etc/nginx/nginx.conf

粘贴此代码:

worker_processes  1;  

events {
    worker_connections 1024;
}

http {
    server {
        listen 8080;
        server_name localhost;

        location / { 
            proxy_pass https://your_app.herokuapp.com;
            proxy_set_header Authorization "Basic YWRtaW46c2VjcmV0MTIz";
        }   
    }   
}

更改 proxy_pass 匹配您的应用程序网址。

Change proxy_pass to match your app url.

并将 proxy_set_header 匹配为授权基本< your_encoded_creds>

然后:酿造服务启动nginx

从现在开始,当您点击 http:// localhost:8080 时,您将被重定向到您的页面并登录。

From now on, when you'll hit http://localhost:8080 you'll be redirected to your page and logged in.

这篇关于使用Safari Capybara Selenium的基本浏览器身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆