oauth2 0.4.1 → 0.5.1

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.
metadata CHANGED
@@ -1,109 +1,119 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oauth2
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
4
5
  prerelease:
5
- version: 0.4.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Michael Bleigh
9
+ - Erik Michaels-Ober
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
-
13
- date: 2011-04-22 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
13
+ date: 2011-09-26 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70341369880920 !ruby/object:Gem::Requirement
19
18
  none: false
20
- requirements:
19
+ requirements:
21
20
  - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 0.6.1
21
+ - !ruby/object:Gem::Version
22
+ version: 0.7.4
24
23
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: multi_json
28
24
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70341369880920
26
+ - !ruby/object:Gem::Dependency
27
+ name: multi_json
28
+ requirement: &70341369879920 !ruby/object:Gem::Requirement
30
29
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 0.0.5
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.3
35
34
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: json_pure
39
35
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *70341369879920
37
+ - !ruby/object:Gem::Dependency
38
+ name: multi_xml
39
+ requirement: &70341369879020 !ruby/object:Gem::Requirement
41
40
  none: false
42
- requirements:
41
+ requirements:
43
42
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: "1.5"
43
+ - !ruby/object:Gem::Version
44
+ version: '0.4'
46
45
  type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: rake
50
46
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *70341369879020
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: &70341369878180 !ruby/object:Gem::Requirement
52
51
  none: false
53
- requirements:
52
+ requirements:
54
53
  - - ~>
55
- - !ruby/object:Gem::Version
56
- version: "0.8"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.9'
57
56
  type: :development
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: simplecov
61
57
  prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *70341369878180
59
+ - !ruby/object:Gem::Dependency
60
+ name: rdoc
61
+ requirement: &70341369877680 !ruby/object:Gem::Requirement
63
62
  none: false
64
- requirements:
63
+ requirements:
65
64
  - - ~>
66
- - !ruby/object:Gem::Version
67
- version: "0.4"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.9'
68
67
  type: :development
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
68
+ prerelease: false
69
+ version_requirements: *70341369877680
70
+ - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
+ requirement: &70341369876980 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.6'
78
+ type: :development
72
79
  prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
80
+ version_requirements: *70341369876980
81
+ - !ruby/object:Gem::Dependency
82
+ name: simplecov
83
+ requirement: &70341369860040 !ruby/object:Gem::Requirement
74
84
  none: false
75
- requirements:
85
+ requirements:
76
86
  - - ~>
77
- - !ruby/object:Gem::Version
78
- version: "2.5"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.4'
79
89
  type: :development
80
- version_requirements: *id006
81
- - !ruby/object:Gem::Dependency
82
- name: ZenTest
83
90
  prerelease: false
84
- requirement: &id007 !ruby/object:Gem::Requirement
91
+ version_requirements: *70341369860040
92
+ - !ruby/object:Gem::Dependency
93
+ name: yard
94
+ requirement: &70341369858660 !ruby/object:Gem::Requirement
85
95
  none: false
86
- requirements:
96
+ requirements:
87
97
  - - ~>
88
- - !ruby/object:Gem::Version
89
- version: "4.5"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.7'
90
100
  type: :development
91
- version_requirements: *id007
92
- description: A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth gem.
93
- email: michael@intridea.com
101
+ prerelease: false
102
+ version_requirements: *70341369858660
103
+ description: A Ruby wrapper for the OAuth 2.0 protocol built with a similar style
104
+ to the original OAuth gem.
105
+ email:
106
+ - michael@intridea.com
107
+ - sferik@gmail.com
94
108
  executables: []
95
-
96
109
  extensions: []
97
-
98
110
  extra_rdoc_files: []
99
-
100
- files:
111
+ files:
101
112
  - .document
102
113
  - .gemtest
103
114
  - .gitignore
104
115
  - .rspec
105
116
  - .travis.yml
106
- - CHANGELOG.md
107
117
  - Gemfile
108
118
  - LICENSE.md
109
119
  - README.md
@@ -111,50 +121,49 @@ files:
111
121
  - lib/oauth2.rb
112
122
  - lib/oauth2/access_token.rb
113
123
  - lib/oauth2/client.rb
114
- - lib/oauth2/response_object.rb
124
+ - lib/oauth2/error.rb
125
+ - lib/oauth2/response.rb
126
+ - lib/oauth2/strategy/auth_code.rb
115
127
  - lib/oauth2/strategy/base.rb
116
128
  - lib/oauth2/strategy/password.rb
117
- - lib/oauth2/strategy/web_server.rb
118
129
  - lib/oauth2/version.rb
119
130
  - oauth2.gemspec
131
+ - spec/helper.rb
120
132
  - spec/oauth2/access_token_spec.rb
121
133
  - spec/oauth2/client_spec.rb
134
+ - spec/oauth2/response_spec.rb
135
+ - spec/oauth2/strategy/auth_code_spec.rb
122
136
  - spec/oauth2/strategy/base_spec.rb
123
137
  - spec/oauth2/strategy/password_spec.rb
124
- - spec/oauth2/strategy/web_server_spec.rb
125
- - spec/spec_helper.rb
126
138
  homepage: http://github.com/intridea/oauth2
127
139
  licenses: []
128
-
129
140
  post_install_message:
130
141
  rdoc_options: []
131
-
132
- require_paths:
142
+ require_paths:
133
143
  - lib
134
- required_ruby_version: !ruby/object:Gem::Requirement
144
+ required_ruby_version: !ruby/object:Gem::Requirement
135
145
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- version: "0"
140
- required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
151
  none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
145
155
  version: 1.3.6
146
156
  requirements: []
147
-
148
157
  rubyforge_project:
149
- rubygems_version: 1.7.2
158
+ rubygems_version: 1.8.10
150
159
  signing_key:
151
160
  specification_version: 3
152
161
  summary: A Ruby wrapper for the OAuth 2.0 protocol.
153
- test_files:
162
+ test_files:
163
+ - spec/helper.rb
154
164
  - spec/oauth2/access_token_spec.rb
155
165
  - spec/oauth2/client_spec.rb
166
+ - spec/oauth2/response_spec.rb
167
+ - spec/oauth2/strategy/auth_code_spec.rb
156
168
  - spec/oauth2/strategy/base_spec.rb
157
169
  - spec/oauth2/strategy/password_spec.rb
158
- - spec/oauth2/strategy/web_server_spec.rb
159
- - spec/spec_helper.rb
160
- has_rdoc:
data/CHANGELOG.md DELETED
@@ -1,21 +0,0 @@
1
- # CHANGELOG
2
-
3
- * [0.4.1 - April 20, 2011](https://github.com/intridea/oauth2/compare/v0.4.0...v0.4.1)
4
- * [0.4.0 - April 20, 2011](https://github.com/intridea/oauth2/compare/v0.3.0...v0.4.0)
5
- * [0.3.0 - April 8, 2011](https://github.com/intridea/oauth2/compare/v0.2.0...v0.3.0)
6
- * [0.2.0 - April 1, 2011](https://github.com/intridea/oauth2/compare/v0.1.1...v0.2.0)
7
- * [0.1.1 - January 12, 2011](https://github.com/intridea/oauth2/compare/v0.1.0...v0.1.1)
8
- * [0.1.0 - October 13, 2010](https://github.com/intridea/oauth2/compare/v0.0.13...v0.1.0)
9
- * [0.0.13 - August 17, 2010](https://github.com/intridea/oauth2/compare/v0.0.12...v0.0.13)
10
- * [0.0.12 - August 17, 2010](https://github.com/intridea/oauth2/compare/v0.0.11...v0.0.12)
11
- * [0.0.11 - August 17, 2010](https://github.com/intridea/oauth2/compare/v0.0.10...v0.0.11)
12
- * [0.0.10 - June 19, 2010](https://github.com/intridea/oauth2/compare/v0.0.9...v0.0.10)
13
- * [0.0.9 - June 18, 2010](https://github.com/intridea/oauth2/compare/v0.0.8...v0.0.9)
14
- * [0.0.8 - April 27, 2010](https://github.com/intridea/oauth2/compare/v0.0.7...v0.0.8)
15
- * [0.0.7 - April 27, 2010](https://github.com/intridea/oauth2/compare/v0.0.6...v0.0.7)
16
- * [0.0.6 - April 25, 2010](https://github.com/intridea/oauth2/compare/v0.0.5...v0.0.6)
17
- * [0.0.5 - April 23, 2010](https://github.com/intridea/oauth2/compare/v0.0.4...v0.0.5)
18
- * [0.0.4 - April 22, 2010](https://github.com/intridea/oauth2/compare/v0.0.3...v0.0.4)
19
- * [0.0.3 - April 22, 2010](https://github.com/intridea/oauth2/compare/v0.0.2...v0.0.3)
20
- * [0.0.2 - April 22, 2010](https://github.com/intridea/oauth2/compare/v0.0.1...v0.0.2)
21
- * [0.0.1 - April 22, 2010](https://github.com/intridea/oauth2/compare/311d9f42e52b832119170d90e818f0f0b0078851...v0.0.1)
@@ -1,58 +0,0 @@
1
- module OAuth2
2
- module ResponseObject
3
- def self.from(response)
4
- object = MultiJson.decode(response.body)
5
-
6
- case object
7
- when Array
8
- ResponseArray.new(response, object)
9
- when Hash
10
- ResponseHash.new(response, object)
11
- else
12
- ResponseString.new(response)
13
- end
14
- rescue
15
- ResponseString.new(response)
16
- end
17
-
18
- def self.included(base)
19
- base.class_eval do
20
- attr_accessor :response
21
- end
22
- end
23
-
24
- def headers; response.headers end
25
- def status; response.status end
26
- end
27
-
28
- class ResponseHash < Hash
29
- include ResponseObject
30
-
31
- def initialize(response, hash)
32
- self.response = response
33
- hash.keys.each{|k| self[k] = hash[k]}
34
- end
35
- end
36
-
37
- class ResponseArray < Array
38
- include ResponseObject
39
-
40
- def initialize(response, array)
41
- self.response = response
42
- super(array)
43
- end
44
- end
45
-
46
- # This special String class is returned from HTTP requests
47
- # and contains the original full response along with convenience
48
- # methods for accessing the HTTP status code and headers. It
49
- # is returned from all access token requests.
50
- class ResponseString < String
51
- include ResponseObject
52
-
53
- def initialize(response)
54
- super(response.body.to_s)
55
- self.response = response
56
- end
57
- end
58
- end
@@ -1,58 +0,0 @@
1
- require 'multi_json'
2
-
3
- module OAuth2
4
- module Strategy
5
- class WebServer < Base
6
- def authorize_params(options={}) #:nodoc:
7
- super(options).merge('response_type' => 'code')
8
- end
9
-
10
- # Retrieve an access token given the specified validation code.
11
- # Note that you must also provide a <tt>:redirect_uri</tt> option
12
- # in order to successfully verify your request for most OAuth 2.0
13
- # endpoints.
14
- def get_access_token(code, options={})
15
- response = @client.request(@client.token_method, @client.access_token_url, access_token_params(code, options))
16
- parse_response(response)
17
- end
18
-
19
- def refresh_access_token(refresh_token, options={})
20
- response = @client.request(@client.token_method, @client.access_token_url, refresh_token_params(refresh_token, options))
21
- parse_response(response, refresh_token)
22
- end
23
-
24
- def access_token_params(code, options={}) #:nodoc:
25
- super(options).merge({
26
- 'grant_type' => 'authorization_code',
27
- 'code' => code,
28
- })
29
- end
30
-
31
- def refresh_token_params(refresh_token, options={}) #:nodoc:
32
- super(options).merge({
33
- 'grant_type' => 'refresh_token',
34
- 'refresh_token' => refresh_token,
35
- })
36
- end
37
-
38
- def parse_response(response, refresh_token = nil)
39
- if response.is_a? Hash
40
- params = response
41
- else
42
- params = MultiJson.decode(response) rescue nil
43
- # the ActiveSupport JSON parser won't cause an exception when
44
- # given a formencoded string, so make sure that it was
45
- # actually parsed in an Hash. This covers even the case where
46
- # it caused an exception since it'll still be nil.
47
- params = Rack::Utils.parse_query(response) unless params.is_a? Hash
48
- end
49
-
50
- access = params.delete('access_token')
51
- refresh = params.delete('refresh_token') || refresh_token
52
- # params['expires'] is only for Facebook
53
- expires_in = params.delete('expires_in') || params.delete('expires')
54
- OAuth2::AccessToken.new(@client, access, refresh, expires_in, params)
55
- end
56
- end
57
- end
58
- end
@@ -1,138 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe OAuth2::Strategy::WebServer do
4
- let(:client) do
5
- cli = OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com')
6
- cli.connection.build do |b|
7
- b.adapter :test do |stub|
8
- stub.get('/oauth/access_token?client_id=abc&client_secret=def&code=sushi&grant_type=authorization_code') do |env|
9
- case @mode
10
- when "formencoded"
11
- [200, {}, 'expires_in=600&access_token=salmon&refresh_token=trout&extra_param=steve']
12
- when "json"
13
- [200, {}, '{"expires_in":600,"access_token":"salmon","refresh_token":"trout","extra_param":"steve"}']
14
- when "from_facebook"
15
- [200, {}, 'expires=600&access_token=salmon&refresh_token=trout&extra_param=steve']
16
- end
17
- end
18
- stub.post('/oauth/access_token', { 'client_id' => 'abc', 'client_secret' => 'def', 'code' => 'sushi', 'grant_type' => 'authorization_code' }) do |env|
19
- case @mode
20
- when "formencoded"
21
- [200, {}, 'expires_in=600&access_token=salmon&refresh_token=trout&extra_param=steve']
22
- when "json"
23
- [200, {}, '{"expires_in":600,"access_token":"salmon","refresh_token":"trout","extra_param":"steve"}']
24
- when "from_facebook"
25
- [200, {}, 'expires=600&access_token=salmon&refresh_token=trout&extra_param=steve']
26
- end
27
- end
28
- stub.get('/oauth/access_token?client_id=abc&client_secret=def&grant_type=refresh_token&refresh_token=trout') do |env|
29
- case @mode
30
- when "formencoded"
31
- [200, {}, 'expires_in=600&access_token=tuna']
32
- when "json"
33
- [200, {}, '{"expires_in":600,"access_token":"tuna"}']
34
- end
35
- end
36
- stub.post('/oauth/access_token', { 'client_id' => 'abc', 'client_secret' => 'def', 'refresh_token' => 'trout', 'grant_type' => 'refresh_token' }) do |env|
37
- case @mode
38
- when "formencoded"
39
- [200, {}, 'expires_in=600&access_token=tuna']
40
- when "json"
41
- [200, {}, '{"expires_in":600,"access_token":"tuna"}']
42
- end
43
- end
44
- end
45
- end
46
- cli
47
- end
48
- subject{client.web_server}
49
-
50
- describe '#authorize_url' do
51
- it 'should include the client_id' do
52
- subject.authorize_url.should be_include('client_id=abc')
53
- end
54
-
55
- it 'should include the type' do
56
- subject.authorize_url.should be_include('response_type=code')
57
- end
58
-
59
- it 'should include passed in options' do
60
- cb = 'http://myserver.local/oauth/callback'
61
- subject.authorize_url(:redirect_uri => cb).should be_include("redirect_uri=#{Rack::Utils.escape(cb)}")
62
- end
63
- end
64
-
65
- %w(json formencoded from_facebook).each do |mode|
66
- [false, true].each do |parse_json|
67
- [:get, :post].each do |verb|
68
- describe "#get_access_token (#{mode}, token_method=#{verb} parse_json=#{parse_json})" do
69
- before do
70
- @mode = mode
71
- client.json=parse_json
72
- client.token_method=verb
73
- @access = subject.get_access_token('sushi')
74
- end
75
-
76
- it 'returns AccessToken with same Client' do
77
- @access.client.should == client
78
- end
79
-
80
- it 'returns AccessToken with #token' do
81
- @access.token.should == 'salmon'
82
- end
83
-
84
- it 'returns AccessToken with #refresh_token' do
85
- @access.refresh_token.should == 'trout'
86
- end
87
-
88
- it 'returns AccessToken with #expires_in' do
89
- @access.expires_in.should == 600
90
- end
91
-
92
- it 'returns AccessToken with #expires_at' do
93
- @access.expires_at.should be_kind_of(Time)
94
- end
95
-
96
- it 'returns AccessToken with params accessible via []' do
97
- @access['extra_param'].should == 'steve'
98
- end
99
- end
100
- end
101
- end
102
- end
103
-
104
- %w(json formencoded).each do |mode|
105
- [false, true].each do |parse_json|
106
- [:get].each do |verb|
107
- describe "#refresh_access_token (#{mode}, token_method=#{verb} parse_json=#{parse_json})" do
108
- before do
109
- @mode = mode
110
- client.json=parse_json
111
- client.token_method=verb
112
- @access = subject.refresh_access_token('trout')
113
- end
114
-
115
- it 'returns AccessToken with same Client' do
116
- @access.client.should == client
117
- end
118
-
119
- it 'returns AccessToken with #token' do
120
- @access.token.should == 'tuna'
121
- end
122
-
123
- it 'returns AccessToken with #refresh_token' do
124
- @access.refresh_token.should == 'trout'
125
- end
126
-
127
- it 'returns AccessToken with #expires_in' do
128
- @access.expires_in.should == 600
129
- end
130
-
131
- it 'returns AccessToken with #expires_at' do
132
- @access.expires_at.should be_kind_of(Time)
133
- end
134
- end
135
- end
136
- end
137
- end
138
- end
data/spec/spec_helper.rb DELETED
@@ -1,11 +0,0 @@
1
- require "rubygems"
2
- require "bundler"
3
- Bundler.setup
4
-
5
- require 'simplecov'
6
- SimpleCov.start
7
- require 'oauth2'
8
- require 'rspec'
9
- require 'rspec/autorun'
10
-
11
- Faraday.default_adapter = :test