carpool 0.2.2 → 0.3.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/carpool.gemspec +23 -23
- data/init.rb +1 -1
- data/lib/carpool.rb +5 -29
- data/lib/carpool/driver.rb +21 -62
- data/lib/carpool/encryptor.rb +52 -0
- data/lib/carpool/mixins/action_controller.rb +6 -28
- data/lib/carpool/mixins/core.rb +17 -13
- data/lib/carpool/passenger.rb +7 -31
- data/lib/carpool/responder.rb +19 -0
- data/lib/carpool/seatbelt.rb +40 -69
- metadata +8 -7
- data/.gitignore +0 -21
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/carpool.gemspec
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{carpool}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brent Kirby"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-12-06}
|
13
13
|
s.description = %q{Carpool is a single sign on solution for Rack-based applications allowing you to persist sessions across domains.}
|
14
14
|
s.email = %q{dev@kurbmedia.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
21
|
+
"LICENSE",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"carpool.gemspec",
|
26
|
+
"init.rb",
|
27
|
+
"lib/carpool.rb",
|
28
|
+
"lib/carpool/driver.rb",
|
29
|
+
"lib/carpool/encryptor.rb",
|
30
|
+
"lib/carpool/mixins/action_controller.rb",
|
31
|
+
"lib/carpool/mixins/action_view.rb",
|
32
|
+
"lib/carpool/mixins/core.rb",
|
33
|
+
"lib/carpool/passenger.rb",
|
34
|
+
"lib/carpool/rails/railtie.rb",
|
35
|
+
"lib/carpool/responder.rb",
|
36
|
+
"lib/carpool/seatbelt.rb",
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/test_carpool.rb"
|
38
39
|
]
|
39
40
|
s.homepage = %q{http://github.com/kurbmedia/carpool}
|
40
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
41
41
|
s.require_paths = ["lib"]
|
42
42
|
s.rubygems_version = %q{1.3.7}
|
43
43
|
s.summary = %q{Single Sign On solution for Rack-Based applications}
|
44
44
|
s.test_files = [
|
45
45
|
"test/helper.rb",
|
46
|
-
|
46
|
+
"test/test_carpool.rb"
|
47
47
|
]
|
48
48
|
|
49
49
|
if s.respond_to? :specification_version then
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'carpool'
|
1
|
+
require 'carpool'
|
data/lib/carpool.rb
CHANGED
@@ -1,23 +1,18 @@
|
|
1
1
|
require 'carpool/mixins/core'
|
2
|
+
require 'carpool/responder'
|
3
|
+
require 'carpool/encryptor'
|
2
4
|
require 'carpool/driver'
|
3
5
|
require 'carpool/passenger'
|
4
6
|
require 'carpool/seatbelt'
|
5
7
|
require 'base64'
|
8
|
+
require 'fast-aes'
|
6
9
|
|
7
10
|
require 'carpool/rails/railtie' if defined?(Rails) && defined?(Rails::Railtie)
|
8
11
|
|
9
12
|
module Carpool
|
10
13
|
|
11
14
|
class << self
|
12
|
-
|
13
|
-
def auth_attempt=(bool)
|
14
|
-
@auth_attempt = bool
|
15
|
-
end
|
16
|
-
|
17
|
-
def auth_attempt?
|
18
|
-
@auth_attempt ||= false
|
19
|
-
end
|
20
|
-
|
15
|
+
|
21
16
|
def driver_uri
|
22
17
|
"#{Carpool::Passenger.driver_uri}/sso/authenticate"
|
23
18
|
end
|
@@ -31,26 +26,7 @@ module Carpool
|
|
31
26
|
def acts_as?(type)
|
32
27
|
@acts_as == type.to_sym
|
33
28
|
end
|
34
|
-
|
35
|
-
def redirect_request(loc, message = "Redirecting")
|
36
|
-
[302,
|
37
|
-
{ 'Content-Type' => 'text/plain',
|
38
|
-
'Location' => loc,
|
39
|
-
'Cache-Control' => 'private, no-cache, max-age=0, must-revalidate',
|
40
|
-
'Content-Length' => "#{message.to_s.length}"
|
41
|
-
}, message]
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.generate_site_key(url)
|
47
|
-
digest = Digest::SHA256.new
|
48
|
-
digest.update(url)
|
49
|
-
Base64.encode64(digest.digest).gsub( /\s/, '')
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.unpack_key(key)
|
53
|
-
Base64.decode64(key)
|
29
|
+
|
54
30
|
end
|
55
31
|
|
56
32
|
end
|
data/lib/carpool/driver.rb
CHANGED
@@ -7,8 +7,7 @@ module Carpool
|
|
7
7
|
include Carpool::Mixins::Core
|
8
8
|
|
9
9
|
class << self
|
10
|
-
|
11
|
-
attr_accessor :site_key
|
10
|
+
|
12
11
|
attr_accessor :unauthorized_uri
|
13
12
|
attr_accessor :revoke_uri
|
14
13
|
|
@@ -16,14 +15,8 @@ module Carpool
|
|
16
15
|
@passengers ||= []
|
17
16
|
end
|
18
17
|
|
19
|
-
def passenger(url,
|
20
|
-
|
21
|
-
options[:secret] ||= Carpool.generate_site_key(url.reverse)
|
22
|
-
passengers << { url => options }
|
23
|
-
end
|
24
|
-
|
25
|
-
def site_key
|
26
|
-
@site_key ||= Carpool.generate_site_key(@env['HTTP_HOST'])
|
18
|
+
def passenger(url, secret)
|
19
|
+
passengers << { :host => url, :secret => secret }
|
27
20
|
end
|
28
21
|
|
29
22
|
end
|
@@ -36,73 +29,39 @@ module Carpool
|
|
36
29
|
end
|
37
30
|
|
38
31
|
def call(env)
|
32
|
+
@env = env
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# TODO: See if this is even necessary? Basically make sure auth_attempt
|
44
|
-
# is set to true if current_passenger is set. This value shouldn't be set if we've already
|
45
|
-
# processed a passenger.
|
46
|
-
Carpool.auth_attempt = true if carpool_cookies['current_passenger']
|
34
|
+
env['carpool'] = Carpool::Seatbelt.new(env) unless env['carpool'] && env['carpool'] != Carpool::Seatbelt
|
35
|
+
return revoke_all_instances! if is_revoking?
|
47
36
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# Unless this domain is listed as a potential passenger, issue a 500.
|
55
|
-
current_passenger = Carpool::Driver.passengers.reject{ |p| !p.keys.first.downcase.include?(referrer.host) }
|
56
|
-
if current_passenger.nil? or current_passenger.empty?
|
57
|
-
return [500, {'Content-Type'=>'text/plain'}, 'Unauthorized request.']
|
58
|
-
end
|
59
|
-
|
60
|
-
# We are logging out this user, clear out our cookies and reset the session, then pass the request to the normal revoke path.
|
61
|
-
if is_revoking?
|
62
|
-
destroy_session!
|
63
|
-
set_new_path(Carpool::Driver.revoke_uri)
|
64
|
-
return @app.call(env)
|
65
|
-
end
|
66
|
-
|
67
|
-
carpool_cookies['current_passenger'] = current_passenger.first[referrer.host.to_s]
|
37
|
+
if valid_request?
|
38
|
+
manager.auth_request!
|
39
|
+
unless manager.authentication_exists?
|
40
|
+
return Carpool::Responder.authenticate
|
41
|
+
end
|
42
|
+
end
|
68
43
|
|
69
|
-
|
70
|
-
|
71
|
-
# The seatbelt includes two parts:
|
72
|
-
# 1) The referring uri, so that Carpool::Passenger on the other end can send the user back to their location one authenticated
|
73
|
-
# 2) The session payload. This is an AES encrypted hash of whatever attributes you've made available. The encrypted hash is
|
74
|
-
# keyed with the site_key and secret of the referring site for extra security.
|
75
|
-
#
|
76
|
-
if carpool_passenger_token
|
77
|
-
seatbelt = SeatBelt.new(env)
|
78
|
-
seatbelt.set_referrer(referrer)
|
79
|
-
seatbelt = seatbelt.create_payload!
|
80
|
-
Carpool.auth_attempt = false
|
81
|
-
cleanup_session!
|
82
|
-
return Carpool.redirect_request(seatbelt, 'Approved!')
|
44
|
+
result = catch(:carpool) do
|
45
|
+
@app.call(env)
|
83
46
|
end
|
84
47
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
set_new_path(Carpool::Driver.unauthorized_uri)
|
89
|
-
return @app.call(env)
|
90
|
-
|
48
|
+
return result
|
49
|
+
|
91
50
|
end
|
92
51
|
|
93
52
|
private
|
94
53
|
|
95
|
-
def valid_referrer?
|
96
|
-
!(@env['HTTP_REFERER'].nil? or @env['HTTP_REFERER'].blank?)
|
97
|
-
end
|
98
|
-
|
99
54
|
def valid_request?
|
100
|
-
@env['PATH_INFO'].downcase == "/sso/authenticate" || @env['PATH_INFO'].downcase == "/sso/revoke"
|
55
|
+
(@env['PATH_INFO'].downcase == "/sso/authenticate" || @env['PATH_INFO'].downcase == "/sso/revoke") && !@env['HTTP_REFERER'].to_s.blank?
|
101
56
|
end
|
102
57
|
|
103
58
|
def is_revoking?
|
104
59
|
@env['PATH_INFO'].downcase == "/sso/revoke"
|
105
60
|
end
|
106
61
|
|
62
|
+
def revoke_all_instances!
|
63
|
+
[307, {"Location" => Carpool::Driver.revoke_uri}, "Revoking global access."]
|
64
|
+
end
|
65
|
+
|
107
66
|
end
|
108
67
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'fast-aes'
|
2
|
+
module Carpool
|
3
|
+
class Encryptor
|
4
|
+
|
5
|
+
def self.generate_token(user_hash, token)
|
6
|
+
digest = self.create_digest(token)
|
7
|
+
aes = FastAES.new(digest.digest)
|
8
|
+
encoded = self.encode(user_hash)
|
9
|
+
self.encode64(aes.encrypt(encoded))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.generate_payload(redirection, user_token)
|
13
|
+
self.encode64(Marshal.dump({:redirect_to => redirection, :user => user_token}))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.process_seatbelt(seatbelt)
|
17
|
+
seatbelt = Marshal.load(Base64.decode64(seatbelt))
|
18
|
+
{
|
19
|
+
:redirect_to => seatbelt[:redirect_to],
|
20
|
+
:user => self.recover_user(seatbelt[:user])
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.create_digest(data)
|
27
|
+
digest = Digest::SHA256.new
|
28
|
+
digest.update(data)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.encode(data)
|
32
|
+
object = Marshal.dump(data)
|
33
|
+
self.encode64(object)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.encode64(data)
|
37
|
+
Base64.encode64(data).gsub(/\s/, '')
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.decode(data)
|
41
|
+
object = Base64.decode64(data)
|
42
|
+
Marshal.load(object)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.recover_user(user_token)
|
46
|
+
digest = self.create_digest(Carpool::Passenger.secret)
|
47
|
+
aes = FastAES.new(digest.digest)
|
48
|
+
self.decode(aes.decrypt(Base64.decode64(user_token)))
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -10,38 +10,16 @@ module Carpool
|
|
10
10
|
Carpool.revoke_uri
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def carpool_user
|
18
|
-
@_carpool_user
|
19
|
-
end
|
20
|
-
|
21
|
-
def fasten_seatbelt(user)
|
22
|
-
Carpool::SeatBelt.new(carpool_rack_env).fasten!(user)
|
23
|
-
end
|
24
|
-
|
25
|
-
def fasten_seatbelt!(user)
|
26
|
-
redirect_to fasten_seatbelt(user)
|
27
|
-
end
|
28
|
-
|
29
|
-
def remove_seatbelt!
|
30
|
-
seatbelt = Carpool::SeatBelt.new(carpool_rack_env).remove!
|
31
|
-
@_carpool_user = seatbelt.user
|
32
|
-
seatbelt
|
13
|
+
def carpool_manager
|
14
|
+
carpool_rack_env['carpool']
|
33
15
|
end
|
16
|
+
|
17
|
+
private
|
34
18
|
|
35
|
-
def
|
36
|
-
|
37
|
-
carpool_rack_env.delete('carpool.cookies')
|
38
|
-
else
|
39
|
-
redirect_to carpool_logout_url
|
40
|
-
end
|
19
|
+
def carpool_rack_request
|
20
|
+
@_request = Rack::Request.new(carpool_rack_env)
|
41
21
|
end
|
42
22
|
|
43
|
-
private
|
44
|
-
|
45
23
|
def carpool_rack_env
|
46
24
|
(defined?(env) ? env : request.env)
|
47
25
|
end
|
data/lib/carpool/mixins/core.rb
CHANGED
@@ -10,34 +10,38 @@ module Carpool
|
|
10
10
|
|
11
11
|
def carpool_cookies
|
12
12
|
session['carpool.cookies'] ||= {}
|
13
|
-
end
|
13
|
+
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def request
|
16
|
+
@request ||= Rack::Request.new(@env)
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
19
|
+
def session
|
20
|
+
request.session
|
21
21
|
end
|
22
22
|
|
23
23
|
def cleanup_session!
|
24
|
-
|
24
|
+
carpool_cookies.delete('requesting_authentication')
|
25
|
+
carpool_cookies.delete('passenger_uri')
|
25
26
|
end
|
26
27
|
|
27
28
|
def destroy_session!
|
28
|
-
|
29
|
+
cleanup_session!
|
30
|
+
carpool_cookies = {}
|
31
|
+
session.delete('carpool.cookies')
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
32
|
-
@
|
34
|
+
def manager
|
35
|
+
@env['carpool']
|
33
36
|
end
|
34
37
|
|
35
|
-
def
|
36
|
-
|
38
|
+
def carpool_passenger_tokens
|
39
|
+
carpool_cookies['passenger_tokens'] ||= []
|
37
40
|
end
|
38
41
|
|
39
|
-
def
|
40
|
-
|
42
|
+
def update_authentication!(new_token)
|
43
|
+
carpool_passenger_tokens << new_token
|
44
|
+
carpool_passenger_tokens.uniq!
|
41
45
|
end
|
42
46
|
|
43
47
|
end
|
data/lib/carpool/passenger.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
|
3
1
|
module Carpool
|
4
2
|
class Passenger
|
5
3
|
|
@@ -21,43 +19,21 @@ module Carpool
|
|
21
19
|
|
22
20
|
def call(env)
|
23
21
|
@env = env
|
24
|
-
@params = CGI.parse(env['QUERY_STRING'])
|
25
22
|
|
26
|
-
|
23
|
+
env['carpool'] = Carpool::Seatbelt.new(env) unless env['carpool'] && env['carpool'] != Carpool::Seatbelt
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
return
|
33
|
-
|
34
|
-
# Set a custom HTTP header for our payload and send the request to the user's /sso/authorize handler.
|
35
|
-
env['X-CARPOOL-PAYLOAD'] = @params['seatbelt']
|
36
|
-
|
37
|
-
return @app.call(env)
|
25
|
+
return @app.call(env) unless valid_request?
|
26
|
+
result = catch(:carpool) do
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
return result
|
38
30
|
|
39
31
|
end
|
40
32
|
|
41
33
|
private
|
42
34
|
|
43
35
|
def valid_request?
|
44
|
-
@env['PATH_INFO'] == "/sso/authorize"
|
45
|
-
end
|
46
|
-
|
47
|
-
def valid_referrer?
|
48
|
-
return false if @env['HTTP_REFERER'].nil? or @env['HTTP_REFERER'].blank?
|
49
|
-
return false if @params['driver'].nil? or @params['driver'].blank?
|
50
|
-
|
51
|
-
referring_uri = @params['driver'].to_s
|
52
|
-
secret_match = Digest::SHA256.new
|
53
|
-
secret_match = secret_match.update(Carpool::Passenger.secret).to_s
|
54
|
-
referring_uri = referring_uri.to_s.gsub(/(\[|\]|\")/,'') # TODO: Figure out why ruby 1.9.2 has extra chars.
|
55
|
-
secret_match = secret_match.to_s
|
56
|
-
referring_uri == secret_match
|
57
|
-
end
|
58
|
-
|
59
|
-
def authenticate_from_remote!
|
60
|
-
|
36
|
+
@env['PATH_INFO'] == "/sso/authorize"
|
61
37
|
end
|
62
38
|
|
63
39
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Carpool
|
2
|
+
|
3
|
+
class Responder
|
4
|
+
|
5
|
+
def self.authenticate
|
6
|
+
[307, {"Location" => Carpool::Driver.unauthorized_uri}, "Redirecing for authentication."]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.passenger_redirect(passenger, payload)
|
10
|
+
new_uri = "#{passenger.scheme}://"
|
11
|
+
new_uri << passenger.host
|
12
|
+
new_uri << ((passenger.port != 80 && passenger.port != 443) ? ":#{passenger.port}" : "")
|
13
|
+
new_uri << "/sso/authorize?seatbelt=#{payload}"
|
14
|
+
[303, {"Location" => new_uri}, "Redirecting...."]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/carpool/seatbelt.rb
CHANGED
@@ -1,95 +1,66 @@
|
|
1
|
-
require 'fast-aes'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
1
|
module Carpool
|
5
|
-
class
|
2
|
+
class Seatbelt
|
6
3
|
|
7
4
|
include Carpool::Mixins::Core
|
8
5
|
|
9
|
-
attr_accessor :env
|
10
|
-
attr_accessor :redirect_uri
|
11
|
-
attr_accessor :user
|
6
|
+
attr_accessor :env, :current_passenger, :current_user, :redirect_to
|
12
7
|
|
13
|
-
# SeatBelt instances require access to the rack environment.
|
14
8
|
def initialize(env)
|
15
9
|
@env = env
|
16
10
|
end
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
# referring site.
|
21
|
-
# Fasten! returns a url for redirection back to our passenger site including the seatbelt used for authentication
|
22
|
-
# on the other end.
|
23
|
-
#
|
24
|
-
def fasten!(user)
|
25
|
-
carpool_cookies['passenger_token'] = generate_token(user)
|
26
|
-
Carpool.auth_attempt = false
|
27
|
-
payload = create_payload!
|
28
|
-
cleanup_session!
|
29
|
-
payload
|
12
|
+
def authentication_exists?
|
13
|
+
!carpool_passenger_tokens.empty?
|
30
14
|
end
|
31
15
|
|
32
|
-
|
33
|
-
|
34
|
-
payload = @env['X-CARPOOL-PAYLOAD']
|
35
|
-
payload = payload.flatten.first if payload.is_a?(Array) # TODO: Figure out why our header is an array?
|
36
|
-
seatbelt = YAML.load(Base64.decode64(CGI.unescape(payload))).to_hash
|
37
|
-
seatbelt = stringify_keys(seatbelt)
|
38
|
-
user = Base64.decode64(seatbelt['user'])
|
39
|
-
key = Carpool.generate_site_key(@env['SERVER_NAME'])
|
40
|
-
secret = Carpool::Passenger.secret
|
41
|
-
digest = Digest::SHA256.new
|
42
|
-
digest.update("#{key}--#{secret}")
|
43
|
-
aes = FastAES.new(digest.digest)
|
44
|
-
data = aes.decrypt(user)
|
45
|
-
@redirect_uri = seatbelt['redirect_uri'].to_s
|
46
|
-
@user = YAML.load(data).to_hash
|
47
|
-
self
|
16
|
+
def authenticate!
|
17
|
+
throw(:carpool, Carpool::Responder.authenticate) unless authentication_exists?
|
48
18
|
end
|
49
19
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
20
|
+
def authorize!(user = nil)
|
21
|
+
unless Carpool.acts_as?(:passenger)
|
22
|
+
return false unless auth_request?
|
23
|
+
update_authentication!(passenger_for_auth[:secret])
|
24
|
+
token = Carpool::Encryptor.generate_token(user.encrypted_credentials, passenger_for_auth[:secret])
|
25
|
+
payload = Carpool::Encryptor.generate_payload(current_passenger, token)
|
26
|
+
throw(:carpool, Carpool::Responder.passenger_redirect(current_passenger, payload))
|
27
|
+
else
|
28
|
+
seatbelt = Carpool::Encryptor.process_seatbelt(request.params['seatbelt'])
|
29
|
+
throw(:carpool, Carpool::Responder.invalid) and return unless seatbelt[:user].is_a?(Hash)
|
30
|
+
@current_user = seatbelt[:user]
|
31
|
+
@redirect_to = seatbelt[:redirect_to]
|
32
|
+
end
|
60
33
|
end
|
61
34
|
|
62
|
-
def
|
63
|
-
|
35
|
+
def auth_request!
|
36
|
+
return if auth_request?
|
37
|
+
carpool_cookies['passenger_uri'] = @env['HTTP_REFERER']
|
38
|
+
carpool_cookies['requesting_authentication'] = true
|
64
39
|
end
|
65
40
|
|
66
|
-
def
|
67
|
-
carpool_cookies['
|
41
|
+
def auth_request?
|
42
|
+
carpool_cookies['requesting_authentication'] && carpool_cookies['requesting_authentication'] == true
|
68
43
|
end
|
69
44
|
|
70
|
-
|
45
|
+
def current_passenger
|
46
|
+
URI.parse(carpool_cookies['passenger_uri'])
|
47
|
+
end
|
71
48
|
|
72
|
-
def
|
73
|
-
|
74
|
-
passenger = Carpool::Driver.passengers.reject{ |p| p.keys.first.downcase != referrer.host }.first.values.first
|
75
|
-
|
76
|
-
digest = Digest::SHA256.new
|
77
|
-
digest.update("#{passenger[:site_key]}--#{passenger[:secret]}")
|
78
|
-
aes = FastAES.new(digest.digest)
|
79
|
-
Base64.encode64(aes.encrypt(gather_credentials(user).to_yaml.to_s)).gsub( /\s/, '')
|
80
|
-
|
49
|
+
def revoke!
|
50
|
+
destroy_session!
|
81
51
|
end
|
82
52
|
|
83
|
-
def
|
84
|
-
|
53
|
+
def success!
|
54
|
+
throw(:carpool, [303, {"Location" => @redirect_to.to_s}, "Authorized!"])
|
85
55
|
end
|
86
56
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
57
|
+
private
|
58
|
+
|
59
|
+
def passenger_for_auth
|
60
|
+
passenger = Carpool::Driver.passengers.detect{ |p| p[:host].downcase.include?(current_passenger.host.downcase) }
|
61
|
+
throw(:carpool, Carpool::Responder.invalid) and return if current_passenger.nil?
|
62
|
+
passenger
|
92
63
|
end
|
93
|
-
|
94
|
-
end
|
64
|
+
|
65
|
+
end
|
95
66
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Brent Kirby
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-06 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -54,7 +54,6 @@ extra_rdoc_files:
|
|
54
54
|
- README.md
|
55
55
|
files:
|
56
56
|
- .document
|
57
|
-
- .gitignore
|
58
57
|
- LICENSE
|
59
58
|
- README.md
|
60
59
|
- Rakefile
|
@@ -63,11 +62,13 @@ files:
|
|
63
62
|
- init.rb
|
64
63
|
- lib/carpool.rb
|
65
64
|
- lib/carpool/driver.rb
|
65
|
+
- lib/carpool/encryptor.rb
|
66
66
|
- lib/carpool/mixins/action_controller.rb
|
67
67
|
- lib/carpool/mixins/action_view.rb
|
68
68
|
- lib/carpool/mixins/core.rb
|
69
69
|
- lib/carpool/passenger.rb
|
70
70
|
- lib/carpool/rails/railtie.rb
|
71
|
+
- lib/carpool/responder.rb
|
71
72
|
- lib/carpool/seatbelt.rb
|
72
73
|
- test/helper.rb
|
73
74
|
- test/test_carpool.rb
|
@@ -76,8 +77,8 @@ homepage: http://github.com/kurbmedia/carpool
|
|
76
77
|
licenses: []
|
77
78
|
|
78
79
|
post_install_message:
|
79
|
-
rdoc_options:
|
80
|
-
|
80
|
+
rdoc_options: []
|
81
|
+
|
81
82
|
require_paths:
|
82
83
|
- lib
|
83
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|