Python gRPC client library for the BigBucks Auth service
Project description
py-auth-grpc-client
Python gRPC client library for the Auth service. Provides authenticate and authorize RPCs to validate JWTs and check permissions.
Installation
pip install bigbucks-auth-grpc-client
# With FastAPI decorator support
pip install 'bigbucks-auth-grpc-client[fastapi]'
Regenerate gRPC stubs
chmod +x generate_stubs.sh
./generate_stubs.sh
Usage
Standalone client
from auth_grpc_client import AuthGrpcClient
with AuthGrpcClient("localhost:50051") as client:
auth = client.authenticate(token="your-jwt-token")
print(auth.user_id, auth.username, auth.roles)
authz = client.authorize(
token="your-jwt-token",
resource="documents",
scope="org",
action="read",
org_id="org-123",
)
print(authz.result) # True / False
FastAPI decorators
Protect your FastAPI routes with @require_auth and @require_authorization decorators.
Configure the gRPC client once at startup — no need to pass it to each decorator.
from contextlib import asynccontextmanager
from fastapi import FastAPI
from auth_grpc_client import AuthenticateResult, AuthorizeResult
from auth_grpc_client.decorators import configure_auth, close_auth, require_auth, require_authorization
@asynccontextmanager
async def lifespan(app: FastAPI):
configure_auth("localhost:50051")
yield
close_auth()
app = FastAPI(lifespan=lifespan)
# auth is injected only if you declare it
@app.get("/me")
@require_auth
async def get_me(auth: AuthenticateResult):
return {"user_id": auth.user_id, "username": auth.username}
# pure guard — no auth/authz params needed
@app.get("/ping")
@require_auth
async def ping():
return {"ok": True}
# authorization with optional auth/authz injection
@app.get("/orgs/{org_id}/documents")
@require_authorization(resource="documents", scope="org", action="read")
async def list_documents(org_id: str, auth: AuthenticateResult):
return {"org_id": org_id, "user": auth.user_id}
Note: You do not need to declare
request: Request— the decorator handles it automatically. Theauthandauthzparameters are only injected if your handler declares them.
Secure (TLS) connection
client = AuthGrpcClient("auth.example.com:443", secure=True)
Custom credentials
import grpc
creds = grpc.ssl_channel_credentials(
root_certificates=open("ca.pem", "rb").read(),
)
client = AuthGrpcClient("auth.example.com:443", secure=True, credentials=creds)
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
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 bigbucks_auth_grpc_client-0.0.2.tar.gz.
File metadata
- Download URL: bigbucks_auth_grpc_client-0.0.2.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
011f7b32c63b1b7dcc1bad4e1d0cdee6b13c33a64fd5ee6cbbb8737629526ff5
|
|
| MD5 |
f51fe5c1e5d2f6890efc70564c75cc54
|
|
| BLAKE2b-256 |
e37e13494320988a52c764955be614ce5caa16bd219bb8fde49dcd72549cb854
|
Provenance
The following attestation bundles were made for bigbucks_auth_grpc_client-0.0.2.tar.gz:
Publisher:
ci.yml on bigbucks-solutions/py-auth-grpc-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bigbucks_auth_grpc_client-0.0.2.tar.gz -
Subject digest:
011f7b32c63b1b7dcc1bad4e1d0cdee6b13c33a64fd5ee6cbbb8737629526ff5 - Sigstore transparency entry: 1006444356
- Sigstore integration time:
-
Permalink:
bigbucks-solutions/py-auth-grpc-client@86c99583acd2c90fcfbd270e676a883898fd91a7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bigbucks-solutions
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@86c99583acd2c90fcfbd270e676a883898fd91a7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bigbucks_auth_grpc_client-0.0.2-py3-none-any.whl.
File metadata
- Download URL: bigbucks_auth_grpc_client-0.0.2-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5f396b5b42853b63e89cbba7a244ca0db20938114aeb7411819db00c38d7cc1
|
|
| MD5 |
bb15fc7561739b0a5b097952f20d457c
|
|
| BLAKE2b-256 |
40fb1ff5c63b72801ab9e11776fabed867797bbf3ee8c811812b827f11c99b94
|
Provenance
The following attestation bundles were made for bigbucks_auth_grpc_client-0.0.2-py3-none-any.whl:
Publisher:
ci.yml on bigbucks-solutions/py-auth-grpc-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bigbucks_auth_grpc_client-0.0.2-py3-none-any.whl -
Subject digest:
b5f396b5b42853b63e89cbba7a244ca0db20938114aeb7411819db00c38d7cc1 - Sigstore transparency entry: 1006444359
- Sigstore integration time:
-
Permalink:
bigbucks-solutions/py-auth-grpc-client@86c99583acd2c90fcfbd270e676a883898fd91a7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bigbucks-solutions
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@86c99583acd2c90fcfbd270e676a883898fd91a7 -
Trigger Event:
push
-
Statement type: