oauth2 0.5.0 → 0.5.2

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/.travis.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
+ - 1.9.3
5
+ - jruby
6
+ - rbx
4
7
  - ree
5
- - ruby-head
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/README.md CHANGED
@@ -1,24 +1,25 @@
1
- OAuth2
2
- ======
3
- A Ruby wrapper for the OAuth 2.0 specification. This is a work in progress, being built first to solve the pragmatic process of connecting to existing OAuth 2.0 endpoints (a.k.a. Facebook) with the goal of building it up to meet the entire specification over time.
1
+ # OAuth2 [![Build Status](https://secure.travis-ci.org/intridea/oauth2.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/intridea/oauth2.png?travis)][gemnasium]
2
+ A Ruby wrapper for the OAuth 2.0 specification. This is a work in progress,
3
+ being built first to solve the pragmatic process of connecting to existing
4
+ OAuth 2.0 endpoints (a.k.a. Facebook) with the goal of building it up to meet
5
+ the entire specification over time.
4
6
 
5
- Installation
6
- ------------
7
- gem install oauth2
7
+ [travis]: http://travis-ci.org/intridea/oauth2
8
+ [gemnasium]: https://gemnasium.com/intridea/oauth2
8
9
 
9
- Continuous Integration
10
- ----------------------
11
- [![Build Status](https://secure.travis-ci.org/intridea/oauth2.png)](http://travis-ci.org/intridea/oauth2)
10
+ ## <a name="installation"></a>Installation
11
+ gem install oauth2
12
12
 
13
- Resources
14
- ---------
15
- * View Source on GitHub (https://github.com/intridea/oauth2)
16
- * Report Issues on GitHub (https://github.com/intridea/oauth2/issues)
17
- * Read More at the Wiki (https://wiki.github.com/intridea/oauth2)
13
+ ## <a name="resources"></a>Resources
14
+ * [View Source on GitHub][code]
15
+ * [Report Issues on GitHub][issues]
16
+ * [Read More at the Wiki][wiki]
18
17
 
19
- Generic Client Example
20
- ----------------------
18
+ [code]: https://github.com/intridea/oauth2
19
+ [issues]: https://github.com/intridea/oauth2/issues
20
+ [wiki]: https://wiki.github.com/intridea/oauth2
21
21
 
22
+ ## <a name="examples"></a>Usage Examples
22
23
  require 'oauth2'
23
24
  client = OAuth2::Client.new('client_id', 'client_secret', :site => 'https://example.org')
24
25
 
@@ -30,55 +31,80 @@ Generic Client Example
30
31
  response.class.name
31
32
  # => OAuth2::Response
32
33
 
33
- OAuth2::Response
34
- ----------------
35
- The AccessToken methods #get, #post, #put and #delete and the generic #request will return an instance of the #OAuth2::Response class.
36
- This instance contains a #parsed method that will parse the response body and return a Hash if the Content-Type is application/x-www-form-urlencoded or if the body is a JSON object. It will return an Array if the body is a JSON array. Otherwise, it will return the original body string.
37
-
38
- The original response body, headers, and status can be accessed via their respective methods.
39
-
40
- OAuth2::AccessToken
41
- -------------------
42
- If you have an existing Access Token for a user, you can initialize an instance using various class methods including the standard new, from_hash (if you have a hash of the values), or from_kvform (if you have an application/x-www-form-urlencoded encoded string of the values).
43
-
44
- OAuth2::Error
45
- -------------
46
- On 400+ status code responses, an OAuth2::Error will be raised. If it is a standard OAuth2 error response, the body will be parsed and #code and #description will contain the values provided from the error and error_description parameters. The #response property of OAuth2::Error will always contain the OAuth2::Response instance.
47
-
48
- If you do not want an error to be raised, you may use :raise_errors => false option on initialization of the client. In this case the OAuth2::Response instance will be returned as usual and on 400+ status code responses, the Response instance will contain the OAuth2::Error instance.
49
-
50
- Authorization Grants
51
- --------------------
52
- Currently the Authorization Code and Resource Owner Password Credentials authentication grant types have helper strategy classes that simplify client use. They are available via the #auth_code and #password methods respectively.
53
-
54
- auth_url = client.auth_code.authorization_url(:redirect_uri => 'http://localhost:8080/oauth/callback')
34
+ ## <a name="response"></a>OAuth2::Response
35
+ The AccessToken methods #get, #post, #put and #delete and the generic #request
36
+ will return an instance of the #OAuth2::Response class.
37
+
38
+ This instance contains a #parsed method that will parse the response body and
39
+ return a Hash if the Content-Type is application/x-www-form-urlencoded or if
40
+ the body is a JSON object. It will return an Array if the body is a JSON
41
+ array. Otherwise, it will return the original body string.
42
+
43
+ The original response body, headers, and status can be accessed via their
44
+ respective methods.
45
+
46
+ ## <a name="access_token"></a>OAuth2::AccessToken
47
+ If you have an existing Access Token for a user, you can initialize an instance
48
+ using various class methods including the standard new, from_hash (if you have
49
+ a hash of the values), or from_kvform (if you have an
50
+ application/x-www-form-urlencoded encoded string of the values).
51
+
52
+ ## <a name="error"></a>OAuth2::Error
53
+ On 400+ status code responses, an OAuth2::Error will be raised. If it is a
54
+ standard OAuth2 error response, the body will be parsed and #code and
55
+ #description will contain the values provided from the error and
56
+ error_description parameters. The #response property of OAuth2::Error will
57
+ always contain the OAuth2::Response instance.
58
+
59
+ If you do not want an error to be raised, you may use :raise_errors => false
60
+ option on initialization of the client. In this case the OAuth2::Response
61
+ instance will be returned as usual and on 400+ status code responses, the
62
+ Response instance will contain the OAuth2::Error instance.
63
+
64
+ ## <a name="authorization_grants"></a>Authorization Grants
65
+ Currently the Authorization Code and Resource Owner Password Credentials
66
+ authentication grant types have helper strategy classes that simplify client
67
+ use. They are available via the #auth_code and #password methods respectively.
68
+
69
+ auth_url = client.auth_code.authorize_url(:redirect_uri => 'http://localhost:8080/oauth/callback')
55
70
  token = client.auth_code.get_token('code_value', :redirect_uri => 'http://localhost:8080/oauth/callback')
56
71
 
57
72
  token = client.password.get_token('username', 'password')
58
73
 
59
- You can always use the #request method on the OAuth2::Client instance to make requests for tokens for any Authentication grant type.
60
-
74
+ You can always use the #request method on the OAuth2::Client instance to make
75
+ requests for tokens for any Authentication grant type.
61
76
 
62
- Note on Patches/Pull Requests
63
- -----------------------------
77
+ ## <a name="pulls"></a>Submitting a Pull Request
64
78
  1. Fork the project.
65
79
  2. Create a topic branch.
66
80
  3. Implement your feature or bug fix.
67
81
  4. Add documentation for your feature or bug fix.
68
82
  5. Add specs for your feature or bug fix.
69
- 6. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 5.
83
+ 6. Run `bundle exec rake spec`. If your changes are not 100% covered, go back
84
+ to step 5.
70
85
  7. Commit and push your changes.
71
- 8. Submit a pull request. Please do not include changes to the [gemspec](https://github.com/intridea/oauth2/blob/master/oauth2.gemspec), [version](https://github.com/intridea/oauth2/blob/master/lib/oauth2/version.rb), or [changelog](https://github.com/intridea/oauth2/wiki/Changelg) . (If you want to create your own version for some reason, please do so in a separate commit.)
86
+ 8. Submit a pull request. Please do not include changes to the [gemspec][],
87
+ [version][], or [changelog][]. (If you want to create your own version for
88
+ some reason, please do so in a separate commit.)
72
89
 
73
- Supported Rubies
74
- ----------------
75
- This library aims to support and is [tested
76
- against](http://travis-ci.org/intridea/oauth2) the following Ruby
90
+ [gemspec]: https://github.com/intridea/oauth2/blob/master/oauth2.gemspec
91
+ [version]: https://github.com/intridea/oauth2/blob/master/lib/oauth2/version.rb
92
+ [changelog]: https://github.com/intridea/oauth2/wiki/Changelog
93
+
94
+ ## <a name="versions"></a>Supported Ruby Versions
95
+ This library aims to support and is [tested against][travis] the following Ruby
77
96
  implementations:
78
97
 
79
98
  * Ruby 1.8.7
80
99
  * Ruby 1.9.2
81
- * Ruby Enterprise Edition 1.8.7
100
+ * Ruby 1.9.3
101
+ * [JRuby][]
102
+ * [Rubinius][]
103
+ * [Ruby Enterprise Edition][ree]
104
+
105
+ [jruby]: http://www.jruby.org/
106
+ [rubinius]: http://rubini.us/
107
+ [ree]: http://www.rubyenterpriseedition.com/
82
108
 
83
109
  If something doesn't work on one of these interpreters, it should be considered
84
110
  a bug.
@@ -94,7 +120,7 @@ implementation, you will be personally responsible for providing patches in a
94
120
  timely fashion. If critical issues for a particular implementation exist at the
95
121
  time of a major release, support for that Ruby version may be dropped.
96
122
 
97
- Copyright
98
- ---------
123
+ ## <a name="copyright"></a>Copyright
99
124
  Copyright (c) 2011 Intridea, Inc. and Michael Bleigh.
100
- See [LICENSE](https://github.com/intridea/oauth2/blob/master/LICENSE.md) for details.
125
+ See [LICENSE][] for details.
126
+ [license]: https://github.com/intridea/oauth2/blob/master/LICENSE.md
data/Rakefile CHANGED
@@ -9,10 +9,13 @@ RSpec::Core::RakeTask.new(:spec)
9
9
  task :default => :spec
10
10
  task :test => :spec
11
11
 
12
- require 'rdoc/task'
13
- Rake::RDocTask.new do |rdoc|
14
- rdoc.rdoc_dir = 'rdoc'
15
- rdoc.title = "oauth2 #{OAuth2::VERSION}"
16
- rdoc.rdoc_files.include('README*')
17
- rdoc.rdoc_files.include('lib/**/*.rb')
12
+ namespace :doc do
13
+ require 'rdoc/task'
14
+ require File.expand_path('../lib/oauth2/version', __FILE__)
15
+ RDoc::Task.new do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = "oauth2 #{OAuth2::VERSION}"
18
+ rdoc.main = 'README.md'
19
+ rdoc.rdoc_files.include('README.md', 'LICENSE.md', 'lib/**/*.rb')
20
+ end
18
21
  end
data/lib/oauth2/client.rb CHANGED
@@ -115,9 +115,10 @@ module OAuth2
115
115
  # Initializes an AccessToken by making a request to the token endpoint
116
116
  #
117
117
  # @param [Hash] params a Hash of params for the token endpoint
118
+ # @param [Hash] access token options, to pass to the AccessToken object
118
119
  # @return [AccessToken] the initalized AccessToken
119
- def get_token(params)
120
- opts = {:raise_errors => true, :parse => params.delete(:parse)}
120
+ def get_token(params, access_token_opts={})
121
+ opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
121
122
  if options[:token_method] == :post
122
123
  opts[:body] = params
123
124
  opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
@@ -125,8 +126,8 @@ module OAuth2
125
126
  opts[:params] = params
126
127
  end
127
128
  response = request(options[:token_method], token_url, opts)
128
- raise Error.new(response) unless response.parsed.is_a?(Hash) && response.parsed['access_token']
129
- AccessToken.from_hash(self, response.parsed)
129
+ raise Error.new(response) if options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])
130
+ AccessToken.from_hash(self, response.parsed.merge(access_token_opts))
130
131
  end
131
132
 
132
133
  # The Authorization Code strategy
@@ -23,7 +23,7 @@ module OAuth2
23
23
  #
24
24
  # @param [Faraday::Response] response The Faraday response instance
25
25
  # @param [Hash] opts options in which to initialize the instance
26
- # @option opts [Symbol] :parse (:automatic) how to parse the response body. one of :url (for x-www-form-urlencoded),
26
+ # @option opts [Symbol] :parse (:automatic) how to parse the response body. one of :query (for x-www-form-urlencoded),
27
27
  # :json, or :automatic (determined by Content-Type response header)
28
28
  def initialize(response, opts={})
29
29
  @response = response
@@ -22,10 +22,11 @@ module OAuth2
22
22
  #
23
23
  # @param [String] code The Authorization Code value
24
24
  # @param [Hash] params additional params
25
+ # @param [Hash] opts options
25
26
  # @note that you must also provide a :redirect_uri with most OAuth 2.0 providers
26
- def get_token(code, params={})
27
+ def get_token(code, params={}, opts={})
27
28
  params = {'grant_type' => 'authorization_code', 'code' => code}.merge(client_params).merge(params)
28
- @client.get_token(params)
29
+ @client.get_token(params, opts)
29
30
  end
30
31
  end
31
32
  end
@@ -16,11 +16,11 @@ module OAuth2
16
16
  # @param [String] username the End User username
17
17
  # @param [String] password the End User password
18
18
  # @param [Hash] params additional params
19
- def get_token(username, password, params={})
19
+ def get_token(username, password, params={}, opts={})
20
20
  params = {'grant_type' => 'password',
21
21
  'username' => username,
22
22
  'password' => password}.merge(client_params).merge(params)
23
- @client.get_token(params)
23
+ @client.get_token(params, opts)
24
24
  end
25
25
  end
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module OAuth2
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.2"
3
3
  end
data/oauth2.gemspec CHANGED
@@ -1,20 +1,18 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
  require File.expand_path('../lib/oauth2/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.add_development_dependency 'rake', '~> 0.9'
6
- gem.add_development_dependency 'rdoc', '~> 3.6'
7
- gem.add_development_dependency 'rspec', '~> 2.6'
8
- gem.add_development_dependency 'simplecov', '~> 0.4'
9
- gem.add_development_dependency 'yard', '~> 0.7'
10
- gem.add_development_dependency 'ZenTest', '~> 4.5'
5
+ gem.add_dependency 'faraday', '~> 0.7'
6
+ gem.add_dependency 'multi_json', '~> 1.0'
11
7
  gem.add_development_dependency 'multi_xml'
12
- gem.add_runtime_dependency 'faraday', ['>= 0.6.1', '< 0.8']
13
- gem.add_runtime_dependency 'multi_json', '~> 1.0.0'
8
+ gem.add_development_dependency 'rake'
9
+ gem.add_development_dependency 'rdoc'
10
+ gem.add_development_dependency 'rspec'
11
+ gem.add_development_dependency 'simplecov'
12
+ gem.add_development_dependency 'yard'
14
13
  gem.authors = ["Michael Bleigh", "Erik Michaels-Ober"]
15
14
  gem.description = %q{A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth gem.}
16
15
  gem.email = ['michael@intridea.com', 'sferik@gmail.com']
17
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
16
  gem.files = `git ls-files`.split("\n")
19
17
  gem.homepage = 'http://github.com/intridea/oauth2'
20
18
  gem.name = 'oauth2'
data/spec/helper.rb CHANGED
@@ -1,5 +1,3 @@
1
- $:.unshift File.expand_path('..', __FILE__)
2
- $:.unshift File.expand_path('../../lib', __FILE__)
3
1
  require 'simplecov'
4
2
  SimpleCov.start
5
3
  require 'oauth2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,77 +10,77 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-29 00:00:00.000000000 Z
13
+ date: 2012-01-04 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rake
17
- requirement: &70092424464720 !ruby/object:Gem::Requirement
16
+ name: faraday
17
+ requirement: &70259907739420 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: '0.9'
23
- type: :development
22
+ version: '0.7'
23
+ type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70092424464720
25
+ version_requirements: *70259907739420
26
26
  - !ruby/object:Gem::Dependency
27
- name: rdoc
28
- requirement: &70092424463940 !ruby/object:Gem::Requirement
27
+ name: multi_json
28
+ requirement: &70259907738920 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '3.6'
34
- type: :development
33
+ version: '1.0'
34
+ type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70092424463940
36
+ version_requirements: *70259907738920
37
37
  - !ruby/object:Gem::Dependency
38
- name: rspec
39
- requirement: &70092424463400 !ruby/object:Gem::Requirement
38
+ name: multi_xml
39
+ requirement: &70259907738540 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
- - - ~>
42
+ - - ! '>='
43
43
  - !ruby/object:Gem::Version
44
- version: '2.6'
44
+ version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70092424463400
47
+ version_requirements: *70259907738540
48
48
  - !ruby/object:Gem::Dependency
49
- name: simplecov
50
- requirement: &70092424462900 !ruby/object:Gem::Requirement
49
+ name: rake
50
+ requirement: &70259907738080 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
- - - ~>
53
+ - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
- version: '0.4'
55
+ version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70092424462900
58
+ version_requirements: *70259907738080
59
59
  - !ruby/object:Gem::Dependency
60
- name: yard
61
- requirement: &70092424462440 !ruby/object:Gem::Requirement
60
+ name: rdoc
61
+ requirement: &70259907737660 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
- - - ~>
64
+ - - ! '>='
65
65
  - !ruby/object:Gem::Version
66
- version: '0.7'
66
+ version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70092424462440
69
+ version_requirements: *70259907737660
70
70
  - !ruby/object:Gem::Dependency
71
- name: ZenTest
72
- requirement: &70092424461860 !ruby/object:Gem::Requirement
71
+ name: rspec
72
+ requirement: &70259907737240 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ~>
75
+ - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: '4.5'
77
+ version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70092424461860
80
+ version_requirements: *70259907737240
81
81
  - !ruby/object:Gem::Dependency
82
- name: multi_xml
83
- requirement: &70092424461480 !ruby/object:Gem::Requirement
82
+ name: simplecov
83
+ requirement: &70259907767020 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,32 +88,18 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70092424461480
91
+ version_requirements: *70259907767020
92
92
  - !ruby/object:Gem::Dependency
93
- name: faraday
94
- requirement: &70092424460880 !ruby/object:Gem::Requirement
93
+ name: yard
94
+ requirement: &70259907766600 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
98
98
  - !ruby/object:Gem::Version
99
- version: 0.6.1
100
- - - <
101
- - !ruby/object:Gem::Version
102
- version: '0.8'
103
- type: :runtime
104
- prerelease: false
105
- version_requirements: *70092424460880
106
- - !ruby/object:Gem::Dependency
107
- name: multi_json
108
- requirement: &70092424460060 !ruby/object:Gem::Requirement
109
- none: false
110
- requirements:
111
- - - ~>
112
- - !ruby/object:Gem::Version
113
- version: 1.0.0
114
- type: :runtime
99
+ version: '0'
100
+ type: :development
115
101
  prerelease: false
116
- version_requirements: *70092424460060
102
+ version_requirements: *70259907766600
117
103
  description: A Ruby wrapper for the OAuth 2.0 protocol built with a similar style
118
104
  to the original OAuth gem.
119
105
  email:
@@ -123,7 +109,6 @@ executables: []
123
109
  extensions: []
124
110
  extra_rdoc_files: []
125
111
  files:
126
- - .autotest
127
112
  - .document
128
113
  - .gemtest
129
114
  - .gitignore
@@ -170,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
155
  version: 1.3.6
171
156
  requirements: []
172
157
  rubyforge_project:
173
- rubygems_version: 1.8.5.1
158
+ rubygems_version: 1.8.13
174
159
  signing_key:
175
160
  specification_version: 3
176
161
  summary: A Ruby wrapper for the OAuth 2.0 protocol.
@@ -182,3 +167,4 @@ test_files:
182
167
  - spec/oauth2/strategy/auth_code_spec.rb
183
168
  - spec/oauth2/strategy/base_spec.rb
184
169
  - spec/oauth2/strategy/password_spec.rb
170
+ has_rdoc:
data/.autotest DELETED
@@ -1 +0,0 @@
1
- require 'autotest/bundler'