An easy interface for Microsoft Office 365 Oauth Device Code authentication.
Install
pip install oauth_tools
Example
from oauth_tools import AuthManager
import webbrowser
import creds
import os
if not os.path.exists('users.json'):
open('users.json', mode='wt').write(json.dumps({}))
authManager = AuthManager(
# Get your client/tenant ID by following these instructions:
# https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad-app
microsoftClientID=creds.clientID,
microsoftTenantID=creds.tenantID,
)
authManager.SaveIncompleteOACallback = lambda ID, data: open('incomplete.json', mode='wt').write(
json.dumps({ID: data}, indent=2))
authManager.GetIncompleteOACallback = lambda ID: json.loads(open('incomplete.json', mode='rt').read()).get(ID, None)
authManager.SaveToDBCallback = lambda ID, data: open('users.json', mode='wt').write(
json.dumps({ID: data}, indent=2))
authManager.GetFromDBCallback = lambda ID: json.loads(open('users.json', mode='rt').read()).get(ID, None)
MY_ID = 'Grant'
user = authManager.GetUserByID(MY_ID)
if user is None:
# the user has not authenticated before
d = authManager.CreateNewUser(MY_ID)
webbrowser.open(d['verification_uri'])
print('Enter the code', d['user_code'])
while True:
time.sleep(d['interval'])
status = authManager.CheckOAStatus(MY_ID)
print('status=', status)
if status == 'Success':
break
user = authManager.GetUserByID(MY_ID)
print('user=', user)
The output looks like
>>> Enter the code A4S4QS4EG >>> status= Waiting for user to authenticate >>> status= Success >>> user= <User: ID=Grant, EmailAddress=grant@grant-miller.com, AccessToken=abcdefghijklm...>
Metadata
Release files for oauth-tools 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| oauth_tools-0.0.2.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| oauth_tools-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.0 kB
Release files / oauth_tools-0.0.2.tar.gz
| Download URL | oauth_tools-0.0.2.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33fa7bfd85e8d9b273088ddf07a319232b67fda5d3657500afbcdce347a145c1
|
|
BLAKE2b-256 checksum How to use checksums |
e635e5e7d3c249462d4b0b86f812c62841625bc2159b8496a9488ee713140612
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
|
Release files / oauth_tools-0.0.2-py3-none-any.whl
| Download URL | oauth_tools-0.0.2-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2946839f6d21f816ac70534511f2b5b2626e1a8f6d4c183cb17a62b3adbe08c7
|
|
BLAKE2b-256 checksum How to use checksums |
147d88a85d0885403ccdb154379730ef16fb541c24e1512f49051e63e05863ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
|