feat(zarinhub): automate access token refresh
This commit is contained in:
10
README.md
10
README.md
@@ -16,7 +16,7 @@ The HTTP handler coordinates the public API contract and audit persistence. The
|
||||
|
||||
- Go 1.27 or later
|
||||
- Node.js 22 or later
|
||||
- A valid ZarinHub access token
|
||||
- ZarinHub API credentials
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -26,11 +26,13 @@ Copy the example environment file from the project root:
|
||||
Copy-Item .env.sample .env
|
||||
```
|
||||
|
||||
Set `ZARINHUB_ACCESS_TOKEN` in the new `.env` file. This file is ignored by Git.
|
||||
Set `ZARINHUB_API_USERNAME` and `ZARINHUB_API_PASSWORD` in the new `.env` file. These are the API credentials created in the ZarinHub panel, not the regular panel login credentials. The `.env` file is ignored by Git.
|
||||
|
||||
| Variable | Default | Purpose |
|
||||
| --- | --- | --- |
|
||||
| `ZARINHUB_ACCESS_TOKEN` | None; required | ZarinHub access token |
|
||||
| `ZARINHUB_API_USERNAME` | None; required | API username created in the ZarinHub panel |
|
||||
| `ZARINHUB_API_PASSWORD` | None; required | API password created in the ZarinHub panel |
|
||||
| `ZARINHUB_AUTH_ENDPOINT` | Official GetToken endpoint | Token acquisition and refresh endpoint |
|
||||
| `ZARINHUB_ENDPOINT` | Official CardToIban endpoint | External service endpoint |
|
||||
| `ZARINHUB_TIMEOUT` | `5s` | External request timeout |
|
||||
| `DATABASE_PATH` | `./card-to-iban.db` | SQLite database file path |
|
||||
@@ -43,6 +45,8 @@ The frontend reads the following value from `frontend/.env` and uses the shown a
|
||||
NUXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8080
|
||||
```
|
||||
|
||||
The backend obtains an access token during startup, keeps the access and refresh tokens in memory, and refreshes them automatically shortly before expiration. Credentials and tokens are never written to the database or logs.
|
||||
|
||||
## Running the Project
|
||||
|
||||
Start the backend from the Go module directory. The root `.env` file is loaded automatically, and the database migration runs during startup:
|
||||
|
||||
Reference in New Issue
Block a user