requests/requests-kerberos

How to get the username from the HTTPKerberosAuth() object

piersf opened this issue · 1 comments

Hi there,

This is not so much of an issue but more of a question. I am not very familiar with the details of how Kerberos authentication works so please ignore my ignorance.

I have the below code:

import requests
session = requests.Session()
session.auth = HTTPKerberosAuth(
    mutual_authentication="REQUIRED"
)

The above code works fine and I can use session.auth object further down and successfully make a call to a URL with the session object.

What I am trying to do is find out the value of the username that is authenticated/logged in on the system where the above code runs. That is, what user the HTTPKerberosAuth() object has if that makes sense. For example, if I am logged in on Windows with user/account JoeDoe, i would expect to get that information somehow from the HTTPKerberosAuth() object

I can see that session.auth.__dict__ has a principal attribute but that is set to None.

Any idea if this is possible?

Thank you in advance!

You cannot so this. You can set the principal to control what user to authenticate as and select a specific credential in the cache if available but you cannot use this library to determine what principal it has or it will use. There is no API implemented in pykerberos to provide this information.