Package: anaconda-cloud-auth
anaconda-cloud-authA client library for Anaconda.cloud APIs to authenticate and securely store API keys.This package provides arequestsclient class that handles loading the API key for requests made to Anaconda Cloud services.This package provides aPanel OAuth plugincalledanaconda_cloud.Installationconda install anaconda-cloud-authInteractive login/logoutIn 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 APIfromanaconda_cloud_authimportloginlogin()Thelogin()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 on your system.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 calllogin()while there is a valid (non-expired) API key no action is
taken. You can replace the valid API key withlogin(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 thebasic=Truekeyword argument. Thelogin()function will interactively
request your username and password before completing login and storing the API
key.fromanaconda_cloud_authimportloginlogin(basic=True)LogoutTo remove the API key from your keyring storage use thelogout()function.fromanaconda_cloud_authimportlogoutlogout()API requestsThe BaseClient class is a subclass ofrequests.Session.
It will automatically load the API key from the keyring on each request.
If the API key is expired it will raise aTokenExpiredError.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
theLoginRequiredErrorwill be raised.fromanaconda_cloud_auth.clientimportBaseClientclient=BaseClient()response=client.get("/api/<endpoint>")print(response.json())BaseClient accepts the following optional arguments.domain: Domain to use for requests, defaults toanaconda.cloudapi_key: API key to use for requests, if unspecified uses token set byanaconda loginuser_agent: Defaults toanaconda-cloud-auth/<package-version>api_version: Requested API version, defaults to latest available from the domainextra_headers: Dictionary or JSON string of extra headers to send in requestsTo create a Client class specific to your package, subclass BaseClient and set
an appropriate user-agent and API version for your needs. This is automatically done
if you use thecookiecutterin this repository to create a new package.fromanaconda_cloud_auth.clientimportBaseClientclassClient(BaseClient):_user_agent="anaconda-cloud-<package>/<version>"_api_version="<api-version>"CLI usageTo useanaconda-cloud-authas a CLI you will need to install theanaconda-cloudpackage. Once installed you can use theanacondaCLI 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          Deprecated [default: no-basic]                                                                │
│ --force     --no-force          [default: no-force]                                                                            │
│ --help                          Show this message and exit.                                                                    │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ConfigurationYou can configureanaconda-cloud-authby setting one or moreANACONDA_CLOUD_environment variables or use a.envfile. The.envfile 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"In addition to the variables above you can set the following# API key to use for all requests, this will ignore the keyring token set by `anaconda login`
ANACONDA_CLOUD_API_KEY="<api-key>"

# Extra headers to use in all requests; must be parsable JSON format
ANACONDA_CLOUD_API_EXTRA_HEADERS='<json-parsable-dictionary>'Panel OAuth ProviderIn order to use the anaconda_cloud auth plugin you will need an OAuth client
ID (key) and secret. The client must be configured as followsSet scopes: offline_access, openid, email, profile
Set redirect url to http://localhost:5006
Set grant type: Authorization Code
Set response types: ID Token, Token, Code
Set access token type: JWT
Set Authentication Method: HTTP BodyTo run the app with the anaconda_cloud auth provider you will need to set several
environment variables or command-line arguments. See thePanel OAuth documentationfor more detailsPANEL_OAUTH_PROVIDER=anaconda_cloud or --oauth-provider anaconda_cloud
PANEL_OAUTH_KEY=<key>               or --oauth-key=<key>
PANEL_OAUTH_SECRET=<secret>         or --oauth-secret=<key>
PANEL_COOKIE_SECRET=<cookie-name>   or --cookie-secret=<value>
PANEL_OAUTH_REFRESH_TOKENS=1        or --oauth-refresh-tokens
PANEL_OAUTH_OPTIONAL=1              or --oauth-optionalpanel serve <arguments> ...If you do not specify the.envfile, the production configuration should be the default.
Please file an issue if you see any errors.Setup for developmentEnsure you havecondainstalled.
Then run:makesetupRun the unit testsmaketestRun the unit tests across isolated environments with toxmaketox