passport 0.0.1

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Lance Pollard (lancejpollard@gmail.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1 @@
1
+ # Passport
data/Rakefile ADDED
@@ -0,0 +1,83 @@
1
+ require 'rake'
2
+ require "rake/rdoctask"
3
+ require 'rake/gempackagetask'
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = "passport"
7
+ s.author = "Lance Pollard"
8
+ s.version = "0.0.1"
9
+ s.summary = "Passport: Oauth and OpenID made dead simple"
10
+ s.homepage = "http://github.com/viatropos/passport"
11
+ s.email = "lancejpollard@gmail.com"
12
+ s.description = "Oauth and OpenID made dead simple"
13
+ s.has_rdoc = true
14
+ s.rubyforge_project = "passport"
15
+ s.platform = Gem::Platform::RUBY
16
+ s.files = %w(README.markdown Rakefile init.rb MIT-LICENSE) + Dir["{lib,rails,test}/**/*"] - Dir["test/tmp"]
17
+ s.require_path = "lib"
18
+ s.add_dependency("activesupport", ">= 2.1.2")
19
+ s.add_dependency("activerecord", ">= 2.1.2")
20
+ s.add_dependency("json")
21
+ s.add_dependency("ruby-openid")
22
+ s.add_dependency("rack-openid", ">=0.2.1")
23
+ s.add_dependency("oauth")
24
+ s.add_dependency("oauth2")
25
+ end
26
+
27
+ Rake::GemPackageTask.new(spec) do |pkg|
28
+ pkg.gem_spec = spec
29
+ pkg.package_dir = "pkg"
30
+ end
31
+
32
+ desc "Create .gemspec file (useful for github)"
33
+ task :gemspec do
34
+ File.open("pkg/#{spec.name}.gemspec", "w") do |f|
35
+ f.puts spec.to_ruby
36
+ end
37
+ end
38
+
39
+ desc "Build the gem into the current directory"
40
+ task :gem => :gemspec do
41
+ `gem build pkg/#{spec.name}.gemspec`
42
+ end
43
+
44
+ desc "Publish gem to rubygems"
45
+ task :publish => [:package] do
46
+ %x[gem push pkg/#{spec.name}-#{spec.version}.gem]
47
+ end
48
+
49
+ desc "Print a list of the files to be put into the gem"
50
+ task :manifest do
51
+ File.open("Manifest", "w") do |f|
52
+ spec.files.each do |file|
53
+ f.puts file
54
+ end
55
+ end
56
+ end
57
+
58
+ desc "Install the gem locally"
59
+ task :install => [:package] do
60
+ sh %{gem install pkg/#{spec.name}-#{spec.version} --no-ri --no-rdoc}
61
+ end
62
+
63
+ desc "Generate the rdoc"
64
+ Rake::RDocTask.new do |rdoc|
65
+ files = ["README.markdown", "lib/**/*.rb"]
66
+ rdoc.rdoc_files.add(files)
67
+ rdoc.main = "README.markdown"
68
+ rdoc.title = spec.summary
69
+ end
70
+
71
+ task :yank do
72
+ `gem yank #{spec.name} -v #{spec.version}`
73
+ end
74
+
75
+ desc 'run unit tests'
76
+ task :test do
77
+ Dir["test/**/*"].each do |file|
78
+ next unless File.extname(file) == ".rb"
79
+ next unless File.basename(file) =~ /test_/
80
+ next if File.basename(file) =~ /test_helper/
81
+ system "ruby #{file}"
82
+ end
83
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ File.dirname(__FILE__) + "/rails/init.rb"
@@ -0,0 +1,127 @@
1
+ # copied from open_id_authentication plugin on github
2
+ require 'uri'
3
+ require 'openid'
4
+ require 'rack/openid'
5
+
6
+ module OpenIdAuthentication
7
+ def self.new(app)
8
+ store = OpenIdAuthentication.store
9
+ if store.nil?
10
+ Rails.logger.warn "OpenIdAuthentication.store is nil. Using in-memory store."
11
+ end
12
+
13
+ ::Rack::OpenID.new(app, OpenIdAuthentication.store)
14
+ end
15
+
16
+ def self.store
17
+ @@store
18
+ end
19
+
20
+ def self.store=(*store_option)
21
+ store, *parameters = *([ store_option ].flatten)
22
+
23
+ @@store = case store
24
+ when :memory
25
+ require 'openid/store/memory'
26
+ OpenID::Store::Memory.new
27
+ when :file
28
+ require 'openid/store/filesystem'
29
+ OpenID::Store::Filesystem.new(Rails.root.join('tmp/openids'))
30
+ when :memcache
31
+ require 'memcache'
32
+ require 'openid/store/memcache'
33
+ OpenID::Store::Memcache.new(MemCache.new(parameters))
34
+ else
35
+ store
36
+ end
37
+ end
38
+
39
+ self.store = nil
40
+
41
+ class Result
42
+ ERROR_MESSAGES = {
43
+ :missing => "Sorry, the OpenID server couldn't be found",
44
+ :invalid => "Sorry, but this does not appear to be a valid OpenID",
45
+ :canceled => "OpenID verification was canceled",
46
+ :failed => "OpenID verification failed",
47
+ :setup_needed => "OpenID verification needs setup"
48
+ }
49
+
50
+ def self.[](code)
51
+ new(code)
52
+ end
53
+
54
+ def initialize(code)
55
+ @code = code
56
+ end
57
+
58
+ def status
59
+ @code
60
+ end
61
+
62
+ ERROR_MESSAGES.keys.each { |state| define_method("#{state}?") { @code == state } }
63
+
64
+ def successful?
65
+ @code == :successful
66
+ end
67
+
68
+ def unsuccessful?
69
+ ERROR_MESSAGES.keys.include?(@code)
70
+ end
71
+
72
+ def message
73
+ ERROR_MESSAGES[@code]
74
+ end
75
+ end
76
+
77
+ protected
78
+ # The parameter name of "openid_identifier" is used rather than
79
+ # the Rails convention "open_id_identifier" because that's what
80
+ # the specification dictates in order to get browser auto-complete
81
+ # working across sites
82
+ def using_open_id?(identifier = nil) #:doc:
83
+ identifier ||= open_id_identifier
84
+ !identifier.blank? || request.env[Rack::OpenID::RESPONSE]
85
+ end
86
+
87
+ def authenticate_with_open_id(identifier = nil, options = {}, &block) #:doc:
88
+ identifier ||= open_id_identifier
89
+ if request.env[Rack::OpenID::RESPONSE]
90
+ complete_open_id_authentication(&block)
91
+ else
92
+ begin_open_id_authentication(identifier, options, &block)
93
+ end
94
+ end
95
+
96
+ private
97
+ def open_id_identifier
98
+ params[:openid_identifier] || params[:openid_url]
99
+ end
100
+
101
+ def begin_open_id_authentication(identifier, options = {})
102
+ options[:identifier] = identifier
103
+ value = Rack::OpenID.build_header(options)
104
+ response.headers[Rack::OpenID::AUTHENTICATE_HEADER] = value
105
+ head :unauthorized
106
+ end
107
+
108
+ def complete_open_id_authentication
109
+ response = request.env[Rack::OpenID::RESPONSE]
110
+ identifier = response.display_identifier
111
+ case response.status
112
+ when OpenID::Consumer::SUCCESS
113
+ yield Result[:successful], identifier,
114
+ OpenID::SReg::Response.from_success_response(response)
115
+ when :missing
116
+ yield Result[:missing], identifier, nil
117
+ when :invalid
118
+ yield Result[:invalid], identifier, nil
119
+ when OpenID::Consumer::CANCEL
120
+ yield Result[:canceled], identifier, nil
121
+ when OpenID::Consumer::FAILURE
122
+ yield Result[:failed], identifier, nil
123
+ when OpenID::Consumer::SETUP_NEEDED
124
+ yield Result[:setup_needed], response.setup_url, nil
125
+ end
126
+ end
127
+ end
data/lib/passport.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'active_record'
2
+ require "rubygems"
3
+ require 'oauth'
4
+ require 'oauth2'
5
+
6
+ this = File.dirname(__FILE__)
7
+ library = "#{this}/passport"
8
+
9
+ require "#{this}/open_id_authentication"
10
+ require "#{library}/ext"
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"]
22
+
23
+ # Rails 3/2 config
24
+ load_path_method = ActiveSupport::Dependencies.respond_to?(:autoload_paths) ? :autoload_paths : :load_paths
25
+
26
+ custom_models.each do |path|
27
+ $LOAD_PATH << path
28
+ ActiveSupport::Dependencies.send(load_path_method) << path
29
+ end
30
+
31
+ # Rails 3beta4 backport
32
+ if defined?(ActiveSupport::HashWithIndifferentAccess)
33
+ ActiveSupport::HashWithIndifferentAccess.class_eval do
34
+ def symbolize_keys!
35
+ symbolize_keys
36
+ end
37
+ end
38
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "passport"
2
+
3
+ # copied from open_id_authentication plugin on github
4
+
5
+ # this is the Rails 2.x equivalent.
6
+ # Rails 3 equivalent is in authlogic_connect/engine.rb
7
+ if Rails.version < '3'
8
+ config.gem 'rack-openid', :lib => 'rack/openid', :version => '>=0.2.1'
9
+ end
10
+
11
+ require 'open_id_authentication'
12
+
13
+ config.middleware.use OpenIdAuthentication
14
+ config.middleware.use Passport::CallbackFilter
15
+
16
+ config.after_initialize do
17
+ OpenID::Util.logger = Rails.logger
18
+ ActionController::Base.send :include, OpenIdAuthentication
19
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: passport
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Lance Pollard
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-14 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 1
33
+ - 2
34
+ version: 2.1.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activerecord
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 2
48
+ - 1
49
+ - 2
50
+ version: 2.1.2
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: json
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: ruby-openid
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :runtime
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: rack-openid
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 21
90
+ segments:
91
+ - 0
92
+ - 2
93
+ - 1
94
+ version: 0.2.1
95
+ type: :runtime
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: oauth
99
+ prerelease: false
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ type: :runtime
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ name: oauth2
113
+ prerelease: false
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ type: :runtime
124
+ version_requirements: *id007
125
+ description: Oauth and OpenID made dead simple
126
+ email: lancejpollard@gmail.com
127
+ executables: []
128
+
129
+ extensions: []
130
+
131
+ extra_rdoc_files: []
132
+
133
+ files:
134
+ - README.markdown
135
+ - Rakefile
136
+ - init.rb
137
+ - MIT-LICENSE
138
+ - lib/open_id_authentication.rb
139
+ - lib/passport.rb
140
+ - rails/init.rb
141
+ has_rdoc: true
142
+ homepage: http://github.com/viatropos/passport
143
+ licenses: []
144
+
145
+ post_install_message:
146
+ rdoc_options: []
147
+
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ requirements: []
169
+
170
+ rubyforge_project: passport
171
+ rubygems_version: 1.3.7
172
+ signing_key:
173
+ specification_version: 3
174
+ summary: "Passport: Oauth and OpenID made dead simple"
175
+ test_files: []
176
+