oauth2-aptible 0.9.5 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6b1926148110d013c74ebf7d9ecbc0fd41d00bb
4
- data.tar.gz: 5ba394061da8dbeca872b4678f76f7de8167fe8e
3
+ metadata.gz: c846a8652ef877ec30ecf1c39d791dafa4426ee8
4
+ data.tar.gz: 60ad59f81d91f0940029ecf6b4b0ab96989af3cf
5
5
  SHA512:
6
- metadata.gz: 61335618b62de6ce94a1bd14dfd1d74b11124bfd7a447c3bee6e4e54346e7c62b4fffe56bf5c31c26a71833ef18369b70b3698c075d08c8f01ac847c94d417a2
7
- data.tar.gz: 28f32435318e5b48a0d47c5bd6836e3d2a930e06926c3050e153bb1b24c7e07af152cf2f0cc55cc4aa7ac488c070a0147c840b78d88dbe46e19c75a5eee8b3b3
6
+ metadata.gz: 613be9e21be059631092e7a8da50399243a67ab35563cb0948abfb4e15ea9f0d4d0bb4cf9aebafccb41177366a4236759592c87aa16c05370360f1914a5b2dac
7
+ data.tar.gz: 0a595db7f64a61c2a5090ab445ca4fc21bac691ea54e4b783ae13beaa99ccd95a1621f4eb8d3dcea33f003f462d1f00361ef23721fc40719a7c2af68d1cef2f0
@@ -1,3 +1,5 @@
1
+ require 'time'
2
+
1
3
  module OAuth2
2
4
  class AccessToken
3
5
  attr_reader :client, :token, :expires_in, :expires_at, :params
@@ -30,7 +32,7 @@ module OAuth2
30
32
  # @param [Hash] opts the options to create the Access Token with
31
33
  # @option opts [String] :refresh_token (nil) the refresh_token value
32
34
  # @option opts [FixNum, String] :expires_in (nil) the number of seconds in which the AccessToken will expire
33
- # @option opts [FixNum, String] :expires_at (nil) the epoch time in seconds in which AccessToken will expire
35
+ # @option opts [FixNum, String] :expires_at (nil) the time (epoch time in seconds or iso8601-formatted date) when the token will expire
34
36
  # @option opts [Symbol] :mode (:header) the transmission mode of the Access Token parameter value
35
37
  # one of :header, :body or :query
36
38
  # @option opts [String] :header_format ('Bearer %s') the string format to use for the Authorization header
@@ -44,8 +46,16 @@ module OAuth2
44
46
  end
45
47
  @expires_in ||= opts.delete('expires')
46
48
  @expires_in &&= @expires_in.to_i
47
- @expires_at &&= @expires_at.to_i
48
- @expires_at ||= Time.now.to_i + @expires_in if @expires_in
49
+ @expires_at &&= begin
50
+ Time.iso8601(@expires_at)
51
+ rescue ArgumentError, TypeError
52
+ begin
53
+ Time.at(Integer(@expires_at))
54
+ rescue ArgumentError
55
+ nil
56
+ end
57
+ end unless @expires_at.is_a?(Time)
58
+ @expires_at ||= Time.at(Time.now.to_i + @expires_in) if @expires_in
49
59
  @options = {:mode => opts.delete(:mode) || :header,
50
60
  :header_format => opts.delete(:header_format) || 'Bearer %s',
51
61
  :param_name => opts.delete(:param_name) || 'access_token'}
@@ -70,7 +80,7 @@ module OAuth2
70
80
  #
71
81
  # @return [Boolean]
72
82
  def expired?
73
- expires? && (expires_at < Time.now.to_i)
83
+ expires? && (expires_at < Time.now)
74
84
  end
75
85
 
76
86
  # Refreshes the current Access Token
@@ -1,8 +1,8 @@
1
1
  module OAuth2
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 9
5
- PATCH = 5
4
+ MINOR = 10
5
+ PATCH = 0
6
6
 
7
7
  class << self
8
8
  # @return [String]
@@ -60,11 +60,35 @@ describe AccessToken do
60
60
  expect(target.options[:mode]).to eq(:body)
61
61
  end
62
62
 
63
- it 'initializes with a string expires_at' do
63
+ it 'initializes with a string expires_at epoch' do
64
64
  hash = {:access_token => token, :expires_at => '1361396829', 'foo' => 'bar'}
65
65
  target = AccessToken.from_hash(client, hash)
66
66
  assert_initialized_token(target)
67
- expect(target.expires_at).to be_a(Integer)
67
+ expect(target.expires_at).to be_a(Time)
68
+ expect(target.expires_at.to_i).to eq(1361396829)
69
+ end
70
+
71
+ it 'initializes with a string expires_at time' do
72
+ hash = {:access_token => token, :expires_at => '2016-05-06T17:37:59.128Z', 'foo' => 'bar'}
73
+ target = AccessToken.from_hash(client, hash)
74
+ assert_initialized_token(target)
75
+ expect(target.expires_at).to be_a(Time)
76
+ expect(target.expires_at.to_i).to eq(1462556279)
77
+ end
78
+
79
+ it 'sets a Time for expires_at via expires_in' do
80
+ hash = {:access_token => token, :expires_in => '100', 'foo' => 'bar'}
81
+ target = AccessToken.from_hash(client, hash)
82
+ assert_initialized_token(target)
83
+ expect(target.expires_at).to be_a(Time)
84
+ end
85
+
86
+ it 'passes through a Time for expires_at' do
87
+ t = Time.now
88
+ hash = {:access_token => token, :expires_at => t, 'foo' => 'bar'}
89
+ target = AccessToken.from_hash(client, hash)
90
+ assert_initialized_token(target)
91
+ expect(target.expires_at).to eq(t)
68
92
  end
69
93
  end
70
94
 
@@ -164,7 +188,12 @@ describe AccessToken do
164
188
 
165
189
  describe '#to_hash' do
166
190
  it 'return a hash equals to the hash used to initialize access token' do
167
- hash = {:access_token => token, :refresh_token => 'foobar', :expires_at => Time.now.to_i + 200, 'foo' => 'bar'}
191
+ t = Time.now + 200
192
+ hash = { :access_token => token,
193
+ :refresh_token => 'foobar',
194
+ :expires_at => t,
195
+ 'foo' => 'bar'
196
+ }
168
197
  access_token = AccessToken.from_hash(client, hash.clone)
169
198
  expect(access_token.to_hash).to eq(hash)
170
199
  end
@@ -76,7 +76,7 @@ describe OAuth2::Strategy::AuthCode do
76
76
  end
77
77
 
78
78
  it 'returns AccessToken with #expires_at' do
79
- expect(@access.expires_at).to be_kind_of(Integer)
79
+ expect(@access.expires_at).to be_kind_of(Time)
80
80
  end
81
81
 
82
82
  it 'returns AccessToken with params accessible via []' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth2-aptible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: 1.3.5
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.4.5
161
+ rubygems_version: 2.6.4
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: A Ruby wrapper for the OAuth 2.0 protocol.