Skip to main content

OIDC Human Callback for MongoDB: browser-based OAuth 2.0 Authorization Code Flow with PKCE (Azure AD and other OIDC providers).

Project description

mongo-oidc-human-callback

OIDC Human Callback for MongoDB Atlas authentication: OAuth 2.0 Authorization Code flow with PKCE (Azure AD and other OIDC providers).

Single dependency: pymongo (stdlib for the rest: urllib, logging, http.server, etc.).

Installation

pip install mongo-oidc-human-callback

Usage

from pymongo import MongoClient
from mongo_oidc_human_callback import OIDCHumanCallback

# Connect with human callback (browser opens + PKCE)
client = MongoClient(
    "mongodb+srv://<cluster>.mongodb.net/",
    authMechanism="MONGODB-OIDC",
    authMechanismProperties={"OIDC_CALLBACK": OIDCHumanCallback()},
)
# First access: browser opens to sign in (e.g. Azure AD)
client.admin.command("ping")

Callback options

OIDCHumanCallback(
    redirect_path="redirect",  # or "callback" depending on Azure AD config
    port=27097,                # local callback server port
)

Features

  • PKCE (Proof Key for Code Exchange)
  • Token caching to avoid re-authenticating on each connection
  • Local HTTP server to receive the OAuth redirect
  • Automatic browser opening
  • Azure AD compatibility (endpoints /oauth2/v2.0/authorize and /oauth2/v2.0/token)

Azure AD configuration

In the Azure portal, for your app registration:

  1. Authentication → Redirect URI: http://localhost:27097/redirect (or the port/redirect_path you use).
  2. API permissions → Microsoft Graph (or target API): e.g. openid, profile, email.

Publishing (PyPI)

Via GitHub Actions

The .github/workflows/publish-pypi.yml workflow publishes to PyPI:

  • On each release: create a release (tag) on GitHub → the workflow runs.
  • On demand: Actions → Publish to PyPI → Run workflow.

PyPI setup (trusted publishing, no secrets):

  1. PyPI → your project → PublishingAdd a new trusted publisher.
  2. Enter exactly (as on GitHub):
    • Owner: mreouven (your GitHub username, not display name)
    • Repository: mongo-oidc-human-callback
    • Workflow: publish-pypi.yml
  3. Save. Future workflow runs will publish without PYPI_API_TOKEN.

If you get invalid-publisher, ensure Owner is the GitHub username of the repo (e.g. mreouven), not the org or display name.

Alternative (API token): add the PYPI_API_TOKEN secret in the repo (Settings → Secrets) and use a workflow that sets TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} if you prefer not to use trusted publishing.

From your machine

pip install build twine
python -m build
twine upload dist/*

License

MIT

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

mongo_oidc_human_callback-0.1.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

mongo_oidc_human_callback-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file mongo_oidc_human_callback-0.1.0.tar.gz.

File metadata

  • Download URL: mongo_oidc_human_callback-0.1.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mongo_oidc_human_callback-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1e6bf0c7ac313797153e219185013f3f29df8eef2d6ea200752b0985e04b1a2f
MD5 9db864e5ee26fa57dbaa0fa2a462c6d5
BLAKE2b-256 351994004ccc7f26b8545c1f452f58784d04e8b12f82c5198dde75c3f5814e83

See more details on using hashes here.

File details

Details for the file mongo_oidc_human_callback-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mongo_oidc_human_callback-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mongo_oidc_human_callback-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 149f78851d8e4b5e5b40de7e8521a530603f309dc6a249bfc0f16fcf8096c09b
MD5 2e914544c8c8d3dfd63f1b8b1945432b
BLAKE2b-256 a689a88ab6dae9ed0313204f6e11bdf12304349aaa287dabaee6d050e44f1ebc

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