NEWT AUTH

In [3]:
from requests import Session
s = Session()
In [4]:
r = s.post("https://newt.nersc.gov/newt/auth", {"username": "myuser", "password": "XXXXXXXX"})

The newt_sessionid object is actually returned with the auth request so you don't need to dig around the cookies.

In [5]:
r.json()
Out[5]:
{u'auth': True,
 u'newt_sessionid': u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
 u'session_lifetime': 43199,
 u'username': u'myuser'}

Now you can just extract this newt_session_id and pass it on with a future request

In [16]:
newt_sessionid = r.json()['newt_sessionid']

A new session can now be initiated as long as it has the newt_sessionid string. This newt_sessionid is a short-lived token and can be passed to other clients or servers that need access.

In [14]:
s2 = Session()
r = s2.get("https://newt.nersc.gov/newt/auth", cookies={'newt_sessionid': newt_sessionid})
In [15]:
r.json()
Out[15]:
{u'auth': True,
 u'newt_sessionid': u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
 u'session_lifetime': 39698,
 u'username': u'myuser'}