mullender / python-ntlm

Automatically exported from code.google.com/p/python-ntlm
90 stars 42 forks source link

Need ability to authenticate as "current user" without passing username/password #21

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to be able to write code like this.
Note that I don't specify username and password. 
I want to make a request using NTLM authentication with the credentials of the 
user making the call. 
This should in theory be pretty easy to do (not easy for me though). I think 
there are some clues in this post
http://stackoverflow.com/questions/2916396/smtp-through-exchange-using-integrate
d-windows-authentication-ntlm-using-python

--- snip ---

import urllib2
from ntlm import HTTPNtlmAuthHandler

url = "http://ntlmprotectedserver/securedfile.html"
# create the NTLM authentication handler
# since we aren’t passing a password manager, use credentials
# of calling user
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler()

# create and install the opener
opener = urllib2.build_opener(auth_NTLM)
urllib2.install_opener(opener)

# retrieve the result
response = urllib2.urlopen(url)
print(response.read())

Original issue reported on code.google.com by kevin.ma...@gmail.com on 28 Sep 2010 at 11:16

GoogleCodeExporter commented 9 years ago
python-ntlm is most useful when you do not have the option to `import sspi` 
(not running on Windows)...

Original comment by dho...@gmail.com on 18 Jan 2011 at 3:23

GoogleCodeExporter commented 9 years ago
I agree with both the need to support this when running on Windows and the need 
to use alternate auth handlers when running elsewhere.  I'm not sure how to 
best integrate the proposed solution.  I'll think about it and get back to you.

Original comment by samw...@gmail.com on 12 Feb 2013 at 12:50

jabesq commented 9 years ago

Is there any update on this issue ?

railocius commented 6 years ago

I would also like this!

ledikari commented 6 years ago

is this feature included on the current version?

rajpchaudhary commented 5 years ago

For Python 2.7 Please use below solution.

I am using VS code. Installed "Don Jayamanne" version in code from Extension tab. using Terminal Install "requests" and "requests_negotiate_sspi" libraries

Steps

Step1: Open VS code Step2: Create New folder and give any name Step3: Create new file under newly created folder and give any name with extension ".py" eg --> test.py Step4: in Left Panel select Extension tab Step5: Type Python in Search Extensions in Marketplace Step6: Open Terminal from Terminal Menu --> NewTerminal Step7: Type following command in Terminal to install "requests" library e.g --> pip install requests Step8: Type following command in Terminal to install "requests_negotiate_sspi" library e.g --> pip install requests_negotiate_sspi

Step9: Type following code in test.py file

import requests from requests_negotiate_sspi import HttpNegotiateAuth

--------------- Get Request with Window Authentication -----------------

GetUrl = "http://servername/api/controller/Methodname" # Here you need to set your get Web api url response = requests.get(GetUrl, auth=HttpNegotiateAuth()) print("Get Request Outpot:") print("--------------------") print(response.content)

print("--------------------------------------------------------------------------------")

--------------- Post Request with Window Authentication -----------------

PostUrl = "http://servername/api/controller/method" #your post Web api url data={'EntityId':'5908'} # -- Model to send with request -- response1 = requests.post(PostUrl,data=data, auth=HttpNegotiateAuth()) print("Post Request Outpot:") print("--------------------") print(response1.content)

Step10: in Left Panel select debug tab

Step11 : After selecting bebug run program and see your output in Debug console.