An MAuth client based around the excellent requests library.
Project description
requests-mauth
requests-mauth is a python requests (http://docs.python-requests.org/en/latest/) Authentication implementation for Medidata's MAuth authentication system.
Prerequisites
To use MAuth authentication you will need:
- An MAuth APP ID
- An MAuth private key (with the public key registered with Medidata's MAuth server)
Using
import requests
from requests_mauth import MAuth
# MAuth configuration
APP_UUID = "<MAUTH_APP_UUID>"
private_key = open("private.key", "r").read()
mauth = MAuth(APP_UUID, private_key)
# Call an MAuth protected resource, in this case an iMedidata API
# listing the studies for a particular user
user_uuid = "10ac3b0e-9fe2-11df-a531-12313900d531"
url = "https://innovate.imedidata.com/api/v2/users/%s/studies.json" % user_uuid
# Make the requests call, passing the auth client
result = requests.get(url, auth=mauth)
# Print results
if result.status_code == 200:
print([r["uuid"] for r in result.json()["studies"]])
print(result.text)
Development
We use travis for automated CI of the code (and status checks are required to pass prior to PR merges being accepted).
We use travis to deploy updated versions to PyPI (only from master
)
For local development (cross version) we use tox with pyenv to automate the running of unit tests against different python versions in virtualised python environments.
To setup your environment:
- Install Python
- Install Pyenv
$ brew update $ brew install pyenv
- Install Pyenv versions for the Tox Suite
$ pyenv install 2.7.16 3.3.6 3.4.6 3.5.3 3.6.1 3.7.2
- Install Tox
$ pip install tox tox-pyenv
- Setup the local project versions (one for each env in the
envlist
)$ pyenv local 2.7.16 3.3.6 3.4.6 3.5.3 3.6.1 3.7.2
- Make any changes, update the tests and then run tests with
tox
Name Stmts Miss Cover ------------------------------------------------ requests_mauth/__init__.py 3 0 100% requests_mauth/client.py 31 0 100% requests_mauth/rsa_sign.py 34 0 100% ------------------------------------------------ TOTAL 68 0 100% stats runtests: commands[1] | coverage html _________________________________________________________________________________________________________ summary __________________________________________________________________________________________________________ clean: commands succeeded py27: commands succeeded py33: commands succeeded py34: commands succeeded py35: commands succeeded py36: commands succeeded stats: commands succeeded congratulations :)
- Coverage report can be viewed using
open htmlcov/index.html
- Push your changes and create a PR to
master
- Once the PR is complete, tag the branch and push it to github, this will trigger Travis to deploy to PyPI (make sure the version is consistent)
$ git checkout master $ git pull $ git tag -a 1.0.2 -m "Requests MAuth 1.0.2" $ git push --tags
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file requests_mauth-1.1.0.tar.gz
.
File metadata
- Download URL: requests_mauth-1.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71708f1b46008f6950cf29034b4d45531bc59524d3186d869a1f247a6da659de |
|
MD5 | 000cdf4227f99c4aa8a7c4e65d2b666d |
|
BLAKE2b-256 | d4eb47d63ab35fc44e826b9426062b364daf9142be53dfc051801fc2a3a38690 |
File details
Details for the file requests_mauth-1.1.0-py3.7.egg
.
File metadata
- Download URL: requests_mauth-1.1.0-py3.7.egg
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f557825c481a5be3c71284cfacde3a5c59585667969ad12db7442fc81fe88206 |
|
MD5 | 96120b69790708a489cb3c3528d711ae |
|
BLAKE2b-256 | c0d33ca2de4fef593a7491ac1838533bb9a5d8fd2a12a8dcf5401f9f49dfea99 |
File details
Details for the file requests_mauth-1.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: requests_mauth-1.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5cf35f93f583ef26904b6cf425d8ec1d479dd8b006a2d540a5be5aa2360693d |
|
MD5 | 58f6e7058bdd902bed3cee1a5f26466d |
|
BLAKE2b-256 | f6d98bef95d7a4df113606dbcc30d25d807534743430ef438760f6c5ba236b00 |