Skip to content

Add margin to installation token expiry #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/ff_bot/auth/installation_token_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ defmodule FFBot.Auth.InstallationTokenServer do

# If we did find a token, we look at the expiry date on it
[{install_id, {exp, token}}] ->
# If it expired in the past, create and return a new token
if exp <= DateTime.utc_now() do
Logger.info("Token was expired at lookup time, generating new one",
installation_id: install_id
# If it expires soon (or is already expired), create and return a new token
exp_with_margin = DateTime.add(exp, -10, :second)
if exp_with_mergin <= DateTime.utc_now() do
Logger.info("Token expires at or near lookup time, generating new one",
installation_id: install_id,
expiry: exp
)

token = generate_token(install_id)
Expand Down