provider-auth-service — Central Provider OAuth2 Token Minter
By Engineering Team•October 2, 2026•4 min read
Responsibility
provider-auth-service is the single place that logs into a third-party provider’s API and caches the resulting token, so no consuming service has to mint or independently cache its own copy of a provider credential.
GetToken(provider_name, caller_service_name)— returns a cached, still-valid token for the named provider, or performs a fresh login if none is cached or the cached one is withinTOKEN_SAFETY_MARGIN_SECONDS(60s) of expiry.- Strategy pattern per provider —
service/providerauth/strategy/holds one<provider>_strategy.rsfile per integrated provider behind a sharedprovider_strategy.rstrait and aregistry.rslookup; onboarding a second provider adds a new strategy file, never a growingmatchinside existing logic. Shiprocket is the first integrated provider. - Cache-miss single-flight locking — a
tokio::sync::Mutex<()>serializes concurrent callers racing a cache miss for the same provider, so only one upstream login call is made per expiry; other callers wait on and reuse its result. This locking is single-instance-only — it does not coordinate across replicas. - Deliberately not tenant-scoped —
provider_auth_config(login endpoint/token type/TTL per provider) andprovider_auth_cache(the cached token) hold notenant_idcolumn, since the same provider credentials are shared across every tenant calling through this service. - gRPC-only, no HTTP surface.
Tech Stack
| Concern | Choice |
|---|---|
| Language | Rust |
| gRPC | tonic server only — no outbound REST/HTTP surface exposed |
| Data store | MongoDB — provider_auth_config, provider_auth_cache |
| Template | @templates/rust-postgres-microservice pattern adapted for MongoDB (no dedicated Mongo Rust template exists yet in this monorepo) |
Ports
| Gateway | gRPC (host → container) | Service Name |
|---|---|---|
| — (internal only, no HTTP/Nginx route) | 50062 → 50053 |
provider-auth-service |
Real Consumers
| Consumer | Language | Usage |
|---|---|---|
shipment-service |
Go | repository/providerauth/ — a gRPC client calling GetToken("shiprocket", "shipment-service") before every repository/shiprocket/ call. |
Implementation Notes
- Moving token minting out of
shipment-serviceand into this dedicated service means a second future consumer of Shiprocket (or any other provider this service already knows about) reuses the same cached token and login flow instead of each consumer independently logging in and caching its own copy — see ADR-00022 for why an aggregator-style provider was chosen for fulfillment in the first place, which is what this service authenticates against today. provider_auth_config/provider_auth_cachebeing deliberately non-tenant-scoped is a real divergence from this monorepo’s otherwise-universal multi-tenancy rule (the platform’s layered architecture standard) — justified here because the credential being cached belongs to the platform’s own relationship with the provider, not to any one tenant’s data.- In local development, this service’s own Shiprocket login call can be redirected at mock-service via a seeded
SHIPROCKET_LOGIN_ENDPOINT_OVERRIDE, so a full fulfillment flow can be exercised without a real Shiprocket login.
Architecture overview: Architecture: Multi-Courier Fulfillment via Shiprocket.