A client auth library for Anaconda.cloud APIs
Project description
anaconda-cloud-auth
A client library for Anaconda.cloud APIs to authenticate and securely store API keys.
This package also provides a requests client class that handles loading the API key for requests made to Anaconda Cloud services.
Interactive login/logout
In order to use the request client class you must first login interactively. This can be done using the Python API or CLI (see below).
Login API
from anaconda_cloud_auth import login
login()
The login()
function initiates a browser-based login flow. It will automatically
open your browser and once you have completed the login flow it will store an
API key in your system keychain using the keyring
package.
Typically, these API keys will have a one year expiration so you will only need to login once and requests using the client class will read the token from the keyring storage.
If you call login()
while there is a valid (non-expired) API key in your keyring
no action is taken. You can replace the valid API key with login(force=True)
.
Password-based flow (Deprecated)
WARNING: Password-based login flow will be disable in the near future.
You can login into Anaconda Cloud using username/password flow (non-browser)
with the basic=True
keyword argument. The login()
function will interactively
request your username and password before completing login and storing the API
key.
from anaconda_cloud_auth import login
login(basic=True)
Logout
To remove the API key from your keyring storage use the logout()
function.
from anaconda_cloud_auth import logout
logout()
API requests
The Client class is a subclass of requests.Session.
It will automatically load the API key from the keyring on each request.
If the API key is expired it will raise a TokenExpiredError
.
The Client class can be used for non-authenticated requests, if
the API key cannot be found and the request returns 401 or 403 error codes
the LoginRequiredError
will be raised.
To create a Client class in your package use the client_factory()
function,
which takes a user-agent string as input.
from anaconda_cloud_auth import client_factory
Client = client_factory('<my-application>/<version>')
client = Client()
response = client.get("/api/<endpoint>")
print(response.json())
CLI usage
To use anaconda-cloud-auth
as a CLI you will need to install the
anaconda-cloud
package. Once installed you can use the anaconda
CLI to login and logout of Anaconda Cloud.
❯ anaconda login --help
Usage: anaconda login [OPTIONS]
Login to your Anaconda account.
╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --domain TEXT [default: None] │
│ --basic --no-basic Depcrecated [default: no-basic] │
│ --force --no-force [default: no-force] │
│ --help Show this message and exit. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Configuration
You can configure anaconda-cloud-auth
by setting ANACONDA_CLOUD_
environment variables
or use a .env
file. The .env
file must be in your current working directory.
An example template is provided in the repo, which contains the following options,
which are the default values.
# Logging level
LOGGING_LEVEL="INFO"
# Base URL for all API endpoints
ANACONDA_CLOUD_API_DOMAIN="anaconda.cloud"
# Authentication settings
ANACONDA_CLOUD_AUTH_DOMAIN="id.anaconda.cloud"
ANACONDA_CLOUD_AUTH_CLIENT_ID="b4ad7f1d-c784-46b5-a9fe-106e50441f5a"
If you do not specify the .env
file, the production configuration should be the default.
Please file an issue if you see any errors.
Setup for development
Ensure you have conda
installed.
Then run:
make setup
Run the unit tests
make test
Run the unit tests across isolated environments with tox
make tox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file anaconda_cloud_auth-0.1.0a8.tar.gz
.
File metadata
- Download URL: anaconda_cloud_auth-0.1.0a8.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 002e2c1b5cf990ba42f1759f50e9eaaafd164d0a3f58f04037727dce6dce212d |
|
MD5 | c915ff448e98d8f3d72f3a55410c0b73 |
|
BLAKE2b-256 | 937e18b8522bb5860fb4317d31d676d4ee2a83589a12a8ad875ee0340a4dd9f1 |
File details
Details for the file anaconda_cloud_auth-0.1.0a8-py3-none-any.whl
.
File metadata
- Download URL: anaconda_cloud_auth-0.1.0a8-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0196c3bb56df21f85eea0c9847ca66f51274911e8fc7856e592ac62c7045539d |
|
MD5 | 060a2d12984c501e16ba34367c90eba0 |
|
BLAKE2b-256 | 318eb15da010fed34b4a046f5e60de46f9535ed34b3715d88e4f3731efda338c |