openid_fu_generator 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.
Files changed (49) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +48 -0
  4. data/README.txt +48 -0
  5. data/Rakefile +4 -0
  6. data/config/hoe.rb +72 -0
  7. data/config/requirements.rb +15 -0
  8. data/lib/openid_fu.rb +10 -0
  9. data/lib/openid_fu/association.rb +12 -0
  10. data/lib/openid_fu/controller_methods.rb +97 -0
  11. data/lib/openid_fu/nonce.rb +5 -0
  12. data/lib/openid_fu/openid_ar_store.rb +62 -0
  13. data/lib/openid_fu/openid_attribute_types.rb +79 -0
  14. data/lib/openid_fu/openid_ax_ext.rb +12 -0
  15. data/lib/openid_fu/openid_setting.rb +5 -0
  16. data/lib/openid_fu/version.rb +9 -0
  17. data/openid_fu_generator.rb +246 -0
  18. data/script/console +10 -0
  19. data/script/destroy +14 -0
  20. data/script/generate +14 -0
  21. data/script/txt2html +74 -0
  22. data/setup.rb +1585 -0
  23. data/tasks/deployment.rake +34 -0
  24. data/tasks/environment.rake +7 -0
  25. data/tasks/website.rake +17 -0
  26. data/templates/activation.html.erb +3 -0
  27. data/templates/authenticated_system.rb +155 -0
  28. data/templates/authenticated_test_helper.rb +94 -0
  29. data/templates/controller.rb +111 -0
  30. data/templates/fixtures.yml +15 -0
  31. data/templates/functional_test.rb +87 -0
  32. data/templates/helper.rb +2 -0
  33. data/templates/login.html.erb +20 -0
  34. data/templates/migration.rb +55 -0
  35. data/templates/model.rb +92 -0
  36. data/templates/model_controller.rb +30 -0
  37. data/templates/model_functional_test.rb +64 -0
  38. data/templates/model_helper.rb +2 -0
  39. data/templates/notifier.rb +25 -0
  40. data/templates/notifier_test.rb +31 -0
  41. data/templates/observer.rb +11 -0
  42. data/templates/open_id_form.html.erb +13 -0
  43. data/templates/restore_location.html.erb +30 -0
  44. data/templates/signup.html.erb +19 -0
  45. data/templates/signup_notification.html.erb +8 -0
  46. data/templates/unit_test.rb +94 -0
  47. data/test/test_helper.rb +4 -0
  48. data/test/test_openid_fu.rb +11 -0
  49. metadata +108 -0
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-04-13
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 FIXME full name
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/Manifest.txt ADDED
@@ -0,0 +1,48 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ openid_fu_generator.rb
7
+ templates/activation.html.erb
8
+ templates/authenticated_system.rb
9
+ templates/authenticated_test_helper.rb
10
+ templates/controller.rb
11
+ templates/fixtures.yml
12
+ templates/functional_test.rb
13
+ templates/helper.rb
14
+ templates/login.html.erb
15
+ templates/migration.rb
16
+ templates/model.rb
17
+ templates/model_controller.rb
18
+ templates/model_functional_test.rb
19
+ templates/model_helper.rb
20
+ templates/notifier.rb
21
+ templates/notifier_test.rb
22
+ templates/observer.rb
23
+ templates/open_id_form.html.erb
24
+ templates/restore_location.html.erb
25
+ templates/signup.html.erb
26
+ templates/signup_notification.html.erb
27
+ templates/unit_test.rb
28
+ config/hoe.rb
29
+ config/requirements.rb
30
+ lib/openid_fu.rb
31
+ lib/openid_fu/version.rb
32
+ lib/openid_fu/association.rb
33
+ lib/openid_fu/controller_methods.rb
34
+ lib/openid_fu/nonce.rb
35
+ lib/openid_fu/openid_ar_store.rb
36
+ lib/openid_fu/openid_attribute_types.rb
37
+ lib/openid_fu/openid_ax_ext.rb
38
+ lib/openid_fu/openid_setting.rb
39
+ script/console
40
+ script/destroy
41
+ script/generate
42
+ script/txt2html
43
+ setup.rb
44
+ tasks/deployment.rake
45
+ tasks/environment.rake
46
+ tasks/website.rake
47
+ test/test_helper.rb
48
+ test/test_openid_fu.rb
data/README.txt ADDED
@@ -0,0 +1,48 @@
1
+ = openid_fu
2
+
3
+ * http://rubyforge.org/projects/openid-fu/
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 Rakuto Furutani, Genki Takiuchi
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,72 @@
1
+ require 'openid_fu/version'
2
+
3
+ AUTHOR = ['Rakuto Furutani', 'Genki Takiuchi']
4
+ EMAIL = ['rakuto@gmail.com', 'genki@s21g.com']
5
+ DESCRIPTION = "description of gem"
6
+ GEM_NAME = 'openid_fu_generator' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'openid-fu' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = YAML.load(`svn info`)['Revision']
34
+ VERS = OpenidFu::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'openid_fu documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ #p.developer(AUTHOR, EMAIL)
52
+ p.author = AUTHOR
53
+ p.email = EMAIL
54
+ p.description = DESCRIPTION
55
+ p.summary = DESCRIPTION
56
+ p.url = HOMEPATH
57
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
58
+ p.test_globs = ["test/**/test_*.rb"]
59
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
60
+
61
+ # == Optional
62
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
63
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
64
+
65
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
66
+
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
data/lib/openid_fu.rb ADDED
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module OpenidFu
5
+
6
+ end
7
+
8
+ Dir.glob(File.join(File.dirname(__FILE__), 'openid_fu/**/*.rb')).each do |path|
9
+ require path
10
+ end
@@ -0,0 +1,12 @@
1
+ require 'openid/association'
2
+ require 'activerecord'
3
+
4
+ module OpenidFu
5
+ class Association < ActiveRecord::Base
6
+ set_table_name 'open_id_associations'
7
+
8
+ def from_record
9
+ OpenID::Association.new(handle, secret, issued, lifetime, assoc_type)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,97 @@
1
+ require 'pp'
2
+ require 'openid/yadis/discovery'
3
+ require 'openid/extensions/sreg'
4
+
5
+ module OpenidFu
6
+ module ControllerMethods
7
+ def self.included(base)
8
+ base.extend ClassMethods
9
+ base.class_eval do
10
+ verify :method => :post, :only => :begin,
11
+ :params => :open_id_claimed_id,
12
+ :redirect_to => {:action => 'new'}
13
+ verify :method => :get, :only => :complete,
14
+ :redirect_to => {:action => 'new'}
15
+ before_filter :prepare_begin_open_id_auth, :only => :begin
16
+ before_filter :prepare_complete_open_id_auth, :only => :complete
17
+ attr_reader :open_id_request
18
+ attr_reader :open_id_response
19
+ attr_reader :open_id_fields
20
+ cattr_accessor :open_id_consumer_options
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+ # Setup required attributes
26
+ def open_id_consumer(options={})
27
+ self.open_id_consumer_options = options
28
+ end
29
+ end
30
+
31
+ protected
32
+ # Initialize or obtain consumer object for OpenID
33
+ def consumer
34
+ @consumer ||= OpenID::Consumer.new(
35
+ session[:open_id_session] ||= {},
36
+ ActiveRecordStore.new)
37
+ end
38
+
39
+ def prepare_begin_open_id_auth
40
+ @open_id_request = consumer.begin(params[:open_id_claimed_id])
41
+
42
+ # Fetch Request to obtain personal identity
43
+ add_attribute_exchange_fields(@open_id_request)
44
+ end
45
+
46
+ def prepare_complete_open_id_auth
47
+ return_to = url_for :only_path => false, :action => 'complete'
48
+ parameters = params.reject{|k,v| request.path_parameters[k]}
49
+ @open_id_response = consumer.complete(parameters, return_to)
50
+ return unless open_id_response.status == OpenID::Consumer::SUCCESS
51
+
52
+ #endpoint = open_id_response.endpoint
53
+ #if OpenID.supports_ax?(endpoint)
54
+ # logger.debug "-----------" + open_id_response.message.inspect
55
+ # ax = OpenID::AX::FetchResponse.from_success_response(
56
+ # open_id_response)
57
+ # @open_id_fields = ax.get_extension_args
58
+ # logger.debug "***************** ax params ***************"
59
+ # logger.debug @open_id_fields.inspect
60
+ # logger.debug "***************** ax params ***************"
61
+ #elsif OpenID.supports_sreg?(endpoint)
62
+ @open_id_fields = open_id_response.extension_response('sreg', true)
63
+ logger.debug "***************** sreg params ***************"
64
+ logger.debug @open_id_fields.inspect
65
+ logger.debug "***************** sreg params ***************"
66
+ #end
67
+ end
68
+
69
+ private
70
+ def add_attribute_exchange_fields(oid_req)
71
+ #endpoint = oid_req.endpoint
72
+ #if OpenID.supports_ax?(endpoint)
73
+ # # required attributes
74
+ # ax_req = OpenID::AX::FetchRequest.new
75
+ # (open_id_consumer_options[:required] || []).each do |type|
76
+ # type_uri = OpenID::AX::AttrTypes.type_uri(type)
77
+ # if type_uri
78
+ # ax_attr = OpenID::AX::AttrInfo.new(type_uri)
79
+ # ax_attr.required = true
80
+ # logger.debug "*******" + ax_attr.inspect
81
+ # ax_req.add(ax_attr)
82
+ # else
83
+ # logger.warn "OpenID AX doesn't support #{type}"
84
+ # end
85
+ # end
86
+ # oid_req.add_extension(ax_req)
87
+ #elsif OpenID.supports_sreg?(endpoint)
88
+ open_id_consumer_options.keys.inject({}) do |params, key|
89
+ value = open_id_consumer_options[key]
90
+ value = value.collect {|v| v.to_s.strip} * ',' if
91
+ value.respond_to?(:collect)
92
+ oid_req.add_extension_arg('sreg', key.to_s, value.to_s)
93
+ end
94
+ #end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ module OpenidFu
2
+ class Nonce < ActiveRecord::Base
3
+ set_table_name 'open_id_nonces'
4
+ end
5
+ end
@@ -0,0 +1,62 @@
1
+ require 'openid_fu/association'
2
+ require 'openid_fu/nonce'
3
+ require 'openid/store/interface'
4
+
5
+ # not in OpenID module to avoid namespace conflict
6
+ module OpenidFu
7
+ class ActiveRecordStore < OpenID::Store::Interface
8
+ def store_association(server_url, assoc)
9
+ remove_association(server_url, assoc.handle)
10
+ Association.create(:server_url => server_url,
11
+ :handle => assoc.handle,
12
+ :secret => assoc.secret,
13
+ :issued => assoc.issued,
14
+ :lifetime => assoc.lifetime,
15
+ :assoc_type => assoc.assoc_type)
16
+ end
17
+
18
+ def get_association(server_url, handle=nil)
19
+ assocs = if handle.blank?
20
+ Association.find_all_by_server_url(server_url)
21
+ else
22
+ Association.find_all_by_server_url_and_handle(server_url, handle)
23
+ end
24
+
25
+ assocs.reverse.each do |assoc|
26
+ a = assoc.from_record
27
+ if a.expires_in == 0
28
+ assoc.destroy
29
+ else
30
+ return a
31
+ end
32
+ end if assocs.any?
33
+
34
+ return nil
35
+ end
36
+
37
+ def remove_association(server_url, handle)
38
+ Association.delete_all(['server_url = ? AND handle = ?',
39
+ server_url, handle]) > 0
40
+ end
41
+
42
+ def use_nonce(server_url, timestamp, salt)
43
+ return false if Nonce.find_by_server_url_and_timestamp_and_salt(
44
+ server_url, timestamp, salt)
45
+ return false if (timestamp - Time.now.to_i).abs > OpenID::Nonce.skew
46
+ Nonce.create(:server_url => server_url,
47
+ :timestamp => timestamp, :salt => salt)
48
+ return true
49
+ end
50
+
51
+ def cleanup_nonces
52
+ now = Time.now.to_i
53
+ Nonce.delete_all(["timestamp > ? OR timestamp < ?", now +
54
+ OpenID::Nonce.skew, now - OpenID::Nonce.skew])
55
+ end
56
+
57
+ def cleanup_associations
58
+ now = Time.now.to_i
59
+ Association.delete_all(['issued + lifetime > ?',now])
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,79 @@
1
+ module OpenID
2
+ module AX
3
+ module AttrTypes
4
+ BASE_NS_URI = 'http://schema.openid.net/types/'
5
+
6
+ TYPES = {
7
+ # Name
8
+ :nickname => 'namePerson/friendly',
9
+ :full_name => 'namePerson',
10
+ :name_prefix => 'namePerson/prefix',
11
+ :first_name => 'namePerson/first',
12
+ :last_name => 'namePerson/last',
13
+ :middle_name => 'namePerson/middle',
14
+ :name_suffix => 'namePerson/suffix',
15
+ :company_name => 'company/name',
16
+ :job_title => 'company/title',
17
+ :birth_date => 'birthDate',
18
+ :birth_year => 'birthDate/birthYear',
19
+ :birth_month => 'birthDate/birthMonth',
20
+ :birth_day => 'birthDate/birthday',
21
+ :phone => 'phone/default',
22
+ :phone_home => 'phone/home',
23
+ :phone_business => 'phone/business',
24
+ :phone_mobile => 'phone/cell',
25
+ :phone_fax => 'phone/fax',
26
+ # Address
27
+ :address => 'contact/postalAddress/home',
28
+ :address2 => 'contact/postalAddressAdditional/home',
29
+ :city => 'contact/city/home',
30
+ :state => 'contact/state/home',
31
+ :country => 'contact/country/home',
32
+ :postal_code => 'contact/postalCode/home',
33
+ :business_address => 'contact/postalAddress/business',
34
+ :business_address2 => 'contact/postalAddressAdditional/business',
35
+ :business_city => 'contact/city/business',
36
+ :business_state => 'contact/state/business',
37
+ :business_country => 'contact/country/business',
38
+ :business_code => 'contact/postalCode/business',
39
+ # Email
40
+ :email => 'contact/email',
41
+ # IM
42
+ :aol_im => 'contact/IM/AIM',
43
+ :icq_im => 'contact/IM/ICQ',
44
+ :msn_im => 'contact/IM/MSN',
45
+ :yahoo_im => 'contact/IM/Yahoo',
46
+ :jabber_im => 'IM/Jabber',
47
+ :skype_im => 'contact/IM/Skype',
48
+ # Web Sites
49
+ :web => 'contact/web/default',
50
+ :blog => 'contact/web/blog',
51
+ :linkedin_url => 'contact/web/Linkedin',
52
+ :amazon_url => 'contact/web/Amazon',
53
+ :flickr_url => 'contact/web/Flickr',
54
+ :del_icio_us_url => 'contact/web/Delicious',
55
+ # Audio / Video Greetings
56
+ :spoken_name => 'media/spokenname',
57
+ :audio_greeting => 'media/greeting/audio',
58
+ :video_greeting => 'media/greeting/video',
59
+ # Image
60
+ :image => 'media/image/default',
61
+ :square_image => 'media/image/aspect11',
62
+ :aspect43_image => 'media/image/aspect43',
63
+ :aspect34_image => 'media/image/aspect34',
64
+ :favicon_image => 'media/image/favicon',
65
+ # Other Personal Details /P Preferences
66
+ :gender => 'person/gender',
67
+ :lanugage => 'pref/language',
68
+ :timezone => 'pref/timezone',
69
+ :biography => 'media/biography'
70
+ }
71
+
72
+ # Convinience method for Type URI
73
+ def self.type_uri(key)
74
+ return nil unless TYPES.key?(key)
75
+ BASE_NS_URI + TYPES[key]
76
+ end
77
+ end
78
+ end
79
+ end