Skip to main content

OAuth 2.0 Authorization Code connector for the Model Context Standard.

Project description

mcs-auth-oauth

OAuth 2.0 for AI agents. Authorization Code Flow with PKCE connector for the Model Context Standard (MCS).

A 5-second localhost callback server and your agent has an OAuth token. Works with any OAuth 2.0 provider -- Google, Auth0, Microsoft, GitHub, you name it.

Installation

pip install mcs-auth-oauth

Quick start

from mcs.auth.oauth import OAuthProvider

provider = OAuthProvider(
    authorize_url="https://accounts.google.com/o/oauth2/v2/auth",
    token_url="https://oauth2.googleapis.com/token",
    client_id="...",
    client_secret="...",
    scopes={"gmail": "https://mail.google.com/"},
)

# Opens browser, user logs in, token returned
token = provider.get_token("gmail")

How it works

  1. Agent calls get_token("gmail")
  2. Browser opens with the provider's consent screen
  3. User logs in and grants access
  4. Localhost callback receives the authorization code
  5. Code is exchanged for tokens (with PKCE)
  6. Token returned to agent -- done

The entire flow happens in a single get_token() call. The localhost server lives for exactly one request and shuts down immediately.

Use with Auth0 Token Vault

from mcs.auth.auth0 import Auth0Provider
from mcs.auth.oauth import OAuthConnector

provider = Auth0Provider(
    domain="my-tenant.auth0.com",
    client_id="...",
    client_secret="...",
    _auth=OAuthConnector(
        authorize_url="https://my-tenant.auth0.com/authorize",
        token_url="https://my-tenant.auth0.com/oauth/token",
        client_id="...",
        client_secret="...",
        extra_params={"connection": "google-oauth2", "audience": "..."},
    ),
)

Links

License

Apache-2.0

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

mcs_auth_oauth-0.3.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcs_auth_oauth-0.3.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file mcs_auth_oauth-0.3.0.tar.gz.

File metadata

  • Download URL: mcs_auth_oauth-0.3.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for mcs_auth_oauth-0.3.0.tar.gz
Algorithm Hash digest
SHA256 62eb320a6e43e9c39a138b39a0e6f3811e1fa9a9c5135ee1caf2933c8ca2864a
MD5 7651b49a2ec0aa480ad50e383e1aeaf6
BLAKE2b-256 82b62b2830a7e9a5f83dfd341fb5a22bf72c0a13342ff6b687792dbaaf5f596d

See more details on using hashes here.

File details

Details for the file mcs_auth_oauth-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mcs_auth_oauth-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for mcs_auth_oauth-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 daba1cb19f2f14dd96d7f712574decf98f762ee6f403faadb8ef83d20f2323c2
MD5 9f73e54bcd0cdfb544c320c1a845d4ed
BLAKE2b-256 2d5cb789989c30538e08e33bc1a189a4f58cf10a0c97be0515b9758b178b77be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page