spotify/requests-crtauth

Name: requests-crtauth

Owner: Spotify

Description: A crtauth authentication plugin for Python Requests

Created: 2015-09-17 16:11:06.0

Updated: 2016-01-28 07:51:42.0

Pushed: 2015-09-21 22:30:46.0

Homepage: null

Size: 200

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

requests-crtauth

Build Status

A plugin to support crtauth authentication in Python Requests.

Usage

requests-crtauth works as an authentication plugin for Python Requests. See the authentication documentation for more details. The following arguments may be provided to a new instance of HttpCrtAuth:

name: User to authenticate as. Defaults to $USER.
ate_key: A PEM encoded private key string. Overrides signer.
er: A crtauth SigningPlug instance. Defaults to using the SSH agent (AgentSigner).
ion: Integer version of the crtauth protocol. Defaults to version 1.

Here's an example.

1]: import requests, requests_crtauth, json, logging
2]: logging.basicConfig(level=logging.DEBUG)
3]: session = requests.Session()
tpCrtAuth() will default to authenticating with your $USER env variable and a key from your SSH agent.
 specify an explicit key: requests_crtauth.HttpCrtAuth(username='negz', private_key='key data as a string')
4]: session.auth = requests_crtauth.HttpCrtAuth()
5]: data = json.dumps({'comment': 'I\'m a comment!'})
6]: headers = {'content-type': 'application/json; charset=utf-8'}
7]: response = session.put('https://db.spotify.net/v1/things/yomaris', data=data, headers=headers)
:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): db.spotify.net
G:requests.packages.urllib3.connectionpool:"PUT /v1/things/yomaris HTTP/1.1" 401 12
G:root:Sending challenge request
G:requests.packages.urllib3.connectionpool:"HEAD /_auth HTTP/1.1" 200 0
G:root:Sending response to challenge REDACTED
G:requests.packages.urllib3.connectionpool:"HEAD /_auth HTTP/1.1" 200 0
G:root:Stored CHAP token REDACTED
G:root:Using newly stored CHAP token.
G:requests.packages.urllib3.connectionpool:"PUT /v1/things/yomaris HTTP/1.1" 200 None
8]: response.ok
8]: True

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.