oauth2 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +5 -0
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/oauth2/access_token.rb +10 -3
- data/lib/oauth2/strategy/web_server.rb +5 -2
- data/oauth2.gemspec +5 -2
- data/spec/oauth2/access_token_spec.rb +23 -0
- data/spec/oauth2/strategy/web_server_spec.rb +29 -13
- metadata +17 -5
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.0.9 (June 18)
|
2
|
+
|
3
|
+
* Support a JSON token response with swappable JSON parser via MultiJSON.
|
4
|
+
* Add support for "expires_in" parameter and relevant methods on AccessToken.
|
5
|
+
|
1
6
|
== 0.0.8 (April 27)
|
2
7
|
|
3
8
|
* Change get_request_token to use POST to conform to OAuth 2.0 spec. (via jeremy)
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/intridea/oauth2"
|
12
12
|
gem.authors = ["Michael Bleigh"]
|
13
13
|
gem.add_dependency 'faraday', '~> 0.4.1'
|
14
|
+
gem.add_dependency 'multi_json'
|
14
15
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
17
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.9
|
data/lib/oauth2/access_token.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
module OAuth2
|
2
2
|
class AccessToken
|
3
|
-
attr_reader :client, :token, :refresh_token
|
3
|
+
attr_reader :client, :token, :refresh_token, :expires_in, :expires_at
|
4
4
|
|
5
|
-
def initialize(client, token, refresh_token = nil)
|
5
|
+
def initialize(client, token, refresh_token = nil, expires_in = nil)
|
6
6
|
@client = client
|
7
7
|
@token = token
|
8
8
|
@refresh_token = refresh_token
|
9
|
+
@expires_in = (expires_in.nil? || expires_in == '') ? nil : expires_in.to_i
|
10
|
+
@expires_at = Time.now + @expires_in if @expires_in
|
11
|
+
end
|
12
|
+
|
13
|
+
# True if the token in question has an expiration time.
|
14
|
+
def expires?
|
15
|
+
!!@expires_in
|
9
16
|
end
|
10
17
|
|
11
18
|
def request(verb, path, params = {}, headers = {})
|
12
|
-
@client.request(verb, path, params.merge('access_token' => @token), headers)
|
19
|
+
@client.request(verb, path, params.merge('access_token' => @token), headers.merge('Authorization' => "Token token=\"#{@token}\""))
|
13
20
|
end
|
14
21
|
|
15
22
|
def get(path, params = {}, headers = {})
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
1
3
|
module OAuth2
|
2
4
|
module Strategy
|
3
5
|
class WebServer < Base
|
@@ -11,10 +13,11 @@ module OAuth2
|
|
11
13
|
# endpoints.
|
12
14
|
def get_access_token(code, options = {})
|
13
15
|
response = @client.request(:post, @client.access_token_url, access_token_params(code, options))
|
14
|
-
params = Rack::Utils.parse_query(response)
|
16
|
+
params = MultiJson.decode(response) rescue Rack::Utils.parse_query(response)
|
15
17
|
access = params['access_token']
|
16
18
|
refresh = params['refresh_token']
|
17
|
-
|
19
|
+
expires_in = params['expires_in']
|
20
|
+
OAuth2::AccessToken.new(@client, access, refresh, expires_in)
|
18
21
|
end
|
19
22
|
|
20
23
|
# <b>DEPRECATED:</b> Use #get_access_token instead.
|
data/oauth2.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{oauth2}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Bleigh"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-18}
|
13
13
|
s.description = %q{A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth gem.}
|
14
14
|
s.email = %q{michael@intridea.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -58,13 +58,16 @@ Gem::Specification.new do |s|
|
|
58
58
|
|
59
59
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
60
60
|
s.add_runtime_dependency(%q<faraday>, ["~> 0.4.1"])
|
61
|
+
s.add_runtime_dependency(%q<multi_json>, [">= 0"])
|
61
62
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
62
63
|
else
|
63
64
|
s.add_dependency(%q<faraday>, ["~> 0.4.1"])
|
65
|
+
s.add_dependency(%q<multi_json>, [">= 0"])
|
64
66
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
65
67
|
end
|
66
68
|
else
|
67
69
|
s.add_dependency(%q<faraday>, ["~> 0.4.1"])
|
70
|
+
s.add_dependency(%q<multi_json>, [">= 0"])
|
68
71
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
69
72
|
end
|
70
73
|
end
|
@@ -34,4 +34,27 @@ describe OAuth2::AccessToken do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
describe '#expires?' do
|
39
|
+
it 'should be false if there is no expires_at' do
|
40
|
+
OAuth2::AccessToken.new(client, token).should_not be_expires
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should be true if there is an expires_at' do
|
44
|
+
OAuth2::AccessToken.new(client, token, 'abaca', 600).should be_expires
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#expires_at' do
|
49
|
+
before do
|
50
|
+
@now = Time.now
|
51
|
+
Time.stub!(:now).and_return(@now)
|
52
|
+
end
|
53
|
+
|
54
|
+
subject{ OAuth2::AccessToken.new(client, token, 'abaca', 600)}
|
55
|
+
|
56
|
+
it 'should be a time representation of #expires_in' do
|
57
|
+
subject.expires_at.should == (@now + 600)
|
58
|
+
end
|
59
|
+
end
|
37
60
|
end
|
@@ -6,7 +6,12 @@ describe OAuth2::Strategy::WebServer do
|
|
6
6
|
cli.connection.build do |b|
|
7
7
|
b.adapter :test do |stub|
|
8
8
|
stub.post('/oauth/access_token') do |env|
|
9
|
-
|
9
|
+
case @mode
|
10
|
+
when "formencoded"
|
11
|
+
[200, {}, 'expires_in=600&access_token=salmon&refresh_token=trout']
|
12
|
+
when "json"
|
13
|
+
[200, {}, '{"expires_in":600,"access_token":"salmon","refresh_token":"trout"}']
|
14
|
+
end
|
10
15
|
end
|
11
16
|
end
|
12
17
|
end
|
@@ -30,20 +35,31 @@ describe OAuth2::Strategy::WebServer do
|
|
30
35
|
end
|
31
36
|
|
32
37
|
describe "#get_access_token" do
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
%w(json formencoded).each do |mode|
|
39
|
+
before do
|
40
|
+
@mode = mode
|
41
|
+
@access = subject.get_access_token('sushi')
|
42
|
+
end
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
|
44
|
+
it 'returns AccessToken with same Client' do
|
45
|
+
@access.client.should == client
|
46
|
+
end
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
it 'returns AccessToken with #token' do
|
49
|
+
@access.token.should == 'salmon'
|
50
|
+
end
|
44
51
|
|
45
|
-
|
46
|
-
|
52
|
+
it 'returns AccessToken with #refresh_token' do
|
53
|
+
@access.refresh_token.should == 'trout'
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns AccessToken with #expires_in' do
|
57
|
+
@access.expires_in.should == 600
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns AccessToken with #expires_at' do
|
61
|
+
@access.expires_at.should be_kind_of(Time)
|
62
|
+
end
|
47
63
|
end
|
48
64
|
end
|
49
|
-
end
|
65
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 9
|
9
|
+
version: 0.0.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Bleigh
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-18 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -32,9 +32,21 @@ dependencies:
|
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
35
|
+
name: multi_json
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
50
|
requirements:
|
39
51
|
- - ">="
|
40
52
|
- !ruby/object:Gem::Version
|
@@ -44,7 +56,7 @@ dependencies:
|
|
44
56
|
- 9
|
45
57
|
version: 1.2.9
|
46
58
|
type: :development
|
47
|
-
version_requirements: *
|
59
|
+
version_requirements: *id003
|
48
60
|
description: A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth gem.
|
49
61
|
email: michael@intridea.com
|
50
62
|
executables: []
|