verify-oidc-token
Python tool for verifying OpenID Connect (OIDC) tokens.
Notice
Please note that the current implementation may not fully comply with the related RFC for verifying OIDC tokens. Additional checks and validations might be necessary for complete compliance. Users are advised to review the implementation and make any necessary adjustments to ensure it meets their specific requirements and security standards.
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). Required unless--unsafeis given; an empty value counts as missing.--client-id: The expected client ID (audience) of the token. Required unless--unsafeis given; an empty value counts as missing.--unsafe: Allow a missing--issuer/--client-idto be taken from the unverified token payload. The corresponding check becomes self-referential: the token is verified against whatever issuer/audience it claims itself. Debugging only.--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"
}
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, client_id) -> dictVerifies 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 orUNSAFE_FROM_TOKEN): Expected issuer of the token.client_id(str orUNSAFE_FROM_TOKEN): Expected client ID (audience).
- Returns: Dictionary with the decoded claims.
- Raises:
jwt.InvalidTokenErrorif validation fails,TypeErrorifissuerorclient_idis neither a string norUNSAFE_FROM_TOKEN.
Both
issuerandclient_idare required. Passing theUNSAFE_FROM_TOKENsentinel (importable fromverify_oidc_token) opts into deriving the value from the unverified token payload — this makes the corresponding check self-referential and should only be used for debugging, or when the caller applies its own trust decision to the returned claims. - Parameters:
Development
The project is managed with uv. Run the tests:
uv run -m pytest
Linters and type checking (installed as the dev dependency group):
uv run flake8 src tests
uv run black --check src tests
uv run isort --check-only src tests
uv run mypy src
Use tox to run the tests against all supported Python versions.
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file verify_oidc_token-0.3.0.tar.gz.
File metadata
- Download URL: verify_oidc_token-0.3.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e45d8cffc81f38c618fdd9645b8a1b739f700b1cc3aff27f9fa53131691a579
|
|
| MD5 |
ffc419407ebe99a67464916536a91d28
|
|
| BLAKE2b-256 |
fd5d2482c221ede7479715b320d3d25a046ef5870c50ee0ce98590cc67611ac9
|
Provenance
The following attestation bundles were made for verify_oidc_token-0.3.0.tar.gz:
Publisher:
release.yml on ei-grad/verify-oidc-token
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
verify_oidc_token-0.3.0.tar.gz -
Subject digest:
3e45d8cffc81f38c618fdd9645b8a1b739f700b1cc3aff27f9fa53131691a579 - Sigstore transparency entry: 2107191864
- Sigstore integration time:
-
Permalink:
ei-grad/verify-oidc-token@cc30a38f3e5b38416c50736cee20ea542b36a8c5 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/ei-grad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cc30a38f3e5b38416c50736cee20ea542b36a8c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file verify_oidc_token-0.3.0-py3-none-any.whl.
File metadata
- Download URL: verify_oidc_token-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e7aa964b825db92cf9a40329f1e2ecda0efcf7b8dde0e47457c479a0c44bd95
|
|
| MD5 |
dcc73d39f53e4ada666d66dabc5490d0
|
|
| BLAKE2b-256 |
88f28939b8b70972dfedfcda9261d03a6309f5862f0f1fd09a1d97b0dd96f073
|
Provenance
The following attestation bundles were made for verify_oidc_token-0.3.0-py3-none-any.whl:
Publisher:
release.yml on ei-grad/verify-oidc-token
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
verify_oidc_token-0.3.0-py3-none-any.whl -
Subject digest:
7e7aa964b825db92cf9a40329f1e2ecda0efcf7b8dde0e47457c479a0c44bd95 - Sigstore transparency entry: 2107192017
- Sigstore integration time:
-
Permalink:
ei-grad/verify-oidc-token@cc30a38f3e5b38416c50736cee20ea542b36a8c5 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/ei-grad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cc30a38f3e5b38416c50736cee20ea542b36a8c5 -
Trigger Event:
push
-
Statement type: