carpool 0.2.1 → 0.2.2
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/README.md +118 -0
- data/VERSION +1 -1
- data/carpool.gemspec +8 -5
- data/lib/carpool.rb +12 -1
- data/lib/carpool/driver.rb +23 -24
- data/lib/carpool/mixins/action_controller.rb +51 -0
- data/lib/carpool/mixins/action_view.rb +15 -0
- data/lib/carpool/mixins/core.rb +47 -0
- data/lib/carpool/passenger.rb +9 -6
- data/lib/carpool/rails/railtie.rb +22 -0
- data/lib/carpool/seatbelt.rb +25 -10
- metadata +9 -11
- data/README.rdoc +0 -17
- data/lib/carpool/mixins.rb +0 -21
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# carpool
|
2
|
+
|
3
|
+
Carpool is a single-sign-on (sso) solution for rack based applications. It is designed to allow you to designate one application as a "driver" which powers authentication, and sends session information to "passengers". It has been tested with both Rails 2.3 and Rails 3 (as rack middleware).
|
4
|
+
|
5
|
+
Carpool handles securely transferring user information across domains (using AES encryption), as well as redirection so that already-signed-in users will have a seamless experience. It is designed to be as unobtrusive as possible, allowing you to handle the actual login and session maintenance in any manner you would like.
|
6
|
+
|
7
|
+
# Installation
|
8
|
+
|
9
|
+
Install the gem
|
10
|
+
gem install carpool
|
11
|
+
|
12
|
+
# Configuration
|
13
|
+
|
14
|
+
Configure the application you wish to designate as your driver. In Rails based applications, add Carpool::Driver to your middleware stack. The configuration takes three options.
|
15
|
+
|
16
|
+
- One or more passengers. This takes two options, first, the domain name of the passenger application (the referrer), second a 'secret' designated to the passenger application. This secret can be anything, but must match in both the driver and passenger sites.
|
17
|
+
- unauthorized_uri. If there isn't an existing session within the driver application, redirect to this location to handle logins etc
|
18
|
+
- revoke_uri. This url is used to "logout" passengers from the driver
|
19
|
+
|
20
|
+
In environment.rb:
|
21
|
+
|
22
|
+
Rails.configuration.middleware.use Carpool::Driver do |config|
|
23
|
+
config.passenger 'apasengerdomain.com', :secret => 'secret_key'
|
24
|
+
config.unauthorized_uri = 'urlforunauthoried.passengers'
|
25
|
+
config.revoke_uri = 'signout'
|
26
|
+
end
|
27
|
+
|
28
|
+
Then configure the application that you would like to function as your passenger, adding Carpool::Passenger to your middleware stack. This takes two options.
|
29
|
+
|
30
|
+
- driver_uri. This is the url/location of the 'driver' site. (ie: http://yourdriver.com)
|
31
|
+
- secret. This is a shared secret between both the driver and the passenger to verify the passenger has permission to authenticate itself here.
|
32
|
+
|
33
|
+
In environment.rb:
|
34
|
+
|
35
|
+
Rails.configuration.middleware.use Carpool::Passenger do |config|
|
36
|
+
config.driver_uri = 'http://yourdriver.com'
|
37
|
+
config.secret = "secret_key"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Authenticating
|
41
|
+
|
42
|
+
### Driver Application
|
43
|
+
|
44
|
+
Authentication in your driver application can be handled however you would like. When sessions are created, simply check to see if authentication was requested by a passenger website, or the actual application itself. To check this, use Carpool.auth_attempt? When authentication is initiated by a passenger, Carpool creates a 'seatbelt' object which represents the session details to be passed back after successful login/session.
|
45
|
+
|
46
|
+
# Create user session (authlogic format used as an example)
|
47
|
+
user_session.save
|
48
|
+
|
49
|
+
if Carpool.auth_attempt?
|
50
|
+
|
51
|
+
# This login request was generated from a passenger.
|
52
|
+
# current_user represents our now logged in user.
|
53
|
+
# env is the rack environment.
|
54
|
+
|
55
|
+
# Fasten yer seatbelt to be taken back to the requesting app.
|
56
|
+
seatbelt = Carpool::SeatBelt.new(env).fasten!(current_user)
|
57
|
+
redirect_to seatbelt # Redirect back to the passenger site (to /sso/authorize)
|
58
|
+
|
59
|
+
else
|
60
|
+
# Handle local logins here
|
61
|
+
end
|
62
|
+
|
63
|
+
Seatbelt.fasten! generates a url representing a url back to the Passenger application, including a session payload that Carpool::Passenger uses to generate a session within itself.
|
64
|
+
|
65
|
+
### Passenger Application
|
66
|
+
|
67
|
+
Passengers only need to be able to handle two aspects of the process, redirecting `/login` and handing the resulting seatbelt from your Driver application.
|
68
|
+
|
69
|
+
**Redirecting login:** To use the Driver application for logins, redirect users to Carpool.driver_uri
|
70
|
+
|
71
|
+
**Processing the Seatbelt:** On successful login the Drier will redirect the user back to `/sso/authorize` within the passenger application. On redirect, the header `X-CARPOOL-PAYLOAD`, and the parameters `seatbelt` and `driver` will be set. To be sure authentication has taken place, check for the `X-CARPOOL-PAYLOAD` header, then process the seatbelt.
|
72
|
+
|
73
|
+
# Remove our seatbelt because we've arrived! (ok really just process the result)
|
74
|
+
seatbelt = Carpool::SeatBelt.new(request.env).remove!
|
75
|
+
|
76
|
+
# User will contain any parameters encrypted via the Driver (see above).
|
77
|
+
user = seatbelt.user
|
78
|
+
|
79
|
+
# Handle your session however using the user hash.
|
80
|
+
# Call the redirect_uri from our seatbelt to return users back to their original requesting url.
|
81
|
+
redirect_to seatbelt.redirect_uri
|
82
|
+
|
83
|
+
**Rails users:** make sure you setup a route to respond to `/sso/authorize`.
|
84
|
+
|
85
|
+
## User Data
|
86
|
+
|
87
|
+
To make Carpool actually useful in your passenger applications, you would likely need to pass data from the Driver to the Passenger. The `Carpool::Seatbelt.fasten!` method takes one parameter, which can be any Ruby class that responds to the method `encrypted_credentials`. This method should return a hash containing any information you would like to access in your Passengers. This hash is then encrypted via AES using
|
88
|
+
Nate Wiger's [FastAES](https://github.com/nateware/fast-aes) gem. Although this data is encrypted, it is not recommended that the user data hash include sensitive data such as credit card numbers, social security numbers etc.
|
89
|
+
|
90
|
+
class User
|
91
|
+
def encrypted_credentials
|
92
|
+
{
|
93
|
+
:first_name => 'My',
|
94
|
+
:last_name => 'Name',
|
95
|
+
:id => id_for_database_use
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
### Caveats
|
101
|
+
|
102
|
+
To properly ensure the proper domains are being accessed/used, Carpool relies on the `SERVER_NAME` http header. Make sure that this header is properly set via your nginx/apache configuration. If using Passenger standalone, it seems like this variable will be `_` so make sure that you properly handle that.
|
103
|
+
|
104
|
+
If you choose to, you can set `SERVER_NAME` to `HTTP_HOST`, but note that the `HTTP_HOST` variable can be spoofed by end users.
|
105
|
+
|
106
|
+
### Note on Patches/Pull Requests
|
107
|
+
|
108
|
+
* Fork the project.
|
109
|
+
* Make your feature addition or bug fix.
|
110
|
+
* Add tests for it. This is important so I don't break it in a
|
111
|
+
future version unintentionally.
|
112
|
+
* Commit, do not mess with rakefile, version, or history.
|
113
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
114
|
+
* Send me a pull request. Bonus points for topic branches.
|
115
|
+
|
116
|
+
### Copyright
|
117
|
+
|
118
|
+
Copyright (c) 2010 Brent Kirby / Kurb Media LLC. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/carpool.gemspec
CHANGED
@@ -5,30 +5,33 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{carpool}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
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-11-14}
|
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
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
22
|
"LICENSE",
|
23
|
-
"README.
|
23
|
+
"README.md",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"carpool.gemspec",
|
27
27
|
"init.rb",
|
28
28
|
"lib/carpool.rb",
|
29
29
|
"lib/carpool/driver.rb",
|
30
|
-
"lib/carpool/mixins.rb",
|
30
|
+
"lib/carpool/mixins/action_controller.rb",
|
31
|
+
"lib/carpool/mixins/action_view.rb",
|
32
|
+
"lib/carpool/mixins/core.rb",
|
31
33
|
"lib/carpool/passenger.rb",
|
34
|
+
"lib/carpool/rails/railtie.rb",
|
32
35
|
"lib/carpool/seatbelt.rb",
|
33
36
|
"test/helper.rb",
|
34
37
|
"test/test_carpool.rb"
|
data/lib/carpool.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
require 'carpool/mixins'
|
1
|
+
require 'carpool/mixins/core'
|
2
2
|
require 'carpool/driver'
|
3
3
|
require 'carpool/passenger'
|
4
4
|
require 'carpool/seatbelt'
|
5
5
|
require 'base64'
|
6
6
|
|
7
|
+
require 'carpool/rails/railtie' if defined?(Rails) && defined?(Rails::Railtie)
|
8
|
+
|
7
9
|
module Carpool
|
8
10
|
|
9
11
|
class << self
|
@@ -30,6 +32,15 @@ module Carpool
|
|
30
32
|
@acts_as == type.to_sym
|
31
33
|
end
|
32
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
|
+
|
33
44
|
end
|
34
45
|
|
35
46
|
def self.generate_site_key(url)
|
data/lib/carpool/driver.rb
CHANGED
@@ -38,7 +38,12 @@ module Carpool
|
|
38
38
|
def call(env)
|
39
39
|
|
40
40
|
@env = env
|
41
|
-
|
41
|
+
carpool_cookies['scope'] = "driver"
|
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']
|
42
47
|
|
43
48
|
# Unless we are trying to authenticate a passenger, just continue through the stack.
|
44
49
|
return @app.call(env) unless valid_request? && valid_referrer?
|
@@ -49,15 +54,17 @@ module Carpool
|
|
49
54
|
# Unless this domain is listed as a potential passenger, issue a 500.
|
50
55
|
current_passenger = Carpool::Driver.passengers.reject{ |p| !p.keys.first.downcase.include?(referrer.host) }
|
51
56
|
if current_passenger.nil? or current_passenger.empty?
|
52
|
-
return [500, {}, 'Unauthorized request.']
|
57
|
+
return [500, {'Content-Type'=>'text/plain'}, 'Unauthorized request.']
|
53
58
|
end
|
54
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.
|
55
61
|
if is_revoking?
|
56
|
-
|
57
|
-
|
62
|
+
destroy_session!
|
63
|
+
set_new_path(Carpool::Driver.revoke_uri)
|
64
|
+
return @app.call(env)
|
58
65
|
end
|
59
66
|
|
60
|
-
|
67
|
+
carpool_cookies['current_passenger'] = current_passenger.first[referrer.host.to_s]
|
61
68
|
|
62
69
|
# Attempt to find an existing driver session.
|
63
70
|
# If one is found, redirect back to the passenger site and include our seatbelt
|
@@ -66,34 +73,26 @@ module Carpool
|
|
66
73
|
# 2) The session payload. This is an AES encrypted hash of whatever attributes you've made available. The encrypted hash is
|
67
74
|
# keyed with the site_key and secret of the referring site for extra security.
|
68
75
|
#
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
cookies[:redirect_to] = referrer
|
74
|
-
response = [302, {'Location' => Carpool::Driver.unauthorized_uri}, 'Redirecting unauthorized user...']
|
75
|
-
|
76
|
-
else
|
77
|
-
|
78
|
-
puts "Carpool::Driver: Redirecting to passenger site.."
|
79
|
-
cookies[:redirect_to] = referrer
|
80
|
-
seatbelt = SeatBelt.new(env).create_payload!
|
81
|
-
|
82
|
-
response = [302, {'Location' => seatbelt}, 'Approved!']
|
76
|
+
if carpool_passenger_token
|
77
|
+
seatbelt = SeatBelt.new(env)
|
78
|
+
seatbelt.set_referrer(referrer)
|
79
|
+
seatbelt = seatbelt.create_payload!
|
83
80
|
Carpool.auth_attempt = false
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
cleanup_session!
|
82
|
+
return Carpool.redirect_request(seatbelt, 'Approved!')
|
87
83
|
end
|
88
84
|
|
89
|
-
|
85
|
+
Carpool.auth_attempt = true
|
86
|
+
carpool_cookies['redirect_to'] = referrer
|
87
|
+
|
88
|
+
set_new_path(Carpool::Driver.unauthorized_uri)
|
89
|
+
return @app.call(env)
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
93
|
private
|
94
94
|
|
95
95
|
def valid_referrer?
|
96
|
-
puts "Referrer?: #{@env['HTTP_REFERER']}"
|
97
96
|
!(@env['HTTP_REFERER'].nil? or @env['HTTP_REFERER'].blank?)
|
98
97
|
end
|
99
98
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Carpool
|
2
|
+
module Mixins
|
3
|
+
module ActionController
|
4
|
+
|
5
|
+
def carpool_login_url
|
6
|
+
Carpool.driver_uri
|
7
|
+
end
|
8
|
+
|
9
|
+
def carpool_logout_url
|
10
|
+
Carpool.revoke_uri
|
11
|
+
end
|
12
|
+
|
13
|
+
def carpool_can_authenticate?
|
14
|
+
!([carpool_rack_env['X-CARPOOL-PAYLOAD']].flatten.empty?)
|
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
|
33
|
+
end
|
34
|
+
|
35
|
+
def revoke_authentication!
|
36
|
+
if Carpool.acts_as?(:driver)
|
37
|
+
carpool_rack_env.delete('carpool.cookies')
|
38
|
+
else
|
39
|
+
redirect_to carpool_logout_url
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def carpool_rack_env
|
46
|
+
(defined?(env) ? env : request.env)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Carpool
|
2
|
+
module Mixins
|
3
|
+
|
4
|
+
module Core
|
5
|
+
def self.included(base)
|
6
|
+
base.send :include, InstanceMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
|
11
|
+
def carpool_cookies
|
12
|
+
session['carpool.cookies'] ||= {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def carpool_passenger_token
|
16
|
+
carpool_cookies['passenger_token']
|
17
|
+
end
|
18
|
+
|
19
|
+
def carpool_passenger_token=(token)
|
20
|
+
carpool_cookies['passenger_token'] = token
|
21
|
+
end
|
22
|
+
|
23
|
+
def cleanup_session!
|
24
|
+
['redirect_to', 'current_passenger'].each{ |k| carpool_cookies.delete(k) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def destroy_session!
|
28
|
+
session.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
def request
|
32
|
+
@request ||= Rack::Request.new(@env)
|
33
|
+
end
|
34
|
+
|
35
|
+
def session
|
36
|
+
@env['rack.session']
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_new_path(p)
|
40
|
+
@env['PATH_INFO'] = p
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/carpool/passenger.rb
CHANGED
@@ -22,16 +22,18 @@ module Carpool
|
|
22
22
|
def call(env)
|
23
23
|
@env = env
|
24
24
|
@params = CGI.parse(env['QUERY_STRING'])
|
25
|
-
|
25
|
+
|
26
|
+
carpool_cookies['scope'] ||= "passenger"
|
26
27
|
|
27
28
|
# If this isn't an authorize request from the driver, just ignore it.
|
28
29
|
return @app.call(env) unless valid_request? && valid_referrer?
|
29
30
|
|
30
|
-
# If we can't find our payload, then we need to abort.
|
31
|
+
# If we can't find our payload, then we need to abort.
|
31
32
|
return [500, {}, 'Invalid seatbelt.'] if @params['seatbelt'].nil? or @params['seatbelt'].blank?
|
32
33
|
|
33
34
|
# Set a custom HTTP header for our payload and send the request to the user's /sso/authorize handler.
|
34
35
|
env['X-CARPOOL-PAYLOAD'] = @params['seatbelt']
|
36
|
+
|
35
37
|
return @app.call(env)
|
36
38
|
|
37
39
|
end
|
@@ -39,7 +41,7 @@ module Carpool
|
|
39
41
|
private
|
40
42
|
|
41
43
|
def valid_request?
|
42
|
-
@env['PATH_INFO'] == "/sso/authorize"
|
44
|
+
@env['PATH_INFO'] == "/sso/authorize" || @env['PATH_INFO'] == "/sso/remote_authentication"
|
43
45
|
end
|
44
46
|
|
45
47
|
def valid_referrer?
|
@@ -51,11 +53,12 @@ module Carpool
|
|
51
53
|
secret_match = secret_match.update(Carpool::Passenger.secret).to_s
|
52
54
|
referring_uri = referring_uri.to_s.gsub(/(\[|\]|\")/,'') # TODO: Figure out why ruby 1.9.2 has extra chars.
|
53
55
|
secret_match = secret_match.to_s
|
54
|
-
puts "Referring URI: #{referring_uri.class}"
|
55
|
-
puts "Secret: #{secret_match.class}"
|
56
|
-
puts "Trying to match #{referring_uri} to #{secret_match} : #{referring_uri == secret_match}"
|
57
56
|
referring_uri == secret_match
|
58
57
|
end
|
59
58
|
|
59
|
+
def authenticate_from_remote!
|
60
|
+
|
61
|
+
end
|
62
|
+
|
60
63
|
end
|
61
64
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'carpool/mixins/action_controller'
|
2
|
+
require 'carpool/mixins/action_view'
|
3
|
+
|
4
|
+
module Carpool
|
5
|
+
module Rails
|
6
|
+
|
7
|
+
class Railtie < ::Rails::Railtie
|
8
|
+
|
9
|
+
initializer :carpool do
|
10
|
+
ActionController::Base.class_eval do
|
11
|
+
include Carpool::Mixins::ActionController
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
config.after_initialize do
|
16
|
+
ActionView::Base.send :include, Carpool::Mixins::ActionView
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/carpool/seatbelt.rb
CHANGED
@@ -22,10 +22,10 @@ module Carpool
|
|
22
22
|
# on the other end.
|
23
23
|
#
|
24
24
|
def fasten!(user)
|
25
|
-
|
25
|
+
carpool_cookies['passenger_token'] = generate_token(user)
|
26
26
|
Carpool.auth_attempt = false
|
27
27
|
payload = create_payload!
|
28
|
-
|
28
|
+
cleanup_session!
|
29
29
|
payload
|
30
30
|
end
|
31
31
|
|
@@ -34,15 +34,15 @@ module Carpool
|
|
34
34
|
payload = @env['X-CARPOOL-PAYLOAD']
|
35
35
|
payload = payload.flatten.first if payload.is_a?(Array) # TODO: Figure out why our header is an array?
|
36
36
|
seatbelt = YAML.load(Base64.decode64(CGI.unescape(payload))).to_hash
|
37
|
-
|
38
|
-
user = Base64.decode64(seatbelt[
|
37
|
+
seatbelt = stringify_keys(seatbelt)
|
38
|
+
user = Base64.decode64(seatbelt['user'])
|
39
39
|
key = Carpool.generate_site_key(@env['SERVER_NAME'])
|
40
40
|
secret = Carpool::Passenger.secret
|
41
41
|
digest = Digest::SHA256.new
|
42
42
|
digest.update("#{key}--#{secret}")
|
43
43
|
aes = FastAES.new(digest.digest)
|
44
44
|
data = aes.decrypt(user)
|
45
|
-
@redirect_uri = seatbelt[
|
45
|
+
@redirect_uri = seatbelt['redirect_uri'].to_s
|
46
46
|
@user = YAML.load(data).to_hash
|
47
47
|
self
|
48
48
|
end
|
@@ -50,9 +50,9 @@ module Carpool
|
|
50
50
|
# Create a redirection payload to be sent back to our passenger
|
51
51
|
def create_payload!
|
52
52
|
seatbelt = self.to_s
|
53
|
-
referrer =
|
53
|
+
referrer = carpool_cookies['redirect_to']
|
54
54
|
driver = Digest::SHA256.new
|
55
|
-
driver = driver.update(
|
55
|
+
driver = driver.update(carpool_cookies['current_passenger'][:secret]).to_s
|
56
56
|
new_uri = "#{referrer.scheme}://"
|
57
57
|
new_uri << referrer.host
|
58
58
|
new_uri << ((referrer.port != 80 && referrer.port != 443) ? ":#{referrer.port}" : "")
|
@@ -60,21 +60,36 @@ module Carpool
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def to_s
|
63
|
-
CGI.escape(Base64.encode64({
|
63
|
+
CGI.escape(Base64.encode64({ 'redirect_uri' => carpool_cookies['redirect_to'].to_s, 'user' => carpool_cookies['passenger_token'] }.to_yaml.to_s).gsub( /\s/, ''))
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_referrer(ref)
|
67
|
+
carpool_cookies['redirect_to'] = ref
|
64
68
|
end
|
65
69
|
|
66
70
|
private
|
67
71
|
|
68
72
|
def generate_token(user)
|
69
|
-
referrer =
|
73
|
+
referrer = carpool_cookies['redirect_to']
|
70
74
|
passenger = Carpool::Driver.passengers.reject{ |p| p.keys.first.downcase != referrer.host }.first.values.first
|
71
75
|
|
72
76
|
digest = Digest::SHA256.new
|
73
77
|
digest.update("#{passenger[:site_key]}--#{passenger[:secret]}")
|
74
78
|
aes = FastAES.new(digest.digest)
|
75
|
-
Base64.encode64(aes.encrypt(user.
|
79
|
+
Base64.encode64(aes.encrypt(gather_credentials(user).to_yaml.to_s)).gsub( /\s/, '')
|
76
80
|
|
77
81
|
end
|
82
|
+
|
83
|
+
def gather_credentials(user)
|
84
|
+
user.encrypted_credentials
|
85
|
+
end
|
86
|
+
|
87
|
+
def stringify_keys(hash)
|
88
|
+
hash.inject({}) do |options, (key, value)|
|
89
|
+
options[key.to_s] = value
|
90
|
+
options
|
91
|
+
end
|
92
|
+
end
|
78
93
|
|
79
94
|
end
|
80
95
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carpool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 21
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Brent Kirby
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-14 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -40,7 +38,6 @@ dependencies:
|
|
40
38
|
requirements:
|
41
39
|
- - ">="
|
42
40
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
41
|
segments:
|
45
42
|
- 0
|
46
43
|
version: "0"
|
@@ -54,20 +51,23 @@ extensions: []
|
|
54
51
|
|
55
52
|
extra_rdoc_files:
|
56
53
|
- LICENSE
|
57
|
-
- README.
|
54
|
+
- README.md
|
58
55
|
files:
|
59
56
|
- .document
|
60
57
|
- .gitignore
|
61
58
|
- LICENSE
|
62
|
-
- README.
|
59
|
+
- README.md
|
63
60
|
- Rakefile
|
64
61
|
- VERSION
|
65
62
|
- carpool.gemspec
|
66
63
|
- init.rb
|
67
64
|
- lib/carpool.rb
|
68
65
|
- lib/carpool/driver.rb
|
69
|
-
- lib/carpool/mixins.rb
|
66
|
+
- lib/carpool/mixins/action_controller.rb
|
67
|
+
- lib/carpool/mixins/action_view.rb
|
68
|
+
- lib/carpool/mixins/core.rb
|
70
69
|
- lib/carpool/passenger.rb
|
70
|
+
- lib/carpool/rails/railtie.rb
|
71
71
|
- lib/carpool/seatbelt.rb
|
72
72
|
- test/helper.rb
|
73
73
|
- test/test_carpool.rb
|
@@ -85,7 +85,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
hash: 3
|
89
88
|
segments:
|
90
89
|
- 0
|
91
90
|
version: "0"
|
@@ -94,7 +93,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
93
|
requirements:
|
95
94
|
- - ">="
|
96
95
|
- !ruby/object:Gem::Version
|
97
|
-
hash: 3
|
98
96
|
segments:
|
99
97
|
- 0
|
100
98
|
version: "0"
|
data/README.rdoc
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
= carpool
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Note on Patches/Pull Requests
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
-
* Send me a pull request. Bonus points for topic branches.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2010 Brent Kirby. See LICENSE for details.
|
data/lib/carpool/mixins.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Carpool
|
2
|
-
module Mixins
|
3
|
-
|
4
|
-
module Core
|
5
|
-
def self.included(base)
|
6
|
-
base.send :include, InstanceMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
module InstanceMethods
|
10
|
-
def session
|
11
|
-
@env['rack.session']
|
12
|
-
end
|
13
|
-
|
14
|
-
def cookies
|
15
|
-
session['carpool.cookies'] ||= {}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|