Skip to main content

Google Wallet webhook signature verification utilities for Python.

Project description

google-wallet-webhook-auth

Google Wallet webhook signature verification utilities for Python.

Features

  • Verify Google Wallet webhook signatures according to official documentation
  • Utilities for handling Google Pay cryptographic signature formats
  • Typed and tested Python code

Installation

pip install google-wallet-webhook-auth

Usage

An example with flask :

from flask import Flask, request, jsonify, abort
from google_wallet_webhook_auth import Validator
from google_wallet_webhook_auth.exceptions import SignatureVerificationError


app = Flask(__name__)

@app.route("/webhook/google/events", methods=['POST'])
def event_webhook():
    data = request.get_json()
    try:
        Validator("YOUR_ISSUER_ID").validate(data)
    except SignatureVerificationError:
        abort(401)

if __name__ == '__main__':
    app.run(debug=True)

Usage with cache and django

from rest_framework import permissions
from django.core.cache import cache

from google_wallet_webhook_auth import Validator
from google_wallet_webhook_auth.exceptions import SignatureVerificationError
from google_wallet_webhook_auth.cache import CacheConfig, CacheInterface

class DjangoCacheAdapter(CacheInterface):
    def get(self, key):
        return cache.get(key)

    def set(self, key, value, timeout=None):
        cache.set(key, value, timeout=timeout)

class IsGoogleWebhook(permissions.BasePermission):
    def has_permission(self, request, __view):
        cache_config = CacheConfig(key="google_key", backend=DjangoCacheAdapter())
        try:
            Validator("YOUR_ISSUER_ID", cache_config=cache_config).validate(request.data)
        except SignatureVerificationError:
            return False
        return True

Development

  • Install deps: uv sync --all-extras
  • Run tests: uv run pytest
  • Lint and format: pre-commit run --all-files
  • Before commit: pre-commit install

License

This project is licensed under the GPL-3.0-or-later. See LICENSE for details.

Made with ❤️

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

google_wallet_webhook_auth-1.0.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

google_wallet_webhook_auth-1.0.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file google_wallet_webhook_auth-1.0.0.tar.gz.

File metadata

File hashes

Hashes for google_wallet_webhook_auth-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1dad44801073b585dd4b01b3dec3a5b8b958a6ebee93aa5eb97c932e82144c26
MD5 03d32206941184bbde876d12933ca86b
BLAKE2b-256 08d026d6dc96b8451f67d00f8a4c637f646d71503c8c04f29f9175d87933d1cb

See more details on using hashes here.

File details

Details for the file google_wallet_webhook_auth-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for google_wallet_webhook_auth-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6655bed8eb0c0c69e388334cf6c562f0d947e9dbe704c99aee50212d57a2c1ae
MD5 c35fd983f963786f15f201d5e788ebb8
BLAKE2b-256 e0af84ff4638511e4ac9385028d78cf5bea0b62ce6762058e7cba4a7142727e6

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