Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy Authentication #1802

Closed
ghost opened this issue Mar 14, 2016 · 23 comments
Closed

Proxy Authentication #1802

ghost opened this issue Mar 14, 2016 · 23 comments

Comments

@ghost
Copy link

ghost commented Mar 14, 2016

Background

I'm using capybara (2.6.2) to build an rspec-extension called proxy_rb to do TDD of our HTTP proxy environments. Setting the proxy without any proxy authentication works fine. Authentication against proxies using the BASIC-scheme does not work.

This is a followup to SeleniumHQ/selenium-google-code-issue-archive#5209. Hope there's no other issue about this issue. I found none.

Expected Behavior -

Selenium enters Username + Passwort for Proxy Authentication in Firefox.

Actual Behavior -

Firefox shows Username + Passwort-Form which is closed after a short time span.

@p0deje p0deje changed the title Proxy Authentication (Firefox, Ruby WebDriver) Proxy Authentication Mar 15, 2016
@stevenmccord
Copy link

Having this same issue trying to add a proxy that requires authentication. I am utilizing Chrome but it still doesn't allow me to pass in a proxy with authentication.

@crownpku
Copy link

crownpku commented Aug 4, 2017

Hi, I'm using chromedriver with selenium python. I still cannot find a way to correctly handle proxy authentication, and all the methods I find through googling fail on my case. Any suggestions?

@Nolski
Copy link

Nolski commented Feb 26, 2018

I'm using geckodriver and also having issues when trying to use a proxy with basic auth.

This is using Firefox 58

profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", ip)
profile.set_preference("network.proxy.http_port", port)
profile.set_preference("network.proxy.ssl", ip)
profile.set_preference("network.proxy.ssl_port", port)
credentials = '{}:{}'.format(proxy_info['username'], proxy_info['password'])
credentials = b64encode(credentials.encode('ascii')).decode('utf-8')
# b64 encode username and password as is required by the `Proxy-Authentication` header
profile.set_preference("extensions.closeproxyauth.authtoken", credentials) 

@oleksiivasylenko
Copy link

2018, still facing proxy auth issues.
2018-08-10_105603

C#, chromedriver 2.41.

Would it be fixed? It's 877 days already behind :)

@scottie
Copy link

scottie commented Jan 5, 2019

2019 still same issue, 1027 days now :)
Using hacky autoit scripts is all good but what if you run leaderless ??
Also the user:[email protected] trick dont work now days....

Firefox;

@ghost
Copy link

ghost commented Apr 9, 2019

Still no way to enter Username and password....

@viseth
Copy link

viseth commented Apr 9, 2019

Please it looks like, we all need this feature. Any expected delivery date or workaround ?
Most of companies requires a proxy authentication.
Feedback most appreciated. I keep trusting Selenium !

@viseth
Copy link

viseth commented Apr 10, 2019

@cgoldberg any hints ?
Here's the version I use selenium-server-standalone 3.141.59 , jdk-11.0.2. firefox: 60.6.1esr, geckodriver-v0.24.0.

I have tried:

profile.SetPreference("network.proxy.http", "http://<user>:@:")

OR

    String PROXY = "<proxy>:<port>"
    Proxy proxy = new Proxy()
    proxy.setProxyType(Proxy.ProxyType.MANUAL)
    proxy.setHttpProxy(PROXY)
    proxy.setSslProxy(PROXY)
    proxy.setSocksProxy(PROXY)
    proxy.setSocksVersion(5)
    proxy.setSocksUsername("<someDOmain>\<user>")
    proxy.setSocksPassword("<pwd>")

    options.setCapability(CapabilityType.PROXY, proxy)

Nothing works,

Thanks

@adiohana
Copy link
Contributor

As a workaround, you can install any proxy add-on for firefox and send the basic authorization as a header - Basic {username:password}
We made our own light weight add-on and using it in FF.

@viseth
Copy link

viseth commented Apr 11, 2019

@adiohana thanks for your feedback. I'll check that workaround. So no straightforward way to do it... since I need to check for other webbrowser (IE, Chrome).

@adiohana
Copy link
Contributor

@viseth I'm sure there is a proper way to do it and fix the issue. I will try to dig deeper but it will take some time.
As for other browsers, in Chrome and FF you can use the same extension as long as you follow the API's. One more note, if you want to use an extension in Chrome Headless, this may not be possible (at least for Chrome v.63 so you will have to use a different workaround (Devtools API for example).
Let me know if you need more examples.

@viseth
Copy link

viseth commented Apr 11, 2019

@adiohana definitly if you can me to some example, it will be great and save me time. Thanks a lot !

@adiohana
Copy link
Contributor

Code for extension is:

browser.webRequest.onBeforeSendHeaders.addListener( handler, {urls: ["<all_urls>"]}, ['requestHeaders', 'blocking'] );

I'm using the localStorage to pass the username and password because I need it to be dynamic. If your's is always the same, you can state the value in the extension itself.

function handler(details) { details.requestHeaders.push({name: "Proxy-Authorization", value: getAuthHeaderVal()}); return {requestHeaders: details.requestHeaders}; }; function getAuthHeaderVal() { var res = localStorage.getItem('auth_header_value'); if (res) { return res; } else { return ""; } }

Then, when you launch your WebDriver, you can install the extension, get it's uuid and add values to localStorage like this:
driver.get("moz-extension://" + uuid); driver.executeScript("localStorage.setItem('auth_header_value', 'Basic " + proxyHeaderValue + "')");

@jclusso
Copy link

jclusso commented Apr 15, 2019

This is crazy that this is still broken :(

@luke-hill
Copy link
Contributor

@shs96c should we close this in favour of #6644 - As the main discussion about the complexities are being done there?

@oleksiivasylenko
Copy link

@adiohana, I've used that trick as far as I don't need headless, but now I need headless and it is not possible in that mode :(

@adiohana
Copy link
Contributor

@oleksiivasylenko
which browser you are using?
FF headless should work with extension.
Chrome headless will not work with extension and there is a workaround to use DevTools API to add headers for all requests. It will be available in Selenium 4 (#6667). If you want, I can guide you how to do it manually until Selenium 4 will be released.

@oleksiivasylenko
Copy link

Thank you @adiohana!
I remember I used Chrome.
Please give me articles about workaround you mentioned.

@diemol
Copy link
Member

diemol commented Apr 16, 2019

Closed in favour of #6644, thanks for pointing it out @luke-hill

@diemol diemol closed this as completed Apr 16, 2019
@limsammy
Copy link

limsammy commented May 28, 2019

Code for extension is:

browser.webRequest.onBeforeSendHeaders.addListener( handler, {urls: ["<all_urls>"]}, ['requestHeaders', 'blocking'] );

I'm using the localStorage to pass the username and password because I need it to be dynamic. If your's is always the same, you can state the value in the extension itself.

function handler(details) { details.requestHeaders.push({name: "Proxy-Authorization", value: getAuthHeaderVal()}); return {requestHeaders: details.requestHeaders}; }; function getAuthHeaderVal() { var res = localStorage.getItem('auth_header_value'); if (res) { return res; } else { return ""; } }

Then, when you launch your WebDriver, you can install the extension, get it's uuid and add values to localStorage like this:
driver.get("moz-extension://" + uuid); driver.executeScript("localStorage.setItem('auth_header_value', 'Basic " + proxyHeaderValue + "')");

Hey there @adiohana , attempting to use this solution for my Selenium app. How are you grabbing the internal UUID after loading the extension?

@adiohana
Copy link
Contributor

i recently answered in SO
https://stackoverflow.com/q/56288424/3141682

@limsammy
Copy link

i recently answered in SO
https://stackoverflow.com/q/56288424/3141682

@adiohana mind if I take a quick peek at your maifest.json?

@adiohana
Copy link
Contributor

@limsammy

`{
"name": "Name",
"version": "1.0.31",
"manifest_version": 2,
"description": "Description",
"background": {
"scripts": [ "background.js"]
},
"browser_action": {
"default_icon": "startup.png",
"default_title": "Title"
},
"icons": {
"48": "startup.png"
},

"permissions": [
"storage",
"webRequest",
"webRequestBlocking",
"<all_urls>"
]
}`

@lock lock bot locked and limited conversation to collaborators Aug 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests