Skip to content

[DEV] Implement LinkedInTokenRefresherFunction (timer trigger) #58

@artcava

Description

@artcava

Overview

Implement a new Azure Function LinkedInTokenRefresherFunction with a TimerTrigger that runs on the 1st of every month at 09:00 AM and automatically refreshes the LinkedIn access token via ILinkedInAuthService, writing the new token back to Key Vault.

Depends on: #56 #57

Tasks

  • Create src/Functions/LinkedInTokenRefresherFunction.cs:
[Function("LinkedInTokenRefresher")]
public async Task Run(
    [TimerTrigger("%LinkedInTokenRefreshSchedule%")] TimerInfo timer,
    ILogger<LinkedInTokenRefresherFunction> logger)
{
    logger.LogInformation("Starting LinkedIn token refresh...");
    var refreshToken = await _keyVaultService.GetSecretAsync("LinkedInRefreshToken");
    var (newAccessToken, newRefreshToken) = await _linkedInAuthService.RefreshTokenAsync(refreshToken);
    await _keyVaultService.SetSecretAsync("LinkedInAccessToken", newAccessToken);
    if (!string.IsNullOrEmpty(newRefreshToken))
        await _keyVaultService.SetSecretAsync("LinkedInRefreshToken", newRefreshToken);
    logger.LogInformation("LinkedIn token refreshed successfully.");
}
  • Add App Setting LinkedInTokenRefreshSchedule = 0 0 9 1 * * (day 1 of every month at 09:00)
  • Register dependencies in Program.cs
  • Update src/local.settings.json.example with LinkedInTokenRefreshSchedule
  • Write unit tests

Acceptance Criteria

  • Function triggers correctly on the 1st of the month
  • On success: LinkedInAccessToken secret in Key Vault is updated with new value
  • On failure: exception is logged with severityLevel >= 3 (triggers alert from [DEV] Implement LinkedInTokenRefresherFunction (timer trigger) #58)
  • Idempotent: running twice in a row does not break the token state

Notes

  • Schedule 0 0 9 1 * * = every 1st of the month at 09:00 AM — well within the 60-day expiry window
  • Use %LinkedInTokenRefreshSchedule% (env var binding) to allow schedule override without redeploy

References

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions