oauth2 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/Gemfile +1 -1
- data/README.md +78 -40
- data/lib/oauth2/client.rb +2 -2
- data/lib/oauth2/version.rb +1 -1
- data/oauth2.gemspec +8 -8
- data/spec/helper.rb +0 -2
- metadata +34 -33
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,18 +1,25 @@
|
|
1
|
-
# OAuth2
|
2
|
-
A Ruby wrapper for the OAuth 2.0 specification. This is a work in progress,
|
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.
|
3
6
|
|
4
|
-
|
7
|
+
[travis]: http://travis-ci.org/intridea/oauth2
|
8
|
+
[gemnasium]: https://gemnasium.com/intridea/oauth2
|
9
|
+
|
10
|
+
## <a name="installation"></a>Installation
|
5
11
|
gem install oauth2
|
6
12
|
|
7
|
-
## <a name="
|
8
|
-
[
|
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]
|
9
17
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
* Read More at the Wiki (https://wiki.github.com/intridea/oauth2)
|
18
|
+
[code]: https://github.com/intridea/oauth2
|
19
|
+
[issues]: https://github.com/intridea/oauth2/issues
|
20
|
+
[wiki]: https://wiki.github.com/intridea/oauth2
|
14
21
|
|
15
|
-
## <a name="examples">Usage Examples
|
22
|
+
## <a name="examples"></a>Usage Examples
|
16
23
|
require 'oauth2'
|
17
24
|
client = OAuth2::Client.new('client_id', 'client_secret', :site => 'https://example.org')
|
18
25
|
|
@@ -24,50 +31,80 @@ A Ruby wrapper for the OAuth 2.0 specification. This is a work in progress, bein
|
|
24
31
|
response.class.name
|
25
32
|
# => OAuth2::Response
|
26
33
|
|
27
|
-
## <a name="response">OAuth2::Response
|
28
|
-
The AccessToken methods #get, #post, #put and #delete and the generic #request
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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')
|
45
70
|
token = client.auth_code.get_token('code_value', :redirect_uri => 'http://localhost:8080/oauth/callback')
|
46
71
|
|
47
72
|
token = client.password.get_token('username', 'password')
|
48
73
|
|
49
|
-
You can always use the #request method on the OAuth2::Client instance to make
|
74
|
+
You can always use the #request method on the OAuth2::Client instance to make
|
75
|
+
requests for tokens for any Authentication grant type.
|
50
76
|
|
51
|
-
## <a name="pulls">Submitting a Pull Request
|
77
|
+
## <a name="pulls"></a>Submitting a Pull Request
|
52
78
|
1. Fork the project.
|
53
79
|
2. Create a topic branch.
|
54
80
|
3. Implement your feature or bug fix.
|
55
81
|
4. Add documentation for your feature or bug fix.
|
56
82
|
5. Add specs for your feature or bug fix.
|
57
|
-
6. Run
|
83
|
+
6. Run `bundle exec rake spec`. If your changes are not 100% covered, go back
|
84
|
+
to step 5.
|
58
85
|
7. Commit and push your changes.
|
59
|
-
8. Submit a pull request. Please do not include changes to the [gemspec]
|
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.)
|
60
89
|
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
64
96
|
implementations:
|
65
97
|
|
66
98
|
* Ruby 1.8.7
|
67
99
|
* Ruby 1.9.2
|
68
|
-
*
|
69
|
-
* [
|
70
|
-
* [
|
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/
|
71
108
|
|
72
109
|
If something doesn't work on one of these interpreters, it should be considered
|
73
110
|
a bug.
|
@@ -83,6 +120,7 @@ implementation, you will be personally responsible for providing patches in a
|
|
83
120
|
timely fashion. If critical issues for a particular implementation exist at the
|
84
121
|
time of a major release, support for that Ruby version may be dropped.
|
85
122
|
|
86
|
-
## <a name="copyright">Copyright
|
123
|
+
## <a name="copyright"></a>Copyright
|
87
124
|
Copyright (c) 2011 Intridea, Inc. and Michael Bleigh.
|
88
|
-
See [LICENSE]
|
125
|
+
See [LICENSE][] for details.
|
126
|
+
[license]: https://github.com/intridea/oauth2/blob/master/LICENSE.md
|
data/lib/oauth2/client.rb
CHANGED
@@ -118,7 +118,7 @@ module OAuth2
|
|
118
118
|
# @param [Hash] access token options, to pass to the AccessToken object
|
119
119
|
# @return [AccessToken] the initalized AccessToken
|
120
120
|
def get_token(params, access_token_opts={})
|
121
|
-
opts = {:raise_errors =>
|
121
|
+
opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
|
122
122
|
if options[:token_method] == :post
|
123
123
|
opts[:body] = params
|
124
124
|
opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
|
@@ -126,7 +126,7 @@ module OAuth2
|
|
126
126
|
opts[:params] = params
|
127
127
|
end
|
128
128
|
response = request(options[:token_method], token_url, opts)
|
129
|
-
raise Error.new(response)
|
129
|
+
raise Error.new(response) if options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])
|
130
130
|
AccessToken.from_hash(self, response.parsed.merge(access_token_opts))
|
131
131
|
end
|
132
132
|
|
data/lib/oauth2/version.rb
CHANGED
data/oauth2.gemspec
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
require File.expand_path('../lib/oauth2/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.add_dependency 'faraday', '~> 0.7
|
6
|
-
gem.add_dependency 'multi_json', '~> 1.0
|
7
|
-
gem.add_development_dependency 'multi_xml'
|
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'
|
5
|
+
gem.add_dependency 'faraday', '~> 0.7'
|
6
|
+
gem.add_dependency 'multi_json', '~> 1.0'
|
7
|
+
gem.add_development_dependency 'multi_xml'
|
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'
|
13
13
|
gem.authors = ["Michael Bleigh", "Erik Michaels-Ober"]
|
14
14
|
gem.description = %q{A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth gem.}
|
15
15
|
gem.email = ['michael@intridea.com', 'sferik@gmail.com']
|
data/spec/helper.rb
CHANGED
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.
|
4
|
+
version: 0.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,96 +10,96 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2012-01-04 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
17
|
-
requirement: &
|
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.7
|
22
|
+
version: '0.7'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70259907739420
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: multi_json
|
28
|
-
requirement: &
|
28
|
+
requirement: &70259907738920 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70259907738920
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: multi_xml
|
39
|
-
requirement: &
|
39
|
+
requirement: &70259907738540 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ! '>='
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '0
|
44
|
+
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70259907738540
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rake
|
50
|
-
requirement: &
|
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
|
55
|
+
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70259907738080
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rdoc
|
61
|
-
requirement: &
|
61
|
+
requirement: &70259907737660 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
|
-
- -
|
64
|
+
- - ! '>='
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70259907737660
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
|
-
requirement: &
|
72
|
+
requirement: &70259907737240 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
77
|
+
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70259907737240
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: simplecov
|
83
|
-
requirement: &
|
83
|
+
requirement: &70259907767020 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - ! '>='
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '0
|
88
|
+
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70259907767020
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: yard
|
94
|
-
requirement: &
|
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
|
99
|
+
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *70259907766600
|
103
103
|
description: A Ruby wrapper for the OAuth 2.0 protocol built with a similar style
|
104
104
|
to the original OAuth gem.
|
105
105
|
email:
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: 1.3.6
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.8.
|
158
|
+
rubygems_version: 1.8.13
|
159
159
|
signing_key:
|
160
160
|
specification_version: 3
|
161
161
|
summary: A Ruby wrapper for the OAuth 2.0 protocol.
|
@@ -167,3 +167,4 @@ test_files:
|
|
167
167
|
- spec/oauth2/strategy/auth_code_spec.rb
|
168
168
|
- spec/oauth2/strategy/base_spec.rb
|
169
169
|
- spec/oauth2/strategy/password_spec.rb
|
170
|
+
has_rdoc:
|