oauth2 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +9 -3
- data/VERSION +1 -1
- data/lib/oauth2.rb +2 -1
- data/lib/oauth2/client.rb +4 -3
- data/lib/oauth2/response_string.rb +20 -0
- data/lib/oauth2/strategy/web_server.rb +12 -2
- data/oauth2.gemspec +4 -2
- data/spec/oauth2/client_spec.rb +6 -3
- data/spec/oauth2/strategy/web_server_spec.rb +2 -2
- metadata +5 -3
data/CHANGELOG.rdoc
ADDED
data/README.rdoc
CHANGED
@@ -5,6 +5,12 @@ A Ruby wrapper for the OAuth 2.0 specification. This is a work in progress, bein
|
|
5
5
|
== Installation
|
6
6
|
|
7
7
|
gem install oauth2
|
8
|
+
|
9
|
+
== Resources
|
10
|
+
|
11
|
+
* View Source on GitHub (http://github.com/intridea/oauth2)
|
12
|
+
* Report Issues on GitHub (http://github.com/intridea/oauth2/issues)
|
13
|
+
* Read More at the Wiki (http://wiki.github.com/intridea/oauth2/)
|
8
14
|
|
9
15
|
== Web Server Example (Sinatra)
|
10
16
|
|
@@ -18,7 +24,7 @@ Below is a fully functional example of a Sinatra application that would authenti
|
|
18
24
|
def client
|
19
25
|
OAuth2::Client.new('api_key', 'api_secret', :site => 'https://graph.facebook.com')
|
20
26
|
end
|
21
|
-
|
27
|
+
|
22
28
|
get '/auth/facebook' do
|
23
29
|
redirect client.web_server.authorize_url(
|
24
30
|
:redirect_uri => redirect_uri,
|
@@ -27,7 +33,7 @@ Below is a fully functional example of a Sinatra application that would authenti
|
|
27
33
|
end
|
28
34
|
|
29
35
|
get '/auth/facebook/callback' do
|
30
|
-
access_token = client.web_server.
|
36
|
+
access_token = client.web_server.get_access_token(params[:code], :redirect_uri => redirect_uri)
|
31
37
|
user = JSON.parse(access_token.get('/me'))
|
32
38
|
|
33
39
|
user.inspect
|
@@ -40,7 +46,7 @@ Below is a fully functional example of a Sinatra application that would authenti
|
|
40
46
|
uri.to_s
|
41
47
|
end
|
42
48
|
|
43
|
-
That's all there is to it! You can use the access token like you would with the OAuth gem, calling HTTP verbs on it etc.
|
49
|
+
That's all there is to it! You can use the access token like you would with the OAuth gem, calling HTTP verbs on it etc. You can view more examples on the OAuth2 Wiki (http://wiki.github.com/intridea/oauth2/examples)
|
44
50
|
|
45
51
|
== Note on Patches/Pull Requests
|
46
52
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/oauth2.rb
CHANGED
data/lib/oauth2/client.rb
CHANGED
@@ -42,6 +42,7 @@ module OAuth2
|
|
42
42
|
connection.build_url(path, params).to_s
|
43
43
|
end
|
44
44
|
|
45
|
+
# Makes a request relative to the specified site root.
|
45
46
|
def request(verb, url, params = {}, headers = {})
|
46
47
|
if verb == :get
|
47
48
|
resp = connection.run_request(verb, url, nil, headers) do |req|
|
@@ -51,13 +52,13 @@ module OAuth2
|
|
51
52
|
resp = connection.run_request(verb, url, params, headers)
|
52
53
|
end
|
53
54
|
case resp.status
|
54
|
-
when 200...201 then resp
|
55
|
+
when 200...201 then ResponseString.new(resp)
|
55
56
|
when 401
|
56
|
-
e = OAuth2::AccessDenied.new("Received HTTP 401
|
57
|
+
e = OAuth2::AccessDenied.new("Received HTTP 401 during request.")
|
57
58
|
e.response = resp
|
58
59
|
raise e
|
59
60
|
else
|
60
|
-
e = OAuth2::HTTPError.new("Received HTTP #{resp.status}
|
61
|
+
e = OAuth2::HTTPError.new("Received HTTP #{resp.status} during request.")
|
61
62
|
e.response = resp
|
62
63
|
raise e
|
63
64
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This special String class is returned from HTTP requests
|
2
|
+
# and contains the original full response along with convenience
|
3
|
+
# methods for accessing the HTTP status code and headers. It
|
4
|
+
# is returned from all access token requests.
|
5
|
+
class ResponseString < String
|
6
|
+
def initialize(response)
|
7
|
+
super(response.body)
|
8
|
+
self.response = response
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :response
|
12
|
+
|
13
|
+
def status
|
14
|
+
response.status
|
15
|
+
end
|
16
|
+
|
17
|
+
def headers
|
18
|
+
response.headers
|
19
|
+
end
|
20
|
+
end
|
@@ -5,14 +5,24 @@ module OAuth2
|
|
5
5
|
super(options).merge('type' => 'web_server')
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
# Retrieve an access token given the specified validation code.
|
9
|
+
# Note that you must also provide a <tt>:redirect_uri</tt> option
|
10
|
+
# in order to successfully verify your request for most OAuth 2.0
|
11
|
+
# endpoints.
|
12
|
+
def get_access_token(code, options = {})
|
9
13
|
response = @client.request(:get, @client.access_token_url, access_token_params(code, options))
|
10
14
|
params = Rack::Utils.parse_query(response)
|
11
15
|
token = params['access_token']
|
12
16
|
OAuth2::AccessToken.new(@client, token)
|
13
17
|
end
|
14
18
|
|
15
|
-
|
19
|
+
# <b>DEPRECATED:</b> Use #get_access_token instead.
|
20
|
+
def access_token(*args)
|
21
|
+
warn '[DEPRECATED] OAuth2::Strategy::WebServer#access_token is deprecated, use #get_access_token instead. Will be removed in 0.1.0'
|
22
|
+
get_access_token(*args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def access_token_params(code, options = {}) #:nodoc:
|
16
26
|
super(options).merge({
|
17
27
|
'type' => 'web_server',
|
18
28
|
'code' => code
|
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.6"
|
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-04-
|
12
|
+
s.date = %q{2010-04-25}
|
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 = [
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
|
+
"CHANGELOG.rdoc",
|
22
23
|
"LICENSE",
|
23
24
|
"README.rdoc",
|
24
25
|
"Rakefile",
|
@@ -26,6 +27,7 @@ Gem::Specification.new do |s|
|
|
26
27
|
"lib/oauth2.rb",
|
27
28
|
"lib/oauth2/access_token.rb",
|
28
29
|
"lib/oauth2/client.rb",
|
30
|
+
"lib/oauth2/response_string.rb",
|
29
31
|
"lib/oauth2/strategy/base.rb",
|
30
32
|
"lib/oauth2/strategy/web_server.rb",
|
31
33
|
"oauth2.gemspec",
|
data/spec/oauth2/client_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe OAuth2::Client do
|
|
5
5
|
cli = OAuth2::Client.new('abc','def', :site => 'https://api.example.com')
|
6
6
|
cli.connection.build do |b|
|
7
7
|
b.adapter :test do |stub|
|
8
|
-
stub.get('/success') { |env| [200, {}, 'yay'] }
|
8
|
+
stub.get('/success') { |env| [200, {'Content-Type' => 'text/awesome'}, 'yay'] }
|
9
9
|
stub.get('/unauthorized') { |env| [401, {}, ''] }
|
10
10
|
stub.get('/error') { |env| [500, {}, ''] }
|
11
11
|
end
|
@@ -47,8 +47,11 @@ describe OAuth2::Client do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "#request" do
|
50
|
-
it "returns
|
51
|
-
subject.request(:get, '/success', {}, {})
|
50
|
+
it "returns ResponseString on successful response" do
|
51
|
+
response = subject.request(:get, '/success', {}, {})
|
52
|
+
response.should == 'yay'
|
53
|
+
response.status.should == 200
|
54
|
+
response.headers.should == {'Content-Type' => 'text/awesome'}
|
52
55
|
end
|
53
56
|
|
54
57
|
it "raises OAuth2::AccessDenied on 401 response" do
|
@@ -29,9 +29,9 @@ describe OAuth2::Strategy::WebServer do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe "#
|
32
|
+
describe "#get_access_token" do
|
33
33
|
before do
|
34
|
-
@access = subject.
|
34
|
+
@access = subject.get_access_token('sushi')
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'returns AccessToken with same Client' do
|
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
|
+
- 6
|
9
|
+
version: 0.0.6
|
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-04-
|
17
|
+
date: 2010-04-25 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -57,6 +57,7 @@ extra_rdoc_files:
|
|
57
57
|
files:
|
58
58
|
- .document
|
59
59
|
- .gitignore
|
60
|
+
- CHANGELOG.rdoc
|
60
61
|
- LICENSE
|
61
62
|
- README.rdoc
|
62
63
|
- Rakefile
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- lib/oauth2.rb
|
65
66
|
- lib/oauth2/access_token.rb
|
66
67
|
- lib/oauth2/client.rb
|
68
|
+
- lib/oauth2/response_string.rb
|
67
69
|
- lib/oauth2/strategy/base.rb
|
68
70
|
- lib/oauth2/strategy/web_server.rb
|
69
71
|
- oauth2.gemspec
|