Skip to main content

A tool to verify OIDC tokens

Project description

verify-oidc-token

Python tool for verifying OpenID Connect (OIDC) tokens.

Installation

Install via PyPI:

pip install verify-oidc-token

Or, install from the source repository:

git clone https://github.com/ei-grad/verify-oidc-token
cd verify-oidc-token

# Optionally, create a virtual environment:
python3 -m venv venv
source venv/bin/activate  # Linux/MacOS
# venv\Scripts\activate  # Windows

pip install .

CLI Usage

Verify an OIDC token directly from the command line. Example:

echo "<OIDC_TOKEN>" | verify-oidc-token --issuer https://example-issuer.com --client-id <CLIENT_ID>

Or, specify a file with the token:

verify-oidc-token --token-file /path/to/token.txt --issuer https://example-issuer.com --client-id <CLIENT_ID>

CLI Options:

  • --token-file : The file containing the OIDC token (can be omitted if passed via stdin).
  • --issuer : The expected issuer of the token (authorization server).
  • --client-id : The expected client ID (audience) of the token.
  • --verbose: Enable verbose logging for debugging purposes.

Example:

verify-oidc-token --token-file token.txt --issuer https://accounts.google.com --client-id my-client-id

Example Output:

For a valid token:

{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022,
  ...
}

For an invalid token:

{
  "error": "Invalid issuer. Expected 'https://example-issuer.com', got 'https://wrong-issuer.com'"
}

Output Format:

  • Valid tokens return decoded claims as a JSON object.

  • If validation fails, an error message is returned as JSON:

    {
      "error": "Description of the validation error"
    }
    

Library Usage

Use this tool as a library in Python code:

from verify_oidc_token import verify_token
import jwt

token = "eyJhbGciOiJSUzI1NiIsInR5..."
issuer = "https://accounts.google.com"
client_id = "my-client-id"

try:
    claims = verify_token(token, issuer, client_id)
    print("Token is valid. Claims:", claims)
except jwt.InvalidTokenError as e:
    print({"error": str(e)})

Library API:

  • verify_token(token: str, issuer: str, client_id: str) -> dict Verifies the token, ensuring it matches the specified issuer and client ID, and returns the claims if valid.

    • Parameters:
      • token (str): The JWT to verify.
      • issuer (str): Expected issuer of the token.
      • client_id (str): Expected client ID (audience).
    • Returns: Dictionary with the decoded claims.
    • Raises: jwt.InvalidTokenError if validation fails.

Testing

Run unit tests to ensure functionality:

python -m unittest discover tests

License

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

Author

Andrew Grigorev (andrew@ei-grad.ru)

Reach out with any questions or contribute to the project via the GitHub repository.

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

verify_oidc_token-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

verify_oidc_token-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: verify_oidc_token-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for verify_oidc_token-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b44dd51c37653b8e8b751918a7bfa83dec42903cbcf11f097785722f9c0a15f1
MD5 4b2e03a56305a417c1c773729b3a8d83
BLAKE2b-256 f37013eab2c2dac8347b1fca7c89fc4a515acef0dc090a4a7e098151680380f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for verify_oidc_token-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 840b83fefd5d4c713332862ea9c7e60233e37735a9f496e4798bca951d1b60ca
MD5 01a78084af91a62d04d71926779fb265
BLAKE2b-256 0689e0fb961dd72cb44ef5b37c8aa76c59dd30f949bd5878414e79220849f79f

See more details on using hashes here.

Supported by

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