2

I am working on developing an API call which needs to authenticate to a proxy. I have managed to do this by explicitly entering my proxy information. Like so:

import requests

proxies = {'https': "https://user:password@proxyIP:port"}

response = requests.get('www.google.com', proxies=proxies)

The question is how do I grab the credentials of the currently logged in user and then pass them to the proxy. In my research I have come across this ServerFault post - the answer wasn't helpful but there is another one by shellster which seems to work. However, I cannot make sense of his code.

I have also install requests_negotiate_sspi (docs) and attempted to leverage the HttpNegotiateAuth module as mentioned here but I cannot seem to figure it out.

Note: I am using Python 3.7 and am in Windows 7 + 10 Environment.

EDIT

This question specifies proxies, however I really need to know how this works for other domain resources, like SharePoint, User Shares, etc.

There has to be a pythonic way to accomplish this!

Joe
  • 2,641
  • 5
  • 22
  • 43
  • Did you get solution to this? I am able to do this in C# using HttpWebRequest and UseDefaultCredentials. However i am not able to see anything like that in python – anandhu Aug 12 '20 at 02:29
  • @automaticSoldier No never found a working solution and it is driving me nuts. There absolutely has to be a python solution for sso – Joe Aug 12 '20 at 02:43
  • I saw a solution with requests_negotiate_sspi , but i not able to install that package. it says no package found with matching requirements – anandhu Aug 12 '20 at 02:51
  • oh, i just noticed your comment, thats in that one also you are explicitly stating credentials, thanx – anandhu Aug 12 '20 at 02:53
  • @automaticSoldier yeah if you are just trying to authenticate to the proxy you can specify the credentials. – Joe Aug 12 '20 at 13:54
  • sorry if i am asking rubbish, i am new to this, I dont need to change any proxy thing. Just need to get the html from webpage that has single signon(which i was able to do from vb.net using default credentials). In that case does requests_negotiate_sspi need thats credentials as in below solution?. (I couldn't try it out. I am not able to install the library. it says no package found with matching req. (i'm on python 3.8) – anandhu Aug 13 '20 at 04:02
  • @automaticSoldier I see what you are trying to do now. I'll try and test that today. You should see why you cannot import sspi. Try to see where it downloaded. If you have multiple Python environments it may not be where you think. You can either manually move it to your site packages or use `sys` module to append the directory it is in to your path. – Joe Aug 13 '20 at 11:09

1 Answers1

0

The following worked for me when connecting to sharepoint using requests_negotiate_sspi:

import requests
from requests_negotiate_sspi import HttpNegotiateAuth

proxies = {'https': "https://user:password@proxyIP:port"}
response = requests.get('www.google.com', proxies=proxies, auth = HttpNegotiateAuth())
Smiddy
  • 1
  • 2
  • 3
    Here you are still explicitly defining your credentials. I was looking for a way to pull the credentials from the currently logged in user and pass them to authenticate. This would prevent the user (or the script) from having to manually enter creds – Joe Apr 25 '19 at 21:13