Skip to content

Commit 77f407d

Browse files
committed
fix: fix expired? method when expires_in is 0
1 parent 3770315 commit 77f407d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/oauth2/access_token.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def initialize(client, token, opts = {})
8181
@expires_in &&= @expires_in.to_i
8282
@expires_at &&= convert_expires_at(@expires_at)
8383
@expires_latency &&= @expires_latency.to_i
84-
@expires_at ||= Time.now.to_i + @expires_in if @expires_in
84+
@expires_at ||= Time.now.to_i + @expires_in if @expires_in && !@expires_in.zero?
8585
@expires_at -= @expires_latency if @expires_latency
8686
@options = {mode: opts.delete(:mode) || :header,
8787
header_format: opts.delete(:header_format) || 'Bearer %s',

spec/oauth2/access_token_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ def assert_initialized_token(target)
615615
expect(described_class.new(client, token)).not_to be_expired
616616
end
617617

618+
it 'is false if expires_in is 0 (token is permanent)' do
619+
expect(described_class.new(client, token, refresh_token: 'abaca', expires_in: 0)).not_to be_expired
620+
end
621+
618622
it 'is false if expires_in is in the future' do
619623
expect(described_class.new(client, token, refresh_token: 'abaca', expires_in: 10_800)).not_to be_expired
620624
end

0 commit comments

Comments
 (0)