0

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"

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

Any ideas how to bypass this?

Matthew Jaeger
  • 59
  • 1
  • 11

1 Answers1

1

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

Here is how I've done it:

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

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

In this example it's YWRtaW46c2VjcmV0MTIz

brew install nginx

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

Past there this code:

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";
        }   
    }   
}

Change proxy_pass to match your app url.

And proxy_set_header to Authorization "Basic <your_encoded_creds>"

Then: brew services start nginx

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

Matthew Jaeger
  • 59
  • 1
  • 11
  • I have this configured as documented (except for my values for proxy_pass url and Authorization encoded password) and I still see the authentication dialog from the site when I go to localhost:8080. Any ideas why I would see that instead of being authenticated? If I use the same URL with the credentials included (https://@... it works. But Safari doesn't support that. – user1199956 Feb 24 '20 at 21:22