rack-oauth 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -2
- data/VERSION +1 -1
- data/lib/rack-oauth.rb +11 -0
- data/spec/sample_sinatra_app_spec.rb +15 -0
- metadata +1 -1
data/Rakefile
CHANGED
@@ -17,8 +17,6 @@ begin
|
|
17
17
|
s.files = FileList['[A-Z]*', '{lib,spec,bin,examples}/**/*']
|
18
18
|
s.add_dependency 'oauth'
|
19
19
|
s.add_dependency 'rack'
|
20
|
-
# s.executables << 'script'
|
21
|
-
# s.rubyforge_project = 'gemname'
|
22
20
|
s.extra_rdoc_files = %w( README.rdoc )
|
23
21
|
end
|
24
22
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/rack-oauth.rb
CHANGED
@@ -41,6 +41,11 @@ module Rack #:nodoc:
|
|
41
41
|
def get_access_token name = nil
|
42
42
|
oauth(name).get_access_token(oauth_request_env)
|
43
43
|
end
|
44
|
+
|
45
|
+
# Same as #get_access_token but it clears the access token out of the session.
|
46
|
+
def get_access_token! name = nil
|
47
|
+
oauth(name).get_access_token!(oauth_request_env)
|
48
|
+
end
|
44
49
|
|
45
50
|
# [Internal] this method returns the Rack 'env' for the current request.
|
46
51
|
#
|
@@ -226,6 +231,12 @@ module Rack #:nodoc:
|
|
226
231
|
::OAuth::AccessToken.from_hash consumer, params if params
|
227
232
|
end
|
228
233
|
|
234
|
+
# Same as #get_access_token but it clears the access token info out of the session
|
235
|
+
def get_access_token! env
|
236
|
+
params = session(env).delete(:access_token_params)
|
237
|
+
::OAuth::AccessToken.from_hash consumer, params if params
|
238
|
+
end
|
239
|
+
|
229
240
|
# Usage:
|
230
241
|
#
|
231
242
|
# request @token, '/account/verify_credentials.json'
|
@@ -31,6 +31,14 @@ class SampleSinatraApp < Sinatra::Base
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
get '/get_many' do
|
35
|
+
get_access_token.inspect
|
36
|
+
end
|
37
|
+
|
38
|
+
get '/get_once' do
|
39
|
+
get_access_token!.inspect
|
40
|
+
end
|
41
|
+
|
34
42
|
get '/oauth_complete' do
|
35
43
|
info = JSON.parse get_access_token.get('/account/verify_credentials.json').body
|
36
44
|
name = info['screen_name']
|
@@ -71,6 +79,13 @@ describe SampleSinatraApp do
|
|
71
79
|
# now the user should be authorized
|
72
80
|
request('/').status.should == 200
|
73
81
|
request('/').body.should include('Hello World')
|
82
|
+
|
83
|
+
request('/get_many').body.should include('OAuth::AccessToken')
|
84
|
+
request('/get_many').body.should include('OAuth::AccessToken')
|
85
|
+
|
86
|
+
request('/get_once').body.should include('OAuth::AccessToken')
|
87
|
+
request('/get_once').body.should_not include('OAuth::AccessToken')
|
88
|
+
request('/get_once').body.should_not include('OAuth::AccessToken')
|
74
89
|
end
|
75
90
|
|
76
91
|
end
|