rails_openid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ *.gemspec
21
+
22
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 J. Pablo Fernández
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.rdoc ADDED
@@ -0,0 +1,85 @@
1
+ = Rails OpenId
2
+
3
+ Rails OpenId is a very small library that intends to abstract away a little bit
4
+ of ruby-openid to make it easier to use in Rails applications. It is a very
5
+ infant library, use at your own peril.
6
+
7
+ == Installation
8
+
9
+ This gem is provided through Gemcutter so you need to have gem configured to
10
+ pull gems from Gemcutter.
11
+
12
+ === Enabling Gemcutter
13
+
14
+ A properly configured environment would be like this:
15
+
16
+ $ gem sources
17
+ *** CURRENT SOURCES ***
18
+
19
+ http://gemcutter.org
20
+ http://gems.rubyforge.org/
21
+ http://gems.github.com
22
+
23
+ If you don't have http://gemcutter.org in your sources then you need to add. I
24
+ know two ways to do. One is installing Gemcutter and running gem tumble:
25
+
26
+ $ sudo gem install gemcutter
27
+ $ gem tumble
28
+
29
+ Be careful that gem tumble will remove Gemcutter from your repositories if it's
30
+ already there.
31
+
32
+ The other way is by hand like this:
33
+
34
+ $ gem source -a http://gemcutter.org
35
+
36
+ I'm not sure if there's any difference. I think there isn't one.
37
+
38
+ === Installing rails_openid manually
39
+
40
+ It's simple a matter of running:
41
+
42
+ $ gem install rails_openid
43
+
44
+ and that's it. Let me know if something breaks.
45
+
46
+ === Installing through your Ruby on Rails project
47
+
48
+ In the +environment.rb+ file of your Ruby on Rails project you'll have some
49
+ commented out lines like this:
50
+
51
+ # config.gem "bj"
52
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
53
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
54
+ # config.gem "aws-s3", :lib => "aws/s3"
55
+
56
+ After those you can just add
57
+
58
+ config.gem "rails_openid"
59
+
60
+ and then run
61
+
62
+ $ rake gems:install
63
+
64
+ and you'll get this and all the gems your Rails project need installed.
65
+ Configuring your Rails project like that is something you'll need anyway, so
66
+ this is my recommended way.
67
+
68
+ == API Documentation
69
+
70
+ Up to date api documentation should be automatically generated on
71
+ http://rdoc.info/projects/pupeno/rails_openid
72
+
73
+ == Note on Patches/Pull Requests
74
+
75
+ * Fork the project.
76
+ * Make your feature addition or bug fix.
77
+ * Add tests for it. This is important so I don't break it in a
78
+ future version unintentionally.
79
+ * Commit, do not mess with rakefile, version, or history.
80
+ (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)
81
+ * Send me a pull request. Bonus points for topic branches.
82
+
83
+ == Copyright
84
+
85
+ Copyright (c) 2009 J. Pablo Fernández. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rails_openid"
8
+ gem.summary = "ruby-openid wrappers to make it simpler for a rails app"
9
+ gem.description = "ruby-openid wrappers to make it simpler for a rails app"
10
+ gem.email = "pupeno@pupeno.com"
11
+ gem.homepage = "http://github.com/pupeno/rails_openid"
12
+ gem.authors = ["J. Pablo Fernández"]
13
+ #gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rails_openid #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,70 @@
1
+ require 'openid/extensions/sreg'
2
+ require 'openid/store/filesystem'
3
+
4
+ module RailsOpenId
5
+ def send_open_id_request(params, fallback, return_to, meta = [])
6
+ # Create the OpenID request, and in the process, verify the URI is valid.
7
+ identifier = params[:openid_identifier]
8
+ if identifier.blank?
9
+ flash[:error] = "Please, enter an OpenID identifier (that is, your OpenID address)."
10
+ redirect_to fallback
11
+ return
12
+ end
13
+
14
+ oidreq = consumer.begin(identifier)
15
+
16
+ if not meta.empty?
17
+ # Request email, nickname and fullname.
18
+ sregreq = OpenID::SReg::Request.new
19
+ sregreq.request_fields(meta, true)
20
+ oidreq.add_extension(sregreq)
21
+ oidreq.return_to_args['did_sreg'] = 'y'
22
+ end
23
+
24
+ if oidreq.send_redirect?(root_url, return_to)
25
+ redirect_to oidreq.redirect_url(root_url, return_to)
26
+ else
27
+ # This option is used if the request is too big to be sent in the URL, or something like, not very likely to happen I'd say.
28
+ # A way to force is to do this: oidreq.return_to_args['force_post']='x'*2048
29
+ render :text => oidreq.html_markup(root_url, root_url, :form_tag_attrs => {'id' => 'openid_form'})
30
+ end
31
+ rescue OpenID::OpenIDError => e
32
+ flash[:error] = "#{identifier} doesn't seem to be a valid, working OpenID. Maybe it has a typo?"
33
+ redirect_to fallback
34
+ return
35
+ end
36
+
37
+ def process_open_id_response(params, current_url, fallback)
38
+ parameters = params.reject {|k,v| request.path_parameters[k] }
39
+ oidresp = consumer.complete(parameters, current_url)
40
+
41
+ if oidresp.status == OpenID::Consumer::SUCCESS
42
+ data = nil
43
+ if params[:did_sreg]
44
+ sreg_resp = OpenID::SReg::Response.from_success_response(oidresp)
45
+ data = sreg_resp.data
46
+ end
47
+ return oidresp, data
48
+ else
49
+ # Possible non-succes statuses: OpenID::Consumer::FAILURE, OpenID::Consumer::SETUP_NEEDED, OpenID::Consumer::CANCEL
50
+ if not oidresp.display_identifier.blank?
51
+ flash[:error] = "We couldn't verify your OpenID #{oidresp.display_identifier}."
52
+ else
53
+ flash[:error] = "We couldn't verify your OpenID."
54
+ end
55
+ redirect_to fallback
56
+ return nil
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def consumer
63
+ if @consumer.nil?
64
+ dir = Pathname.new(RAILS_ROOT).join('db').join('cstore')
65
+ store = OpenID::Store::Filesystem.new(dir)
66
+ @consumer = OpenID::Consumer.new(session, store)
67
+ end
68
+ return @consumer
69
+ end
70
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rails_openid'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRailsOpenid < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_openid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "J. Pablo Fern\xC3\xA1ndez"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-29 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ruby-openid wrappers to make it simpler for a rails app
17
+ email: pupeno@pupeno.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/rails_openid.rb
33
+ - test/helper.rb
34
+ - test/test_rails-openid.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/pupeno/rails_openid
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: ruby-openid wrappers to make it simpler for a rails app
63
+ test_files:
64
+ - test/helper.rb
65
+ - test/test_rails-openid.rb