feat(sms): add selectable provider strategy

This commit is contained in:
2026-07-14 09:45:40 +03:30
parent 2264b7fc95
commit e382c4f93a
10 changed files with 171 additions and 12 deletions

View File

@@ -1,11 +1,11 @@
# Gapido Backend Code Challenge
Python gRPC OTP authentication service with MongoDB, Redis, RabbitMQ, and a Kavenegar SMS adapter.
Python gRPC OTP authentication service with MongoDB, Redis, RabbitMQ, and selectable SMS providers.
## Architecture
- `auth-service`: async `grpc.aio` API for OTP login, token refresh, token revocation, and RBAC demo methods.
- `sms-worker`: RabbitMQ consumer that sends OTP messages through Kavenegar.
- `sms-worker`: RabbitMQ consumer that sends OTP messages through the configured SMS provider.
- MongoDB stores users and refresh-token sessions.
- Redis stores OTP hashes, TTL, verification attempts, and OTP request rate limits.
- RabbitMQ decouples authentication from SMS delivery.
@@ -19,6 +19,19 @@ docker compose up --build
The gRPC service listens on `localhost:50051`. RabbitMQ management is available at `http://localhost:15672` with `guest` / `guest`.
## SMS Provider
The SMS integration uses the Strategy pattern behind the `SmsClient` port. Select the provider with:
```env
SMS_PROVIDER=kavenegar
```
Supported values:
- `kavenegar`: uses `KAVENEGAR_API_KEY` and `KAVENEGAR_LOGIN_TEMPLATE`.
- `sms_ir`: uses `SMS_IR_API_KEY` and `SMS_IR_VERIFY_TEMPLATE_ID`.
## Local Development
```bash
@@ -50,5 +63,4 @@ authorization: Bearer <access_token>
- OTP requests are rate-limited per mobile number and client identity.
- Refresh tokens are opaque random values; only SHA-256 hashes are persisted.
- Refresh tokens rotate on use.
- Kavenegar is hidden behind an adapter and mocked in tests.
- SMS providers are hidden behind adapters and mocked in tests.