exvo-auth 0.8.2 → 0.9.0
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/VERSION +1 -1
- data/exvo-auth.gemspec +3 -2
- data/lib/exvo-auth.rb +2 -0
- data/lib/exvo_auth/controllers/base.rb +34 -21
- data/lib/exvo_auth/controllers/merb.rb +4 -4
- data/lib/exvo_auth/controllers/rails.rb +6 -6
- data/lib/exvo_auth/dejavu.rb +22 -0
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/exvo-auth.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{exvo-auth}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.9.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jacek Becela"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-02}
|
13
13
|
s.description = %q{Sign in with Exvo account}
|
14
14
|
s.email = %q{jacek.becela@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/exvo_auth/controllers/base.rb",
|
35
35
|
"lib/exvo_auth/controllers/merb.rb",
|
36
36
|
"lib/exvo_auth/controllers/rails.rb",
|
37
|
+
"lib/exvo_auth/dejavu.rb",
|
37
38
|
"lib/exvo_auth/oauth2.rb",
|
38
39
|
"lib/exvo_auth/strategies/base.rb",
|
39
40
|
"lib/exvo_auth/strategies/interactive.rb",
|
data/lib/exvo-auth.rb
CHANGED
@@ -3,9 +3,11 @@ require 'omniauth/oauth'
|
|
3
3
|
require 'multi_json'
|
4
4
|
require 'httparty'
|
5
5
|
require 'uri'
|
6
|
+
require 'base64'
|
6
7
|
|
7
8
|
module ExvoAuth
|
8
9
|
autoload :Config, 'exvo_auth/config'
|
10
|
+
autoload :Dejavu, 'exvo_auth/dejavu'
|
9
11
|
|
10
12
|
module Strategies
|
11
13
|
autoload :Base, 'exvo_auth/strategies/base'
|
@@ -1,12 +1,8 @@
|
|
1
1
|
module ExvoAuth::Controllers::Base
|
2
|
-
def self.included(base)
|
3
|
-
raise "Please define a #root_url method in #{base.name} (or in routes)" unless base.method_defined? :root_url
|
4
|
-
end
|
5
|
-
|
6
2
|
# A before filter to protect your sensitive actions.
|
7
3
|
def authenticate_user!
|
8
4
|
if !signed_in?
|
9
|
-
|
5
|
+
store_request!
|
10
6
|
|
11
7
|
callback_key = ExvoAuth::Config.callback_key
|
12
8
|
callback_value = params[callback_key]
|
@@ -22,21 +18,19 @@ module ExvoAuth::Controllers::Base
|
|
22
18
|
# Usually this method is called from your sessions#create.
|
23
19
|
def sign_in_and_redirect!(user_id)
|
24
20
|
session[:user_id] = user_id
|
25
|
-
|
21
|
+
|
26
22
|
url = if params[:state] == "popup"
|
27
23
|
ExvoAuth::Config.host + "/close_popup.html"
|
28
24
|
else
|
29
|
-
|
25
|
+
request_replay_url || "/"
|
30
26
|
end
|
31
|
-
|
27
|
+
|
32
28
|
redirect_to url
|
33
29
|
end
|
34
|
-
|
35
|
-
# Redirect to sign_out_url, signs out and redirects back to
|
36
|
-
# This method assumes you have a "root_url" method defined in your controller.
|
37
|
-
#
|
30
|
+
|
31
|
+
# Redirect to sign_out_url, signs out and redirects back to "/" (by default).
|
38
32
|
# Usuallly this method is called from your sessions#destroy.
|
39
|
-
def sign_out_and_redirect!(return_to =
|
33
|
+
def sign_out_and_redirect!(return_to = "/")
|
40
34
|
session.delete(:user_id)
|
41
35
|
@current_user = nil
|
42
36
|
redirect_to sign_out_url(return_to)
|
@@ -80,14 +74,6 @@ module ExvoAuth::Controllers::Base
|
|
80
74
|
|
81
75
|
protected
|
82
76
|
|
83
|
-
def store_location!
|
84
|
-
session[:return_to] = current_url
|
85
|
-
end
|
86
|
-
|
87
|
-
def stored_location
|
88
|
-
session.delete(:return_to)
|
89
|
-
end
|
90
|
-
|
91
77
|
def sign_out_url(return_to)
|
92
78
|
ExvoAuth::Config.host + "/users/sign_out?" + Rack::Utils.build_query({ :return_to => return_to })
|
93
79
|
end
|
@@ -97,4 +83,31 @@ module ExvoAuth::Controllers::Base
|
|
97
83
|
query = Rack::Utils.build_query(params)
|
98
84
|
query.empty? ? path : "#{path}?#{query}"
|
99
85
|
end
|
86
|
+
|
87
|
+
def current_request
|
88
|
+
{
|
89
|
+
:script_name => request.script_name,
|
90
|
+
:path_info => request.path_info,
|
91
|
+
:method => request_method,
|
92
|
+
:params => request.params, # GET + POST params together. no uploads and other crazy shit please ;)
|
93
|
+
:content_type => request.content_type
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def store_request!
|
98
|
+
session[:stored_request] = Base64.encode64(MultiJson.encode(current_request))
|
99
|
+
end
|
100
|
+
|
101
|
+
def request_replay_url
|
102
|
+
if stored_request = session.delete(:stored_request)
|
103
|
+
decoded = MultiJson.decode(Base64.decode64(stored_request))
|
104
|
+
if decoded["method"] == "GET"
|
105
|
+
qs = decoded["query_string"]
|
106
|
+
decoded["script_name"] + decoded["path_info"] + (qs ? "?" + qs : "")
|
107
|
+
else
|
108
|
+
"/auth/dejavu?" + Rack::Utils.build_query(:stored_request => stored_request)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
100
113
|
end
|
@@ -12,6 +12,10 @@ module ExvoAuth::Controllers::Merb
|
|
12
12
|
|
13
13
|
protected
|
14
14
|
|
15
|
+
def request_method
|
16
|
+
request.method.to_s.upcase
|
17
|
+
end
|
18
|
+
|
15
19
|
def basic_authentication_method_name
|
16
20
|
:basic_authentication
|
17
21
|
end
|
@@ -23,9 +27,5 @@ module ExvoAuth::Controllers::Merb
|
|
23
27
|
def find_user_by_id(id)
|
24
28
|
User[id]
|
25
29
|
end
|
26
|
-
|
27
|
-
def current_url
|
28
|
-
request.full_uri if request.method == :get
|
29
|
-
end
|
30
30
|
end
|
31
31
|
end
|
@@ -5,9 +5,13 @@ module ExvoAuth::Controllers::Rails
|
|
5
5
|
base.helper_method :current_user, :signed_in?, :sign_up_path, :sign_in_path
|
6
6
|
end
|
7
7
|
|
8
|
-
module InstanceMethods
|
8
|
+
module InstanceMethods
|
9
9
|
protected
|
10
|
-
|
10
|
+
|
11
|
+
def request_method
|
12
|
+
request.request_method
|
13
|
+
end
|
14
|
+
|
11
15
|
def basic_authentication_method_name
|
12
16
|
:authenticate_or_request_with_http_basic
|
13
17
|
end
|
@@ -15,9 +19,5 @@ module ExvoAuth::Controllers::Rails
|
|
15
19
|
def find_user_by_id(id)
|
16
20
|
User.find(id)
|
17
21
|
end
|
18
|
-
|
19
|
-
def current_url
|
20
|
-
request.url if request.get?
|
21
|
-
end
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class ExvoAuth::Dejavu
|
2
|
+
def initialize(app)
|
3
|
+
@app = app
|
4
|
+
end
|
5
|
+
|
6
|
+
def call(env)
|
7
|
+
dejavu(env) if Rack::Request.new(env).path == "/auth/dejavu"
|
8
|
+
@app.call(env)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def dejavu(env)
|
14
|
+
data = MultiJson.decode(Base64.decode64(Rack::Request.new(env).params["stored_request"]))
|
15
|
+
|
16
|
+
env["QUERY_STRING"] = Rack::Utils.build_nested_query(data["params"]) # Will not work with file uploads.
|
17
|
+
env["SCRIPT_NAME"] = data["script_name"]
|
18
|
+
env["PATH_INFO"] = data["path_info"]
|
19
|
+
env["REQUEST_METHOD"] = data["method"]
|
20
|
+
env["CONTENT_TYPE"] = data["content_type"]
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jacek Becela
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-02 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/exvo_auth/controllers/base.rb
|
110
110
|
- lib/exvo_auth/controllers/merb.rb
|
111
111
|
- lib/exvo_auth/controllers/rails.rb
|
112
|
+
- lib/exvo_auth/dejavu.rb
|
112
113
|
- lib/exvo_auth/oauth2.rb
|
113
114
|
- lib/exvo_auth/strategies/base.rb
|
114
115
|
- lib/exvo_auth/strategies/interactive.rb
|