From 3f1709d28e226f4926c04f88d6ff76de7c4f3138 Mon Sep 17 00:00:00 2001 From: Sam Partington Date: Wed, 3 Dec 2025 12:34:42 +0000 Subject: [PATCH] Fix: Don't raise an error if `expiration_time_millis` is nil; fall back to 0 `data.fetch("expiration_time_millis", 0)` will default to 0 only if the key is not present. If the key is present but the associated value is nil, then prior to this change the code would raise as follows: ``` NoMethodError (undefined method `/' for nil:NilClass expires_at: data.fetch("expiration_time_millis", 0) / 1000 ^): ``` This commit updates the code to default to 0 if the key is not found or if the value is nil. With the existing token stores, this situation may not arise, but it's a particular issue when using a custom token store where values could be nil, like a database. --- lib/googleauth/user_authorizer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/googleauth/user_authorizer.rb b/lib/googleauth/user_authorizer.rb index feb9b507..d99ae536 100644 --- a/lib/googleauth/user_authorizer.rb +++ b/lib/googleauth/user_authorizer.rb @@ -156,7 +156,7 @@ def get_credentials user_id, scope = nil scope: data["scope"] || @scope, access_token: data["access_token"], refresh_token: data["refresh_token"], - expires_at: data.fetch("expiration_time_millis", 0) / 1000 + expires_at: (data.fetch("expiration_time_millis") || 0) / 1000 ) scope ||= @scope return monitor_credentials user_id, credentials if credentials.includes_scope? scope