feat(zarinhub): automate access token refresh
This commit is contained in:
@@ -38,6 +38,24 @@ func run(logger *slog.Logger) error {
|
||||
return fmt.Errorf("load configuration: %w", err)
|
||||
}
|
||||
|
||||
httpClient := &http.Client{Timeout: config.ZarinHubTimeout}
|
||||
tokenManager := zarinhub.NewTokenManager(
|
||||
httpClient,
|
||||
config.ZarinHubAuthEndpoint,
|
||||
config.ZarinHubUsername,
|
||||
config.ZarinHubPassword,
|
||||
)
|
||||
|
||||
authContext, cancelAuth := context.WithTimeout(
|
||||
context.Background(),
|
||||
config.ZarinHubTimeout,
|
||||
)
|
||||
_, err = tokenManager.AccessToken(authContext)
|
||||
cancelAuth()
|
||||
if err != nil {
|
||||
return fmt.Errorf("authenticate with zarinhub: %w", err)
|
||||
}
|
||||
|
||||
db, err := storage.OpenSQLite(config.DatabasePath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -58,9 +76,9 @@ func run(logger *slog.Logger) error {
|
||||
}
|
||||
|
||||
zarinHubClient := zarinhub.NewClient(
|
||||
&http.Client{Timeout: config.ZarinHubTimeout},
|
||||
httpClient,
|
||||
config.ZarinHubEndpoint,
|
||||
config.ZarinHubToken,
|
||||
tokenManager,
|
||||
)
|
||||
cardService := service.NewCardService(zarinHubClient)
|
||||
auditRepository := repository.NewAuditRepository(db)
|
||||
|
||||
Reference in New Issue
Block a user