New to Kestra?
Use blueprints to kickstart your first workflows.
Refresh YouTube OAuth2 access tokens with Kestra. Exchange a refresh token monthly, store the token in KV, and report expiry details to Slack.
Google access tokens expire after roughly an hour, and every YouTube reporting flow that carries a hardcoded token is a countdown to a 401. This blueprint makes rotation a first-class flow: io.kestra.plugin.youtube.OAuth2 exchanges the long-lived refresh token for a fresh access token, the token lands in the namespace KV store where every other YouTube flow can read it, and Slack receives the expiry metadata so the team knows the credential chain is healthy.
refresh_access_token (io.kestra.plugin.youtube.OAuth2) posts the client ID, client secret, and refresh token to Google's token endpoint and outputs accessToken, expiresAt, expiresIn, scope, and tokenType.store_token writes the fresh token into the namespace KV store under YOUTUBE_ACCESS_TOKEN. Downstream flows read it with {{ kv('YOUTUBE_ACCESS_TOKEN') }} and always see the latest value.notify posts the token type, lifetime, expiry timestamp, and granted scope to Slack. The access token itself is never interpolated into the message.errors block raises a distinct Slack alert when the exchange fails, which usually means the refresh token was revoked or the client credentials were rotated.Schedule trigger runs the flow on the first of every month as a credential health check; run it more often, or call it as a subflow, when downstream flows need a token that is always live.Token refresh is a small HTTP call with large blast radius when it stops working. Kestra gives the call a schedule, an execution history that shows exactly when each rotation happened, a KV store to hand the result to other flows, and an alert path for the day Google revokes the grant. The rotation becomes infrastructure instead of tribal knowledge.
YOUTUBE_CLIENT_ID: OAuth2 client ID from the Google Cloud console.YOUTUBE_CLIENT_SECRET: OAuth2 client secret from the Google Cloud console.YOUTUBE_REFRESH_TOKEN: refresh token obtained during the initial authorization flow.SLACK_WEBHOOK_URL: Slack incoming webhook URL.{{ kv('YOUTUBE_ACCESS_TOKEN') }}.disabled: false on the monthly trigger.If task on expiresIn to alert when Google starts returning unusually short lifetimes.