IAV-1027/feat(meta): add Instagram Professional API token auto-refresh pipeline
Summary
Introduces a fully automated refresh pipeline for Instagram Professional API long-lived access tokens (60-day TTL), preventing credential expiry from silently breaking connected social integrations.
Changes
Infrastructure
-
PlatformApiProperties— externalized HTTP timeout configuration via@ConfigurationProperties(prefix = "iavia.platforms"). -
RestTemplateConfig— configures a@PrimaryRestTemplateusing Apache HttpClient 5 with explicit connect / response / connection-request timeouts.
Core Refresh Flow (MetaTokenRefreshService)
- Decrypt stored credential data and extract the raw bearer token.
- Call
GET graph.instagram.com/refresh_access_token(no client secret required). - Validate the response; fall back to a 60-day TTL if
expires_inis absent. -
persistNewToken(@Transactional(REQUIRES_NEW)) — commits the new encrypted token and expiry to DB before any N8N call. This guarantees the source-of-truth is always consistent regardless of downstream propagation outcome. -
propagateToN8nInstances— updates each linked N8N credential instance; failures are isolated per-instance and do not affect others or roll back the DB.
Scheduling (MetaTokenRefreshScheduler)
- Cron
0 0 3 * * *— runs daily at 03:00. - 15-day refresh window: provides 14 retry attempts before a 60-day token expires.
Repository additions
-
CredentialRepository#findExpiringCredentials— JPQL text-block query filtering by type list and expiry threshold. -
CredentialInstanceRepository#findAllByCredential— bulk lookup of N8N instances by parent credential.
Related Issues
Closes IAV-1027