Skip to content

Commit 3d80798

Browse files
committed
Handle nil expiration_time_millis
`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.
1 parent a59a1df commit 3d80798

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/googleauth/user_authorizer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def get_credentials user_id, scope = nil
156156
scope: data["scope"] || @scope,
157157
access_token: data["access_token"],
158158
refresh_token: data["refresh_token"],
159-
expires_at: data.fetch("expiration_time_millis", 0) / 1000
159+
expires_at: (data.fetch("expiration_time_millis") || 0) / 1000
160160
)
161161
scope ||= @scope
162162
return monitor_credentials user_id, credentials if credentials.includes_scope? scope

0 commit comments

Comments
 (0)