signet 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.3
2
+
3
+ * Added support for JWT-formatted ID tokens.
4
+ * Added :issued_at option to #update_token! method.
5
+
1
6
  == 0.2.2
2
7
 
3
8
  * Lowered requirements for json gem
@@ -42,8 +42,7 @@ module Signet #:nodoc:
42
42
  raise ParseError,
43
43
  "Unexpected auth param format: '#{auth_param_string}'."
44
44
  end
45
- pair = match.captures[0]
46
- auth_param_pairs << pair
45
+ auth_param_pairs << match.captures[0] # Appending pair
47
46
  remainder = match.post_match
48
47
  last_match = match
49
48
  end
@@ -557,7 +557,6 @@ module Signet
557
557
  )
558
558
  ]
559
559
  headers = [authorization_header]
560
- headers << ['Cache-Control', 'no-store']
561
560
  if method == 'POST'
562
561
  headers << ['Content-Type', 'application/x-www-form-urlencoded']
563
562
  end
@@ -17,6 +17,7 @@ require 'addressable/uri'
17
17
  require 'signet'
18
18
  require 'signet/errors'
19
19
  require 'signet/oauth_2'
20
+ require 'jwt'
20
21
 
21
22
  module Signet
22
23
  module OAuth2
@@ -61,6 +62,8 @@ module Signet
61
62
  # to be refreshed.
62
63
  # - <code>:access_token</code> —
63
64
  # The current access token for this client.
65
+ # - <code>:id_token</code> —
66
+ # The current ID token for this client.
64
67
  #
65
68
  # @example
66
69
  # client = Signet::OAuth2::Client.new(
@@ -119,6 +122,8 @@ module Signet
119
122
  # to be refreshed.
120
123
  # - <code>:access_token</code> —
121
124
  # The current access token for this client.
125
+ # - <code>:id_token</code> —
126
+ # The current ID token for this client.
122
127
  # - <code>:expires_in</code> —
123
128
  # The current access token for this client.
124
129
  #
@@ -163,8 +168,12 @@ module Signet
163
168
  # to be refreshed.
164
169
  # - <code>:access_token</code> —
165
170
  # The current access token for this client.
171
+ # - <code>:id_token</code> —
172
+ # The current ID token for this client.
166
173
  # - <code>:expires_in</code> —
167
174
  # The current access token for this client.
175
+ # - <code>:issued_at</code> —
176
+ # The timestamp that the token was issued at.
168
177
  #
169
178
  # @example
170
179
  # client.update!(
@@ -181,9 +190,26 @@ module Signet
181
190
  accu[key.to_s] = value
182
191
  accu
183
192
  end
184
- self.refresh_token = options["refresh_token"]
185
- self.access_token = options["access_token"]
186
- self.expires_in = options["expires_in"]
193
+
194
+ self.access_token = options["access_token"] if options["access_token"]
195
+ self.expires_in = options["expires_in"] if options["expires_in"]
196
+
197
+ # The refresh token may not be returned in a token response.
198
+ # In which case, the old one should continue to be used.
199
+ if options["refresh_token"]
200
+ self.refresh_token = options["refresh_token"]
201
+ end
202
+ # The ID token may not be returned in a token response.
203
+ # In which case, the old one should continue to be used.
204
+ if options["id_token"]
205
+ self.id_token = options["id_token"]
206
+ end
207
+ # By default, the token is issued at `Time.now` when `expires_in` is
208
+ # set, but this can be used to supply a more precise time.
209
+ if options["issued_at"]
210
+ self.issued_at = options["issued_at"]
211
+ end
212
+
187
213
  return self
188
214
  end
189
215
 
@@ -473,7 +499,7 @@ module Signet
473
499
  #
474
500
  # @return [String] The refresh token.
475
501
  def refresh_token
476
- return @refresh_token
502
+ return @refresh_token ||= nil
477
503
  end
478
504
 
479
505
  ##
@@ -490,7 +516,7 @@ module Signet
490
516
  #
491
517
  # @return [String] The access token.
492
518
  def access_token
493
- return @access_token
519
+ return @access_token ||= nil
494
520
  end
495
521
 
496
522
  ##
@@ -502,6 +528,35 @@ module Signet
502
528
  @access_token = new_access_token
503
529
  end
504
530
 
531
+ ##
532
+ # Returns the ID token associated with this client.
533
+ #
534
+ # @return [String] The ID token.
535
+ def id_token
536
+ return @id_token ||= nil
537
+ end
538
+
539
+ ##
540
+ # Sets the ID token associated with this client.
541
+ #
542
+ # @param [String] new_id_token
543
+ # The ID token.
544
+ def id_token=(new_id_token)
545
+ @id_token = new_id_token
546
+ end
547
+
548
+ ##
549
+ # Returns the decoded ID token associated with this client.
550
+ #
551
+ # @param [OpenSSL::PKey::RSA, Object] public_key
552
+ # The public key to use to verify the ID token. Skips verification if
553
+ # omitted.
554
+ #
555
+ # @return [String] The decoded ID token.
556
+ def decoded_id_token(public_key=nil)
557
+ JWT.decode(self.id_token, public_key, !!public_key)
558
+ end
559
+
505
560
  ##
506
561
  # Returns the lifetime of the access token in seconds.
507
562
  #
@@ -517,8 +572,12 @@ module Signet
517
572
  # @param [String] new_expires_in
518
573
  # The access token lifetime.
519
574
  def expires_in=(new_expires_in)
520
- @expires_in = new_expires_in.to_i
521
- @issued_at = Time.now
575
+ if new_expires_in != nil
576
+ @expires_in = new_expires_in.to_i
577
+ @issued_at = Time.now
578
+ else
579
+ @expires_in, @issued_at = nil, nil
580
+ end
522
581
  end
523
582
 
524
583
  ##
@@ -556,7 +615,7 @@ module Signet
556
615
  # @return [TrueClass, FalseClass]
557
616
  # The expiration state of the access token.
558
617
  def expired?
559
- return Time.now >= self.expires_at
618
+ return self.expires_at == nil || Time.now >= self.expires_at
560
619
  end
561
620
 
562
621
  ##
@@ -601,11 +660,6 @@ module Signet
601
660
  if self.client_secret == nil
602
661
  raise ArgumentError, 'Missing client secret.'
603
662
  end
604
- if self.redirect_uri && !self.code
605
- # Grant type can be assumed to be `authorization_code` because of
606
- # the presence of the redirect URI.
607
- raise ArgumentError, 'Missing authorization code.'
608
- end
609
663
  method = 'POST'
610
664
  parameters = {"grant_type" => self.grant_type}
611
665
  case self.grant_type
@@ -620,6 +674,12 @@ module Signet
620
674
  parameters['assertion'] = self.assertion
621
675
  when 'refresh_token'
622
676
  parameters['refresh_token'] = self.refresh_token
677
+ else
678
+ if self.redirect_uri
679
+ # Grant type was intended to be `authorization_code` because of
680
+ # the presence of the redirect URI.
681
+ raise ArgumentError, 'Missing authorization code.'
682
+ end
623
683
  end
624
684
  parameters['client_id'] = self.client_id
625
685
  parameters['client_secret'] = self.client_secret
@@ -18,7 +18,7 @@ unless defined? Signet::VERSION
18
18
  module VERSION
19
19
  MAJOR = 0
20
20
  MINOR = 2
21
- TINY = 2
21
+ TINY = 3
22
22
 
23
23
  STRING = [MAJOR, MINOR, TINY].join('.')
24
24
  end
@@ -25,6 +25,7 @@ namespace :gem do
25
25
  s.add_runtime_dependency("httpadapter", "~> 1.0.0")
26
26
  s.add_runtime_dependency("addressable", "~> 2.2.1")
27
27
  s.add_runtime_dependency("json", ">= 1.4.6")
28
+ s.add_runtime_dependency("jwt", ">= 0.1.4")
28
29
 
29
30
  s.add_development_dependency("rake", "~> 0.8.3")
30
31
  s.add_development_dependency("rspec", "~> 1.1.11")
@@ -41,6 +42,21 @@ namespace :gem do
41
42
  p.need_zip = true
42
43
  end
43
44
 
45
+ desc "Generates .gemspec file"
46
+ task :gemspec do
47
+ spec_string = GEM_SPEC.to_ruby
48
+
49
+ begin
50
+ Thread.new { eval("$SAFE = 3\n#{spec_string}", binding) }.join
51
+ rescue
52
+ abort "unsafe gemspec: #{$!}"
53
+ else
54
+ File.open("#{GEM_SPEC.name}.gemspec", 'w') do |file|
55
+ file.write spec_string
56
+ end
57
+ end
58
+ end
59
+
44
60
  desc "Show information about the gem"
45
61
  task :debug do
46
62
  puts GEM_SPEC.to_ruby
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: signet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bob Aman
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-12 00:00:00 -07:00
19
- default_executable:
18
+ date: 2011-11-15 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: httpadapter
@@ -67,9 +66,25 @@ dependencies:
67
66
  type: :runtime
68
67
  version_requirements: *id003
69
68
  - !ruby/object:Gem::Dependency
70
- name: rake
69
+ name: jwt
71
70
  prerelease: false
72
71
  requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 19
77
+ segments:
78
+ - 0
79
+ - 1
80
+ - 4
81
+ version: 0.1.4
82
+ type: :runtime
83
+ version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
73
88
  none: false
74
89
  requirements:
75
90
  - - ~>
@@ -81,11 +96,11 @@ dependencies:
81
96
  - 3
82
97
  version: 0.8.3
83
98
  type: :development
84
- version_requirements: *id004
99
+ version_requirements: *id005
85
100
  - !ruby/object:Gem::Dependency
86
101
  name: rspec
87
102
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
103
+ requirement: &id006 !ruby/object:Gem::Requirement
89
104
  none: false
90
105
  requirements:
91
106
  - - ~>
@@ -97,11 +112,11 @@ dependencies:
97
112
  - 11
98
113
  version: 1.1.11
99
114
  type: :development
100
- version_requirements: *id005
115
+ version_requirements: *id006
101
116
  - !ruby/object:Gem::Dependency
102
117
  name: launchy
103
118
  prerelease: false
104
- requirement: &id006 !ruby/object:Gem::Requirement
119
+ requirement: &id007 !ruby/object:Gem::Requirement
105
120
  none: false
106
121
  requirements:
107
122
  - - ~>
@@ -113,11 +128,11 @@ dependencies:
113
128
  - 2
114
129
  version: 0.3.2
115
130
  type: :development
116
- version_requirements: *id006
131
+ version_requirements: *id007
117
132
  - !ruby/object:Gem::Dependency
118
133
  name: diff-lcs
119
134
  prerelease: false
120
- requirement: &id007 !ruby/object:Gem::Requirement
135
+ requirement: &id008 !ruby/object:Gem::Requirement
121
136
  none: false
122
137
  requirements:
123
138
  - - ~>
@@ -129,11 +144,11 @@ dependencies:
129
144
  - 2
130
145
  version: 1.1.2
131
146
  type: :development
132
- version_requirements: *id007
147
+ version_requirements: *id008
133
148
  - !ruby/object:Gem::Dependency
134
149
  name: typhoeus
135
150
  prerelease: false
136
- requirement: &id008 !ruby/object:Gem::Requirement
151
+ requirement: &id009 !ruby/object:Gem::Requirement
137
152
  none: false
138
153
  requirements:
139
154
  - - ~>
@@ -145,7 +160,7 @@ dependencies:
145
160
  - 31
146
161
  version: 0.1.31
147
162
  type: :development
148
- version_requirements: *id008
163
+ version_requirements: *id009
149
164
  description: |
150
165
  Signet is an OAuth 1.0 / OAuth 2.0 implementation.
151
166
 
@@ -193,7 +208,6 @@ files:
193
208
  - LICENSE
194
209
  - Rakefile
195
210
  - README.md
196
- has_rdoc: true
197
211
  homepage: http://signet.rubyforge.org/
198
212
  licenses: []
199
213
 
@@ -224,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
238
  requirements: []
225
239
 
226
240
  rubyforge_project: signet
227
- rubygems_version: 1.4.1
241
+ rubygems_version: 1.8.6
228
242
  signing_key:
229
243
  specification_version: 3
230
244
  summary: Package Summary