Skip to main content

OAuthManager

OAuthManager is a Python package for managing API authentication using 1Password Service Accounts and securely caching credentials.

Features

  • Manage API credentials securely via 1Password.
  • Cache API credentials locally using encryption for faster retrieval.
  • Designed to be extensible for any API that requires authentication.

Requirements

  • Python 3.11 or later
  • 1Password Service Account
  • 1Password CLI
  • An environment variable for your 1Password service account token (OP_SERVICE_ACCOUNT_TOKEN).
  • cryptography Python package

Installation

  1. Install Python and Pip

    Ensure you have Python 3.11 installed on your system. You can download it from python.org.

  2. Install the OAuthManager package

    You can install the OAuthManager package directly from PyPI:

    pip install oauthmanager
    

Setting Up 1Password Service Account

1. Create a 1Password Account

To begin, sign up for a 1Password account. You will need to be on a 1Password Teams, Business, or Enterprise plan to create service accounts.

2. Create a 1Password Service Account

A service account allows OAuthManager to securely retrieve your API credentials. Follow the steps below to create one:

Create Service Account via 1Password Website

  1. Sign in to your account on 1Password.com.
  2. Select Developer Tools in the sidebar.
  3. Under Infrastructure Secrets Management, select Other.
  4. Click Create a Service Account and follow the instructions:
    • Choose a name for the service account.
    • Choose whether the service account can create vaults.
    • Choose the vaults that the service account can access (make sure it can access your API vault).
    • Click Create Account.
    • Click Save in 1Password to store your service account token.

⚠️ Important: The service account token is shown only once during the creation process. Save it immediately in your 1Password account.

3. Set Environment Variables

Platform-Specific Instructions

You will need to set two environment variables:

  • OP_SERVICE_ACCOUNT_TOKEN: The service account token created in the previous step.
  • OP_CACHE: Enable caching for faster retrieval.

macOS/Linux

  1. Open your terminal.

  2. Use the following command to open your .bashrc, .bash_profile, or .zshrc (depending on your shell):

    nano ~/.bashrc
    
  3. Add the following lines to export your service account token and enable caching:

    export OP_SERVICE_ACCOUNT_TOKEN="your-service-account-token"
    export OP_CACHE="true"
    
  4. Save the file and run:

    source ~/.bashrc
    

Windows

  1. Open the Command Prompt as Administrator.

  2. Set the environment variables:

    setx OP_SERVICE_ACCOUNT_TOKEN "your-service-account-token"
    setx OP_CACHE "true"
    

    This sets the variables globally. Restart the terminal for them to take effect.

Usage

Once you’ve installed OAuthManager and set up the necessary environment variables, you can start retrieving credentials from 1Password.

Example Code:

from oauthmanager import AuthManager, OnePasswordAuthManager

# Initialize the Auth Manager
auth_manager = OnePasswordAuthManager()

# Retrieve credentials for Spotify
spotify_creds = auth_manager.get_credentials("Spotify", "client_id", "client_secret", "uri")

# Use the credentials
print(f"Client ID: {spotify_creds['client_id']}")
print(f"Client Secret: {spotify_creds['client_secret']}")
print(f"Redirect URI: {spotify_creds['uri']}")

Caching

By default, the OAuthManager caches credentials locally using encryption. To refresh the cache, simply delete the credentials_cache.json file, or let it expire after 24 hours.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for oauthmanager 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oauthmanager 0.1.12
File Size Uploaded
oauthmanager-0.1.12.tar.gz 15.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for oauthmanager 0.1.12
File Interpreter ABI Platform
oauthmanager-0.1.12-py3-none-any.whl Python 3 none any Details

Total release size: 33.8 kB

Release files / oauthmanager-0.1.12.tar.gz

Download URL oauthmanager-0.1.12.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6b7d60f9f7df78d0639d2e5fb498d72b78e900e6bcc548a68ae09c5e1a65ca1e
BLAKE2b-256 checksum
How to use checksums
17e48aedb71d4c01edbacd1519fdb63d81646013532fa9d613eb5cf550bade0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.12.7 Darwin/23.6.0

Release files / oauthmanager-0.1.12-py3-none-any.whl

Download URL oauthmanager-0.1.12-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c7a8707c6c16c2fde200b3826802892d8d14e82d9f54b81b2156bcff4942e03
BLAKE2b-256 checksum
How to use checksums
d357bb5fed657b064ecc48bb323c982c9ccf600ef7686529eff053e2a459ffb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.12.7 Darwin/23.6.0

Release history Release notifications | RSS feed

This release

0.1.12 This release

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page