passport 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +183 -1
- data/Rakefile +17 -17
- data/VERSION +1 -0
- data/lib/passport.rb +14 -30
- data/lib/passport/core/certification.rb +47 -0
- data/lib/passport/core/context.rb +74 -0
- data/lib/passport/core/installation.rb +40 -0
- data/lib/passport/core/settings.rb +75 -0
- data/lib/passport/core/state.rb +37 -0
- data/lib/passport/core/user.rb +63 -0
- data/lib/passport/engine.rb +15 -0
- data/lib/passport/helpers/core.rb +85 -0
- data/lib/passport/helpers/filter.rb +28 -0
- data/lib/passport/helpers/mixin.rb +15 -0
- data/lib/passport/helpers/rack-context.rb +72 -0
- data/lib/passport/oauth.rb +8 -0
- data/lib/passport/oauth/client/authorizable.rb +84 -0
- data/lib/passport/oauth/client/consumable.rb +47 -0
- data/lib/passport/oauth/client/defineable.rb +82 -0
- data/lib/passport/oauth/client/queryable.rb +23 -0
- data/lib/passport/oauth/client/restful.rb +36 -0
- data/lib/passport/oauth/helper.rb +18 -0
- data/lib/passport/oauth/oauth_token.rb +10 -0
- data/lib/passport/oauth/protocol.rb +12 -0
- data/lib/passport/oauth/protocol/context.rb +71 -0
- data/lib/passport/oauth/protocol/process.rb +59 -0
- data/lib/passport/oauth/protocol/record.rb +42 -0
- data/lib/passport/oauth/protocol/state.rb +46 -0
- data/lib/passport/oauth/tokens/agent_storm_token.rb +12 -0
- data/lib/passport/oauth/tokens/audio_box_token.rb +11 -0
- data/lib/passport/oauth/tokens/brightkite_token.rb +11 -0
- data/lib/passport/oauth/tokens/cliqset_token.rb +13 -0
- data/lib/passport/oauth/tokens/digg_token.rb +9 -0
- data/lib/passport/oauth/tokens/e_trade_token.rb +8 -0
- data/lib/passport/oauth/tokens/evernote_token.rb +10 -0
- data/lib/passport/oauth/tokens/expono_token.rb +10 -0
- data/lib/passport/oauth/tokens/facebook_token.rb +16 -0
- data/lib/passport/oauth/tokens/fat_secret_token.rb +6 -0
- data/lib/passport/oauth/tokens/foursquare_token.rb +14 -0
- data/lib/passport/oauth/tokens/freebase_token.rb +9 -0
- data/lib/passport/oauth/tokens/freshbooks_token.rb +12 -0
- data/lib/passport/oauth/tokens/friendfeed_oauth.rb +7 -0
- data/lib/passport/oauth/tokens/get_satisfaction_token.rb +9 -0
- data/lib/passport/oauth/tokens/github_token.rb +15 -0
- data/lib/passport/oauth/tokens/gliffy_token.rb +6 -0
- data/lib/passport/oauth/tokens/google_token.rb +41 -0
- data/lib/passport/oauth/tokens/gowalla_token.rb +12 -0
- data/lib/passport/oauth/tokens/launchpad_token.rb +7 -0
- data/lib/passport/oauth/tokens/linked_in_token.rb +19 -0
- data/lib/passport/oauth/tokens/live_work_token.rb +6 -0
- data/lib/passport/oauth/tokens/meetup_token.rb +12 -0
- data/lib/passport/oauth/tokens/mendeley_token.rb +7 -0
- data/lib/passport/oauth/tokens/myspace_token.rb +26 -0
- data/lib/passport/oauth/tokens/netflix_token.rb +10 -0
- data/lib/passport/oauth/tokens/ohloh_token.rb +9 -0
- data/lib/passport/oauth/tokens/photobucket_token.rb +11 -0
- data/lib/passport/oauth/tokens/plaxo_token.rb +3 -0
- data/lib/passport/oauth/tokens/praized_token.rb +6 -0
- data/lib/passport/oauth/tokens/remix_token.rb +6 -0
- data/lib/passport/oauth/tokens/salesforce_token.rb +9 -0
- data/lib/passport/oauth/tokens/simple_geo_token.rb +8 -0
- data/lib/passport/oauth/tokens/smug_mug_token.rb +12 -0
- data/lib/passport/oauth/tokens/soundcloud_token.rb +10 -0
- data/lib/passport/oauth/tokens/tribe_token.rb +9 -0
- data/lib/passport/oauth/tokens/trip_it_token.rb +6 -0
- data/lib/passport/oauth/tokens/twitter_token.rb +8 -0
- data/lib/passport/oauth/tokens/vimeo_token.rb +18 -0
- data/lib/passport/oauth/tokens/we_pay_token.rb +8 -0
- data/lib/passport/oauth/tokens/xero_token.rb +8 -0
- data/lib/passport/oauth/tokens/yahoo_token.rb +19 -0
- data/lib/passport/oauth/tokens/yammer_token.rb +10 -0
- data/lib/{open_id_authentication.rb → passport/openid/protocol.rb} +1 -1
- data/lib/passport/openid/tokens/aol_token.rb +0 -0
- data/lib/passport/openid/tokens/blogger_token.rb +0 -0
- data/lib/passport/openid/tokens/flickr_token.rb +0 -0
- data/lib/passport/openid/tokens/my_openid_token.rb +3 -0
- data/lib/passport/openid/tokens/openid_token.rb +9 -0
- data/lib/passport/passport.rb +23 -0
- data/lib/passport/support/active_record.rb +5 -0
- data/lib/passport/support/mongo.rb +9 -0
- data/lib/passport/support/object.rb +13 -0
- data/rails/init.rb +2 -2
- data/test/config.yml +55 -0
- data/test/config/tokens.yml +56 -0
- data/test/dummy/app.rb +50 -0
- data/test/dummy/database.rb +30 -0
- data/test/dummy/stubs.rb +20 -0
- data/test/dummy/user.rb +3 -0
- data/test/test_helper.rb +53 -0
- data/test/test_oauth.rb +250 -0
- data/test/test_passport.rb +23 -0
- metadata +105 -34
data/README.markdown
CHANGED
@@ -1 +1,183 @@
|
|
1
|
-
# Passport
|
1
|
+
# [Passport](http://authlogic-connect.heroku.com)
|
2
|
+
|
3
|
+
> Oauth and OpenId made Dead Simple.
|
4
|
+
|
5
|
+
Note: This is a refactoring and abstraction of [AuthlogicConnect](http://github.com/viatropos/authlogic-connect) and it is not yet complete. The goal is to make it as low level as possible while still making it extremely simple to setup. It will abstract away all Oauth/OpenID complexities and be pluggable into any existing authentication framework.
|
6
|
+
|
7
|
+
Passport is your single interface to Oauth 1.0, Oauth 2.0, and OpenID.
|
8
|
+
|
9
|
+
Allow your users to login with Github, Facebook, Twitter, Google, LinkedIn, MySpace, Vimeo, and Yahoo Oauth providers ([complete list](https://github.com/viatropos/passport/tree/master/lib/passport/oauth/tokens)), and all the OpenID providers. Simple, Clean, Fast.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
### 1. Install
|
14
|
+
|
15
|
+
sudo gem install passport
|
16
|
+
|
17
|
+
### 2. Configure
|
18
|
+
|
19
|
+
#### Add the gem dependencies in your config
|
20
|
+
|
21
|
+
Rails 2.3.x: `config/environment.rb`
|
22
|
+
|
23
|
+
config.gem "passport"
|
24
|
+
|
25
|
+
Rails 3: `Gemfile`
|
26
|
+
|
27
|
+
gem "passport"
|
28
|
+
|
29
|
+
Ruby:
|
30
|
+
|
31
|
+
require "passport"
|
32
|
+
|
33
|
+
#### Specify your keys and secrets
|
34
|
+
|
35
|
+
In a yaml file, say `config/passport.yml`, write your keys and secrets for each service you would like to support. You have to manually go to the websites and register with the service provider.
|
36
|
+
|
37
|
+
adapter: active_record
|
38
|
+
services:
|
39
|
+
twitter:
|
40
|
+
key: "my_key"
|
41
|
+
secret: "my_secret"
|
42
|
+
label: "Twitter"
|
43
|
+
facebook:
|
44
|
+
key: "my_key"
|
45
|
+
secret: "my_secret"
|
46
|
+
label: "Facebook"
|
47
|
+
google:
|
48
|
+
key: "my_key"
|
49
|
+
secret: "my_secret"
|
50
|
+
label: "Google"
|
51
|
+
yahoo:
|
52
|
+
key: "my_key"
|
53
|
+
secret: "my_secret"
|
54
|
+
label: "Yahoo"
|
55
|
+
myspace:
|
56
|
+
key: "my_key"
|
57
|
+
secret: "my_secret"
|
58
|
+
vimeo:
|
59
|
+
key: "my_key"
|
60
|
+
secret: "my_secret"
|
61
|
+
linked_in:
|
62
|
+
key: "my_key"
|
63
|
+
secret: "my_secret"
|
64
|
+
|
65
|
+
Then in your application's initialization process:
|
66
|
+
|
67
|
+
Passport.configure("config/passport.yml")
|
68
|
+
|
69
|
+
## Adapters
|
70
|
+
|
71
|
+
In the `config/passport.yml`, you can specify an `adapter`. The adapter tells Passport what kind of class we want the `AccessToken` to be. The choices are:
|
72
|
+
|
73
|
+
- `object`
|
74
|
+
- `active_record`
|
75
|
+
- `mongo`
|
76
|
+
|
77
|
+
### Plain Ruby Objects
|
78
|
+
|
79
|
+
By default, if an `adapter` is not specified, `AccessToken` will be a plain-old Ruby [`Object`](http://ruby-doc.org/core/classes/Object.html). This means the framework does not have any large dependencies by default, which is useful if you're making a quick and dirty Sinatra app for example, and just want super-simple Oauth support without a database.
|
80
|
+
|
81
|
+
### ActiveRecord
|
82
|
+
|
83
|
+
If you want to use this with ActiveRecord, setting up migrations is easy. Check out the [Rails 3 AuthlogicConnect example](http://github.com/viatropos/authlogic-connect-example) for an authlogic example with user/session/access_token migrations. The migrations table we have been using so far look like this:
|
84
|
+
|
85
|
+
class CreateAccessTokens < ActiveRecord::Migration
|
86
|
+
def self.up
|
87
|
+
create_table :access_tokens do |t|
|
88
|
+
t.integer :user_id
|
89
|
+
t.string :type, :limit => 30 #=> service as a class name
|
90
|
+
t.string :key # how we identify the user, in case they logout and log back in (e.g. email)
|
91
|
+
t.string :token, :limit => 1024
|
92
|
+
t.string :secret
|
93
|
+
t.boolean :active # whether or not it's associated with the account
|
94
|
+
t.timestamps
|
95
|
+
end
|
96
|
+
|
97
|
+
add_index :access_tokens, :key, :unique
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.down
|
101
|
+
drop_table :access_tokens
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
### MongoDB
|
106
|
+
|
107
|
+
MongoDB doesn't require any migrations so it's a simple setup. Just specify the mongo adapter in `config/passport.yml`:
|
108
|
+
|
109
|
+
adapter: mongo
|
110
|
+
|
111
|
+
## API
|
112
|
+
|
113
|
+
There's a lot of functionality packed into Passport. All you need to know is that every service out there (Facebook, Twitter, Github, Foursquare, etc.) is treated as a `Token`. The `OauthToken` (most of this is Oauth right now) has these key methods and attributes:
|
114
|
+
|
115
|
+
- `Token.authorize(callback_url, headers)`: get the authorize url from the oauth provider
|
116
|
+
- `Token.access(hash)`: get the access token from the oauth provider
|
117
|
+
- `key`: the unique identifier for this user (optional, but definitely recommended)
|
118
|
+
- `token`: oauth token from service
|
119
|
+
- `secret`: oauth secret from service
|
120
|
+
- `get(url, options)`: authenticated api GET to the service; pass in headers, params, etc.
|
121
|
+
- `post(url, body, options)`: authenticated api POST to the service
|
122
|
+
|
123
|
+
This means that instead of having to [write lots of code](http://github.com/intridea/oauth2) to setup even a simple oauth handler in your app, you can do this (sinatra example):
|
124
|
+
|
125
|
+
require 'rubygems'
|
126
|
+
require 'passport'
|
127
|
+
|
128
|
+
Passport.configure("tokens.yml")
|
129
|
+
|
130
|
+
get "/" do
|
131
|
+
"<a href='/authenticate?oauth_provider=facebook'>Login with Facebook</a>"
|
132
|
+
end
|
133
|
+
|
134
|
+
get "/authenticate" do
|
135
|
+
Passport.authenticate
|
136
|
+
end
|
137
|
+
|
138
|
+
This also means that if you wanted to do your own oauth setup, with or without any framework, you can easily do that. Say you want to programmatically setup Facebook Oauth with Mechanize (!):
|
139
|
+
|
140
|
+
def facebook_oauth
|
141
|
+
authorize_hash = FacebookToken.authorize("http://some-real-or-fake-callback-url/")
|
142
|
+
# mechanically submit forms
|
143
|
+
access_hash = FacebookToken.access(authorize_hash)
|
144
|
+
# boom, you have the access token (token, key, and secret), now go exploring
|
145
|
+
end
|
146
|
+
|
147
|
+
### Architecture
|
148
|
+
|
149
|
+
You can accomplish everything oauth in Passport without using a server. All you need to do is call these two methods: `Token.authorize` and `Token.access`.
|
150
|
+
|
151
|
+
If you want to use a server (Sinatra, Rails, etc.), then Passport uses [Rack](http://github.com/chneukirchen/rack). It keeps track of the state of the handshake using the `Rack::Session`.
|
152
|
+
|
153
|
+
### Extending
|
154
|
+
|
155
|
+
You can easily add your own services to Passport by creating an `OauthToken` subclass. This is the `FacebookToken` example:
|
156
|
+
|
157
|
+
class FacebookToken < OauthToken
|
158
|
+
|
159
|
+
version 2.0
|
160
|
+
|
161
|
+
key do |access_token|
|
162
|
+
user = JSON.parse(access_token.get("/me"))
|
163
|
+
user["id"]
|
164
|
+
end
|
165
|
+
|
166
|
+
settings "https://graph.facebook.com",
|
167
|
+
:authorize_url => "https://graph.facebook.com/oauth/authorize",
|
168
|
+
:scope => "email, offline_access"
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
There are 3 executable class methods that define the API to the Oauth provider:
|
173
|
+
|
174
|
+
1. `version`: defaults to `1.0`, can also be `2.0`
|
175
|
+
2. `key`: a `block` or symbol that results in something that uniquely identifies the user (e.g `email`, or a service-specific `id`)
|
176
|
+
3. `settings`: the service domain, and a hash of the oauth urls and scopes
|
177
|
+
|
178
|
+
## Lists of known providers
|
179
|
+
|
180
|
+
- [Oauth Providers](http://wiki.oauth.net/ServiceProviders)
|
181
|
+
- [More Oauth Providers](http://www.programmableweb.com/apis/directory/1?auth=OAuth)
|
182
|
+
- [OpenID Providers](http://en.wikipedia.org/wiki/List_of_OpenID_providers)
|
183
|
+
- [More OpenID Providers](http://openid.net/get-an-openid/)
|
data/Rakefile
CHANGED
@@ -2,21 +2,21 @@ require 'rake'
|
|
2
2
|
require "rake/rdoctask"
|
3
3
|
require 'rake/gempackagetask'
|
4
4
|
|
5
|
+
# http://docs.rubygems.org/read/chapter/20
|
5
6
|
spec = Gem::Specification.new do |s|
|
6
7
|
s.name = "passport"
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
8
|
+
s.version = IO.read("VERSION")
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Lance Pollard"]
|
11
|
+
s.email = ["lancejpollard@gmail.com"]
|
12
|
+
s.summary = "Oauth and OpenID made dead simple"
|
13
|
+
s.description = "Ruby Oauth and OpenID library that abstracts away all the complexities of connecting to multiple accounts."
|
10
14
|
s.homepage = "http://github.com/viatropos/passport"
|
11
|
-
s.email = "lancejpollard@gmail.com"
|
12
|
-
s.description = "Oauth and OpenID made dead simple"
|
13
15
|
s.has_rdoc = true
|
14
16
|
s.rubyforge_project = "passport"
|
15
|
-
s.
|
16
|
-
s.files = %w(README.markdown Rakefile init.rb MIT-LICENSE) + Dir["{lib,rails,test}/**/*"] - Dir["test/tmp"]
|
17
|
+
s.files = %w(README.markdown Rakefile init.rb MIT-LICENSE VERSION) + Dir["{lib,rails,test}/**/*"] - Dir["test/tmp"]
|
17
18
|
s.require_path = "lib"
|
18
19
|
s.add_dependency("activesupport", ">= 2.1.2")
|
19
|
-
s.add_dependency("activerecord", ">= 2.1.2")
|
20
20
|
s.add_dependency("json")
|
21
21
|
s.add_dependency("ruby-openid")
|
22
22
|
s.add_dependency("rack-openid", ">=0.2.1")
|
@@ -24,21 +24,16 @@ spec = Gem::Specification.new do |s|
|
|
24
24
|
s.add_dependency("oauth2")
|
25
25
|
end
|
26
26
|
|
27
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
28
|
-
pkg.gem_spec = spec
|
29
|
-
pkg.package_dir = "pkg"
|
30
|
-
end
|
31
|
-
|
32
27
|
desc "Create .gemspec file (useful for github)"
|
33
28
|
task :gemspec do
|
34
|
-
File.open("
|
29
|
+
File.open("#{spec.name}.gemspec", "w") do |f|
|
35
30
|
f.puts spec.to_ruby
|
36
31
|
end
|
37
32
|
end
|
38
33
|
|
39
34
|
desc "Build the gem into the current directory"
|
40
35
|
task :gem => :gemspec do
|
41
|
-
`gem build
|
36
|
+
`gem build #{spec.name}.gemspec`
|
42
37
|
end
|
43
38
|
|
44
39
|
desc "Publish gem to rubygems"
|
@@ -55,8 +50,13 @@ task :manifest do
|
|
55
50
|
end
|
56
51
|
end
|
57
52
|
|
53
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
54
|
+
pkg.gem_spec = spec
|
55
|
+
pkg.package_dir = "pkg"
|
56
|
+
end
|
57
|
+
|
58
58
|
desc "Install the gem locally"
|
59
|
-
task :install => [:package] do
|
59
|
+
task :install => [:manifest, :package] do
|
60
60
|
sh %{gem install pkg/#{spec.name}-#{spec.version} --no-ri --no-rdoc}
|
61
61
|
end
|
62
62
|
|
@@ -78,6 +78,6 @@ task :test do
|
|
78
78
|
next unless File.extname(file) == ".rb"
|
79
79
|
next unless File.basename(file) =~ /test_/
|
80
80
|
next if File.basename(file) =~ /test_helper/
|
81
|
-
|
81
|
+
require file
|
82
82
|
end
|
83
83
|
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/lib/passport.rb
CHANGED
@@ -1,38 +1,22 @@
|
|
1
|
-
require '
|
2
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
require 'rack'
|
5
|
+
require 'json'
|
6
|
+
require 'yaml'
|
3
7
|
require 'oauth'
|
4
8
|
require 'oauth2'
|
5
9
|
|
6
|
-
this = File.dirname(__FILE__)
|
10
|
+
this = File.expand_path(File.dirname(__FILE__))
|
7
11
|
library = "#{this}/passport"
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
require "#{library}/passport"
|
12
|
-
require "#{library}/callback_filter"
|
13
|
-
require "#{library}/access_token"
|
14
|
-
require "#{library}/openid"
|
15
|
-
require "#{library}/oauth"
|
16
|
-
require "#{library}/common"
|
17
|
-
require "#{library}/engine" if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
18
|
-
|
19
|
-
custom_models = ["#{library}/access_token"]
|
20
|
-
custom_models += Dir["#{library}/oauth/tokens"]
|
21
|
-
custom_models += Dir["#{library}/openid/tokens"]
|
13
|
+
Dir["#{library}/helpers/*"].each { |file| require file }
|
14
|
+
Dir["#{library}/core/*"].each { |file| require file }
|
22
15
|
|
23
|
-
#
|
24
|
-
|
16
|
+
require "#{library}/openid/protocol"
|
17
|
+
require "#{library}/engine" if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
ActiveSupport::Dependencies.send(load_path_method) << path
|
29
|
-
end
|
19
|
+
# require "#{library}/openid"
|
20
|
+
require "#{library}/passport"
|
30
21
|
|
31
|
-
|
32
|
-
if defined?(ActiveSupport::HashWithIndifferentAccess)
|
33
|
-
ActiveSupport::HashWithIndifferentAccess.class_eval do
|
34
|
-
def symbolize_keys!
|
35
|
-
symbolize_keys
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
22
|
+
Passport.root = "#{this}/.."
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Passport
|
2
|
+
module Certification
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def process?
|
9
|
+
Passport::Oauth::Protocol.request?# || Passport::OpenId::Protocol.start?
|
10
|
+
end
|
11
|
+
alias start? process?
|
12
|
+
|
13
|
+
def process(user = nil)
|
14
|
+
protocol.process(user) if protocol
|
15
|
+
end
|
16
|
+
alias start process
|
17
|
+
|
18
|
+
def approve?
|
19
|
+
Passport::Oauth::Protocol.response? # || Passport::OpenId::Protocol.complete?
|
20
|
+
end
|
21
|
+
alias complete? approve?
|
22
|
+
|
23
|
+
def approve(user = nil)
|
24
|
+
protocol.approve(user) if protocol
|
25
|
+
end
|
26
|
+
alias complete approve
|
27
|
+
|
28
|
+
def authenticate(user = nil, &block)
|
29
|
+
if process?
|
30
|
+
process(user) # redirect to service
|
31
|
+
elsif approve?
|
32
|
+
token = approve(user)
|
33
|
+
yield(token) if block_given?
|
34
|
+
token
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def protocol
|
39
|
+
if Passport::Oauth::Protocol.active?
|
40
|
+
Passport::Oauth::Protocol
|
41
|
+
# elsif Passport::OpenId::Protocol.using?
|
42
|
+
#Passport::OpenId::Protocol
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Passport
|
2
|
+
module Context
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def find(key)
|
9
|
+
Rack::Context.find(key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def session
|
13
|
+
Rack::Context.session
|
14
|
+
end
|
15
|
+
|
16
|
+
def session_key(key)
|
17
|
+
Rack::Context.session_key(key)
|
18
|
+
end
|
19
|
+
|
20
|
+
def params
|
21
|
+
Rack::Context.params
|
22
|
+
end
|
23
|
+
|
24
|
+
def params_key(key)
|
25
|
+
Rack::Context.params_key(key)
|
26
|
+
end
|
27
|
+
|
28
|
+
def redirect(url)
|
29
|
+
if controller = Thread.current[:rails_context]
|
30
|
+
controller.redirect_to(url)
|
31
|
+
else
|
32
|
+
puts "REDIRECT #{url}"
|
33
|
+
response = Rack::Response.new
|
34
|
+
response.redirect(url)
|
35
|
+
response.finish
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# if we've said it's a "user" (registration), or a "session" (login)
|
40
|
+
def authentication_type
|
41
|
+
find(:authentication_type)
|
42
|
+
end
|
43
|
+
|
44
|
+
def authentication_method
|
45
|
+
find(:authentication_method)
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear
|
49
|
+
[:auth_request_class,
|
50
|
+
:authentication_type,
|
51
|
+
:auth_method,
|
52
|
+
:auth_attributes,
|
53
|
+
:oauth_provider,
|
54
|
+
:auth_callback_method
|
55
|
+
].each { |key| Rack::Context.delete_session_key(key) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def debug
|
59
|
+
puts "=== BEGIN DEBUG ==="
|
60
|
+
puts "Passport.process? #{Passport.process?}"
|
61
|
+
puts "Passport.approve? #{Passport.approve?}"
|
62
|
+
puts "Passport::Oauth::Protocol.request? #{Passport::Oauth::Protocol.request?.inspect}"
|
63
|
+
puts "Passport::Oauth::Protocol.params? #{Passport::Oauth::Protocol.params?.inspect}"
|
64
|
+
puts "Passport::Oauth::Protocol.provider? #{Passport::Oauth::Protocol.provider?.inspect}"
|
65
|
+
puts "Passport::Oauth::Protocol.response? #{Passport::Oauth::Protocol.response?.inspect}"
|
66
|
+
puts "Passport::Oauth::Protocol.session? #{Passport::Oauth::Protocol.session?.inspect}"
|
67
|
+
puts "Passport::Oauth::Protocol.token? #{Passport::Oauth::Protocol.token?.inspect}"
|
68
|
+
puts "Session #{session.inspect}"
|
69
|
+
puts "Params #{params.inspect}"
|
70
|
+
puts "=== END DEBUG ==="
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Passport
|
2
|
+
module Installation
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
attr_accessor :installed
|
9
|
+
|
10
|
+
def install
|
11
|
+
return if installed
|
12
|
+
|
13
|
+
require "#{root}/lib/passport/support/#{adapter}"
|
14
|
+
require "#{root}/lib/passport/oauth"
|
15
|
+
|
16
|
+
if defined?(Rails)
|
17
|
+
custom_models = ["#{root}/lib/passport/support/#{adapter}"] + Dir["#{root}/lib/passport/oauth/tokens"]
|
18
|
+
#custom_models += Dir["#{library}/openid/tokens"]
|
19
|
+
|
20
|
+
# Rails 3/2 config
|
21
|
+
load_path_method = ActiveSupport::Dependencies.respond_to?(:autoload_paths) ? :autoload_paths : :load_paths
|
22
|
+
|
23
|
+
custom_models.each do |path|
|
24
|
+
$LOAD_PATH << path
|
25
|
+
ActiveSupport::Dependencies.send(load_path_method) << path
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if defined?(ActionController::Base)
|
30
|
+
ActionController::Base.helper(Passport::Oauth::ViewHelper)
|
31
|
+
end
|
32
|
+
if defined?(ActionView::Helpers::FormBuilder)
|
33
|
+
ActionView::Helpers::FormBuilder.send(:include, Passport::Oauth::ViewHelper)
|
34
|
+
end
|
35
|
+
|
36
|
+
installed = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|