diff --git a/.travis.yml b/.travis.yml
index 0e7c860..42ca363 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,10 @@
language: ruby
rvm:
- - 2.4.2
- - 2.3.5
- - 2.2.8
- - 2.1
+ - 2.5.1
+ - 2.4.4
+ - 2.3.7
+ - 2.2.10
+ - 2.1.10
- 2.0.0
- 1.9.3
- jruby-9.1.9.0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7887ca..e185e7e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 0.9.0 (2018-08-16)
+* Add RemoteServerError class for 5xx level errors.
+* Allow to_json to be called with arguments
+* Expires_in now sets and reflects current expires_at value
+* Expires_within(0) now returns false when expires_at is nil.
+
## 0.8.1 (2017-10-13)
* Restore support for Ruby 1.9.3
diff --git a/README.md b/README.md
index 217b9e5..43ea177 100644
--- a/README.md
+++ b/README.md
@@ -7,8 +7,8 @@
LicenseApache 2.0
+[![Gem Version](https://badge.fury.io/rb/signet.svg)](https://badge.fury.io/rb/signet)
[![Build Status](https://secure.travis-ci.org/google/signet.png)](http://travis-ci.org/google/signet)
-[![Dependency Status](https://gemnasium.com/google/signet.png)](https://gemnasium.com/google/signet)
## Description
diff --git a/lib/signet/oauth_2/client.rb b/lib/signet/oauth_2/client.rb
index 1e58ae4..13e57a5 100644
--- a/lib/signet/oauth_2/client.rb
+++ b/lib/signet/oauth_2/client.rb
@@ -95,7 +95,6 @@ def initialize(options={})
@client_secret = nil
@code = nil
@expires_at = nil
- @expires_in = nil
@issued_at = nil
@issuer = nil
@password = nil
@@ -723,32 +722,37 @@ def decoded_id_token(public_key=nil, options = {}, &keyfinder)
##
# Returns the lifetime of the access token in seconds.
+ # Returns nil if the token does not expire.
#
- # @return [Integer] The access token lifetime.
+ # @return [Integer, nil] The access token lifetime.
def expires_in
- return @expires_in
+ if @expires_at.nil? || @issued_at.nil?
+ nil
+ else
+ (@expires_at - @issued_at).to_i
+ end
end
##
- # Sets the lifetime of the access token in seconds. Resets the issued
- # timestamp.
+ # Sets the lifetime of the access token in seconds. Resets the issued_at
+ # timestamp. Nil values will be treated as though the token does
+ # not expire.
#
- # @param [String, Integer] new_expires_in
+ # @param [String, Integer, nil] new_expires_in
# The access token lifetime.
def expires_in=(new_expires_in)
if new_expires_in != nil
- @expires_in = new_expires_in.to_i
@issued_at = Time.now
+ @expires_at = @issued_at + new_expires_in.to_i
else
- @expires_in, @issued_at = nil, nil
+ @expires_at, @issued_at = nil, nil
end
- @expires_at = nil
end
##
# Returns the timestamp the access token was issued at.
#
- # @return [Time] The access token issuance time.
+ # @return [Time, nil] The access token issuance time.
def issued_at
return @issued_at
end
@@ -764,29 +768,26 @@ def issued_at=(new_issued_at)
##
# Returns the timestamp the access token will expire at.
+ # Returns nil if the token does not expire.
#
- # @return [Time] The access token lifetime.
+ # @return [Time, nil] The access token lifetime.
def expires_at
- if @expires_at
- @expires_at
- elsif @issued_at && @expires_in
- return @issued_at + @expires_in
- else
- return nil
- end
+ @expires_at
end
##
# Limits the lifetime of the access token as number of seconds since
- # the Epoch
- # @param [String,Integer,Time] new_expires_at
- # The access token issuance time.
+ # the Epoch. Nil values will be treated as though the token does
+ # not expire.
+ # @param [String,Integer,Time, nil] new_expires_at
+ # The access token expiration time.
def expires_at=(new_expires_at)
- @expires_at = normalize_timestamp(new_expires_at)
+ @expires_at = normalize_timestamp new_expires_at
end
##
# Returns true if the access token has expired.
+ # Returns false if the token has not expired or has an nil @expires_at.
#
# @return [TrueClass, FalseClass]
# The expiration state of the access token.
@@ -796,7 +797,7 @@ def expired?
##
# Returns true if the access token has expired or expires within
- # the next n seconds
+ # the next n seconds. Returns false for tokens with a nil @expires_at.
#
# @param [Integer] sec
# Max number of seconds from now where a token is still considered
@@ -817,7 +818,7 @@ def clear_credentials!
@password = nil
@code = nil
@issued_at = nil
- @expires_in = nil
+ @expires_at = nil
end
@@ -1006,8 +1007,6 @@ def fetch_access_token(options={})
end
def fetch_access_token!(options={})
- options = deep_hash_normalize(options)
-
token_hash = self.fetch_access_token(options)
if token_hash
# No-op for grant types other than `authorization_code`.
@@ -1023,8 +1022,6 @@ def fetch_access_token!(options={})
##
# Refresh the access token, if possible
def refresh!(options={})
- options = deep_hash_normalize(options)
-
self.fetch_access_token!(options)
end
diff --git a/lib/signet/version.rb b/lib/signet/version.rb
index ec03143..6ed1c07 100644
--- a/lib/signet/version.rb
+++ b/lib/signet/version.rb
@@ -17,8 +17,8 @@
module Signet
module VERSION
MAJOR = 0
- MINOR = 8
- TINY = 1
+ MINOR = 9
+ TINY = 0
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
diff --git a/spec/signet/oauth_2/client_spec.rb b/spec/signet/oauth_2/client_spec.rb
index bfd0b8a..35b8966 100644
--- a/spec/signet/oauth_2/client_spec.rb
+++ b/spec/signet/oauth_2/client_spec.rb
@@ -442,9 +442,38 @@ def build_form_encoded_response(payload)
expect(@client).to_not be_expired
end
+ it 'should set expires_in when expires_at is set' do
+ issued_at = Time.now
+ expires_at = Time.now+100
+ @client.expires_at = expires_at.to_i
+ @client.issued_at = issued_at
+ expect(@client.expires_in).to be_within(1).of (expires_at - issued_at).to_i
+ @client.expires_at = nil
+ expect(@client.expires_in).to be_nil
+ end
+
+ it 'should set expires_in to nil when expires_at is set to nil' do
+ @client.expires_at = nil
+ expect(@client.expires_in).to be_nil
+ end
+
+ it 'should set expires_at when expires_in is set' do
+ expires_in = 100
+ @client.expires_in = expires_in
+ expect(@client.expires_at).to eq (@client.issued_at + expires_in)
+ @client.expires_in = nil
+ expect(@client.expires_at).to be_nil
+ end
+
+ it 'should set expires_at to nil when expires_in is set to nil' do
+ @client.expires_in = nil
+ expect(@client.expires_at).to be_nil
+ end
+
it 'should indicate the token is not expired if expired_at nil' do
@client.expires_at = nil
expect(@client.expires_within?(60)).to be false
+ expect(@client.expired?).to be false
end
it 'should indicate the token is not expiring when expiry beyond window' do
@@ -880,7 +909,7 @@ def build_form_encoded_response(payload)
end
it 'should raise an error if the id token cannot be verified' do
- pending "Need to update test data"
+ pending "Need to set test data"
@client.client_id = 'client-12345'
@client.client_secret = 'secret-12345'
stubs = Faraday::Adapter::Test::Stubs.new do |stub|