easy-rack-open-id 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Manifest
2
- pkg/*
2
+ pkg/*
3
+ vendor/*
data/README.rdoc CHANGED
@@ -5,27 +5,30 @@ gem install easy-rack-open-id
5
5
  (depends on rack-openid which depends on ruby-openid)
6
6
 
7
7
  Then, you:
8
- require 'rack/openid'
9
- use Rack::Session::Cookie
10
- use Rack::OpenID
11
- use EasyRackOpenID, :allowed_identifiers => ['http://example.com/']
12
- run lambda {|env| [ 200, { 'Content-Type' => 'text/plain' }, [ 'Authenticated!' ] ] }
8
+ require 'rack/openid'
9
+ use Rack::Session::Cookie
10
+ use Rack::OpenID
11
+ use EasyRackOpenID, :allowed_identifiers => ['http://example.com/']
12
+ run lambda {|env| [ 200, { 'Content-Type' => 'text/plain' }, [ 'Authenticated!' ] ] }
13
13
 
14
14
  There's an example in config.ru
15
15
 
16
16
 
17
- Basically, slap EasyRackOpenID in front of the App you want to protect. Rack::OpenID needs to be above it.
17
+ Basically, slap EasyRackOpenID in front of the App you want to protect. Rack::OpenID needs to be above it. Data from the login (identifier, registration info) will be made available in session[:verified_identity]
18
+
19
+ session['verified_identity']['identifier'] # http://samsm.com/
20
+ session['verified_identity']['nickname'] # samsm
18
21
 
19
22
  == OpenID stores
20
23
 
21
24
  OpenID needs some storage to remember cryptographic nuts and bolts. Rack:OpenID with no arguments uses an in memory OpenID store. This is ok for trying out with rackup, but won't work in a variety of scenarios including using shotgun and multiple servers. You can pass it a different store like so:
22
25
 
23
- require 'openid_mongodb_store' # http://github.com/samsm/openid_mongodb_store
24
- MongoMapper.database = 'testorama'
25
- MongoMapper.database.authorize('username','password')
26
- use Rack::OpenID, OpenidMongodbStore::Store.new
26
+ require 'openid_mongodb_store' # http://github.com/samsm/openid_mongodb_store
27
+ MongoMapper.database = 'testorama'
28
+ MongoMapper.database.authorize('username','password')
29
+ use Rack::OpenID, OpenidMongodbStore::Store.new
27
30
 
28
- == Options
31
+ == Too Many Options!
29
32
 
30
33
  With no arguments, EasyRackOpenID will only allow users with a verified OpenID to proceed. It won't care what that identity is.
31
34
 
@@ -35,13 +38,23 @@ With no arguments, EasyRackOpenID will only allow users with a verified OpenID t
35
38
 
36
39
  Right now allowed_identifiers and identity_match cannot both be used at once.
37
40
 
38
- :default_return_to (optional) is a path just in case the automatic return_to mysteriously vanishes. Unlikely.
41
+ :default_return_to is a path just in case the automatic return_to mysteriously vanishes. Unlikely.
42
+
43
+ :login_path is where to send a user if login fails. Perhaps a login form?
44
+
45
+ :logout_path (defaults to /logout) path that, when visited will clear the login session.
46
+
47
+ :after_logout_path After a user logs out, send them here (don't want the user sitting on the logout path).
48
+
49
+ :form picks which style of openid form is used for login. Choose from 'boring', 'selector', and 'real-selector' (default).
50
+
51
+ == Registration options
39
52
 
40
- :login_path (optional) is where to send a user if login fails. Perhaps a login form?
53
+ :required an array of what simple registration/attribute exchange details you want to fetch about a person.
41
54
 
42
- :logout_path (optional, defaults to /logout) path that, when visited will clear the login session
55
+ :optional like above, registration
43
56
 
44
- :after_logout_path (optional) After a user logs out, send them here. (don't want the user sitting on the logout path)
57
+ :policy_url
45
58
 
46
- == OpenID Selector
47
- This package includes a pretty default login form from the "openid-selector" project. This gem will serve the necessary javascript/images, but it may be more efficient to copy public/easy-rack-openid-assets into your application's public directory so that Apache/Nginx/whatever can serve those file directly.
59
+ == OpenID Selector, Real-selector
60
+ This package includes nice-looking default login forms from the "openid-selector" and "real-openid-selector" projects. This gem will serve the necessary javascript/images, but it may be more efficient to copy public/easy-rack-openid-assets into your application's public directory so that Apache/Nginx/whatever can serve those file directly.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/config.ru CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rack'
3
- require 'rack/openid'
3
+ # require 'rack/openid'
4
+ require 'vendor/rack-openid/lib/rack/openid'
4
5
  require 'lib/easy_rack_open_id'
5
6
 
6
7
  use Rack::ShowExceptions
@@ -14,8 +15,9 @@ end
14
15
 
15
16
  # require 'openid_mongodb_store'
16
17
  # MongoMapper.database = 'testorama'
18
+ puts "Remember shotgun won't work with memory store!"
17
19
 
18
20
  use Rack::Session::Cookie
19
21
  use Rack::OpenID #, OpenidMongodbStore::Store.new
20
- use EasyRackOpenID, :allowed_identifiers => ['http://example.com/'], :after_logout_path => '/login'
22
+ use EasyRackOpenID, :allowed_identifiers => ['http://samsm.com/'], :after_logout_path => '/login', :required => ['nickname']
21
23
  run HelloWorld.new
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{easy-rack-open-id}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sam Schenkman-Moore"]
12
+ s.date = %q{2009-12-20}
13
+ s.description = %q{You supply OpenIDs, this keeps anyone but people with access to those ids from getting through. You don't even have to make a form. :)}
14
+ s.email = %q{samsm@samsm.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "config.ru",
24
+ "easy-rack-open-id.gemspec",
25
+ "lib/easy_rack_open_id.rb",
26
+ "lib/easy_rack_open_id_processing.rb",
27
+ "lib/generic_openid_form.html.erb",
28
+ "lib/nice_openid_form.html.erb",
29
+ "lib/nicer_openid_form.html.erb",
30
+ "public/easy-rack-openid-assets/openid-realselector/css/style.css",
31
+ "public/easy-rack-openid-assets/openid-realselector/demo.html",
32
+ "public/easy-rack-openid-assets/openid-realselector/img/balloon.png",
33
+ "public/easy-rack-openid-assets/openid-realselector/img/indicator.gif",
34
+ "public/easy-rack-openid-assets/openid-realselector/img/openid-icons.png",
35
+ "public/easy-rack-openid-assets/openid-realselector/js/jquery.openid.js",
36
+ "public/easy-rack-openid-assets/openid-realselector/js/jquery.openid.min.js",
37
+ "public/easy-rack-openid-assets/openid-selector/css/openid.css",
38
+ "public/easy-rack-openid-assets/openid-selector/demo.html",
39
+ "public/easy-rack-openid-assets/openid-selector/images/aol.gif",
40
+ "public/easy-rack-openid-assets/openid-selector/images/blogger.ico",
41
+ "public/easy-rack-openid-assets/openid-selector/images/claimid.ico",
42
+ "public/easy-rack-openid-assets/openid-selector/images/facebook.gif",
43
+ "public/easy-rack-openid-assets/openid-selector/images/flickr.ico",
44
+ "public/easy-rack-openid-assets/openid-selector/images/google.gif",
45
+ "public/easy-rack-openid-assets/openid-selector/images/livejournal.ico",
46
+ "public/easy-rack-openid-assets/openid-selector/images/myopenid.ico",
47
+ "public/easy-rack-openid-assets/openid-selector/images/openid-inputicon.gif",
48
+ "public/easy-rack-openid-assets/openid-selector/images/openid.gif",
49
+ "public/easy-rack-openid-assets/openid-selector/images/technorati.ico",
50
+ "public/easy-rack-openid-assets/openid-selector/images/verisign.ico",
51
+ "public/easy-rack-openid-assets/openid-selector/images/vidoop.ico",
52
+ "public/easy-rack-openid-assets/openid-selector/images/wordpress.ico",
53
+ "public/easy-rack-openid-assets/openid-selector/images/yahoo.gif",
54
+ "public/easy-rack-openid-assets/openid-selector/js/jquery-1.2.6.min.js",
55
+ "public/easy-rack-openid-assets/openid-selector/js/openid-jquery.js"
56
+ ]
57
+ s.homepage = %q{http://github.com/samsm/Easy-Rack-OpenID}
58
+ s.rdoc_options = ["--charset=UTF-8"]
59
+ s.require_paths = ["lib"]
60
+ s.rubygems_version = %q{1.3.5}
61
+ s.summary = %q{Super easy OpenID protection for Rack.}
62
+
63
+ if s.respond_to? :specification_version then
64
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
65
+ s.specification_version = 3
66
+
67
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
68
+ s.add_development_dependency(%q<yard>, [">= 0"])
69
+ s.add_runtime_dependency(%q<rack-openid>, [">= 0"])
70
+ else
71
+ s.add_dependency(%q<yard>, [">= 0"])
72
+ s.add_dependency(%q<rack-openid>, [">= 0"])
73
+ end
74
+ else
75
+ s.add_dependency(%q<yard>, [">= 0"])
76
+ s.add_dependency(%q<rack-openid>, [">= 0"])
77
+ end
78
+ end
79
+
@@ -14,7 +14,7 @@ class EasyRackOpenIDProcessing
14
14
  return logout_result if logout_result
15
15
  end
16
16
  if asset?
17
- content_type_lookup = {'css' => 'text/css','html'=> 'text/html','js'=>'text/javascript','gif'=>'image/gif','ico' => 'image/vnd.microsoft.icon'}
17
+ content_type_lookup = {'css' => 'text/css','html'=> 'text/html','js'=>'text/javascript','gif'=>'image/gif','ico' => 'image/vnd.microsoft.icon', 'png'=> 'image/png'}
18
18
  ok(IO.read(gem_public_path + path), content_type_lookup[File.extname(path)[1..-1]])
19
19
  elsif allowed?
20
20
  # pass through
@@ -41,21 +41,36 @@ class EasyRackOpenIDProcessing
41
41
  if resp = env["rack.openid.response"]
42
42
  case resp.status
43
43
  when :success
44
- #... save id and forward to ...
45
- self.verified_identity = resp.identity_url
44
+
45
+ # Load in any registration data gathered
46
+ profile_data = {}
47
+ # merge the SReg data and the AX data into a single hash of profile data
48
+ [ OpenID::SReg::Response, OpenID::AX::FetchResponse ].each do |data_response|
49
+ if data_response.from_success_response( resp )
50
+ profile_data.merge! data_response.from_success_response( resp ).data
51
+ end
52
+ end
53
+
54
+ profile_data['identifier'] = resp.identity_url
55
+ # require 'ruby-debug' ; debugger
56
+ #... save id and registration and forward to ...
57
+ self.verified_identity = profile_data
46
58
  forward_to(protected_path)
47
59
  when :failure
48
60
  present_login_options
49
61
  end
50
62
  else
51
- if identitifier_to_verify
63
+ if identitifier_to_verify && valid_identifier?
52
64
  self.protected_path = path
53
- [401, {"WWW-Authenticate" => "OpenID identifier=\"#{identitifier_to_verify}\""}, []]
65
+ header_hash = {:identifier => identitifier_to_verify}
66
+ header_hash.merge!(:required => options[:required]) if options[:required]
67
+ header_hash.merge!(:required => options[:optional]) if options[:optional]
68
+ header_hash.merge!(:required => options[:policy_url]) if options[:policy_url]
69
+ [401, {"WWW-Authenticate" => Rack::OpenID.build_header(header_hash)}, []]
54
70
  else
55
71
  present_login_options
56
72
  end
57
73
  end
58
-
59
74
  end
60
75
 
61
76
  def path
@@ -67,8 +82,14 @@ class EasyRackOpenIDProcessing
67
82
  forward_to(login_path)
68
83
  else
69
84
  dir = File.dirname(__FILE__)
70
- # form = IO.read(dir + '/generic_openid_form.html.erb')
71
- form = IO.read(dir + '/nice_openid_form.html.erb')
85
+ form = case options[:form]
86
+ when 'boring'
87
+ IO.read(dir + '/generic_openid_form.html.erb')
88
+ when 'selector'
89
+ IO.read(dir + '/nice_openid_form.html.erb')
90
+ else # use default, real-openid selector
91
+ IO.read(dir + '/nicer_openid_form.html.erb')
92
+ end
72
93
  ok(form)
73
94
  end
74
95
  end
@@ -79,11 +100,11 @@ class EasyRackOpenIDProcessing
79
100
 
80
101
  def allowed?
81
102
  if allowed_identifiers
82
- allowed_identifiers.include? verified_identity
103
+ allowed_identifiers.include? verified_identifier
83
104
  elsif identity_match
84
- identity_match === verified_identity
105
+ identity_match === verified_identifier
85
106
  else
86
- verified_identity
107
+ verified_identifier
87
108
  end
88
109
  end
89
110
 
@@ -115,17 +136,42 @@ class EasyRackOpenIDProcessing
115
136
  end
116
137
 
117
138
  def identitifier_to_verify
118
- env["rack.request.query_hash"]["openid_identifier"]
139
+ @identitifier_to_verify ||=
140
+ if env["rack.request.query_hash"] && env["rack.request.query_hash"]["openid_identifier"]
141
+ env["rack.request.query_hash"]["openid_identifier"]
142
+ elsif posted_data = CGI.parse(env['rack.input'].read)
143
+ env['rack.input'].rewind
144
+ identifier = posted_data['openid_identifier']
145
+ if identifier.kind_of? Array
146
+ identifier.last
147
+ else
148
+ identifier
149
+ end
150
+ end
119
151
  end
120
152
 
121
- def verified_identity=(url)
122
- session['verified_identity'] = url
153
+ def valid_identifier?
154
+ uri = URI.parse(identitifier_to_verify.to_s.strip)
155
+ uri = URI.parse("http://#{uri}") unless uri.scheme
156
+ uri.scheme = uri.scheme.downcase # URI should do this
157
+ uri.normalize.to_s
158
+ rescue URI::InvalidURIError
159
+ # raise InvalidOpenId.new("#{url} is not an OpenID URL")
160
+ false
161
+ end
162
+
163
+ def verified_identity=(hash)
164
+ session['verified_identity'] = hash
123
165
  end
124
166
 
125
167
  def verified_identity
126
168
  session['verified_identity']
127
169
  end
128
170
 
171
+ def verified_identifier
172
+ verified_identity && verified_identity['identifier']
173
+ end
174
+
129
175
  def session
130
176
  env['rack.session']
131
177
  end
@@ -0,0 +1,36 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6
+ <title>Log In</title>
7
+ <link rel="stylesheet" href="/easy-rack-openid-assets/openid-realselector/css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
9
+ <script type="text/javascript" src="/easy-rack-openid-assets/openid-realselector/js/jquery.openid.js"></script>
10
+ <script type="text/javascript"><!--//
11
+ $(function() {
12
+ $('#openid').openid({
13
+ img_path: '{{ MEDIA_URL }}img/openid/' //,
14
+ // txt: {
15
+ // label: 'Ingresá tu {username} de <b>{provider}</b>',
16
+ // username: 'usuario',
17
+ // title: 'Seleccioná la página donde tengas una cuenta.',
18
+ // sign: 'Ir'
19
+ // }
20
+ });
21
+ });
22
+ //--></script>
23
+ </head>
24
+ <body>
25
+ <h2>Log in with OpenID</h2>
26
+ <p>Click the icon of the account you want to use, or enter your OpenID if you know it.</p>
27
+ <br/>
28
+
29
+ <form method="post" action="." id="openid">
30
+ <noscript>
31
+ <input id="openid_identifier" name="openid_identifier" type="text" value="http://" />
32
+ <input id="openid_submit" type="submit" value="Sign-In"/>
33
+ </noscript>
34
+ </form>
35
+ </body>
36
+ </html>
@@ -0,0 +1,75 @@
1
+ body {
2
+ font: 14px 'Arial';
3
+ }
4
+
5
+ #openid {
6
+ background: url(../img/indicator.gif) center center no-repeat;
7
+ margin: 0 auto;
8
+ width: 440px;
9
+ height: 162px;
10
+ }
11
+
12
+ #openid_inputarea {
13
+ clear: both;
14
+ display: none;
15
+ background: url(../img/balloon.png) no-repeat;
16
+ width: 410px;
17
+ height: 48px;
18
+ color: white;
19
+ text-align: center;
20
+ margin-top: 35px;
21
+ padding-top: 17px;
22
+ }
23
+
24
+ #openid_inputarea #openid_username {
25
+ margin: 0 4px 0 8px;
26
+ width: 120px;
27
+ }
28
+
29
+ #openid_btns, #openid_btns br {
30
+ clear: both;
31
+ }
32
+
33
+ #openid_highlight {
34
+ -moz-border-radius: 10px;
35
+ -webkit-border-radius: 10px;
36
+ padding: 2px;
37
+ background-color: #FFFCC9;
38
+ float: left;
39
+ }
40
+
41
+ .openid_large_btn, .openid_small_btn {
42
+ background: url(../img/openid-icons.png) no-repeat;
43
+ margin: 3px;
44
+ float: left;
45
+ }
46
+
47
+ .openid_large_btn {
48
+ width: 91px;
49
+ height: 51px;
50
+ }
51
+
52
+ .openid_small_btn {
53
+ width: 16px;
54
+ height: 16px;
55
+ }
56
+
57
+ .Google { background-position: 0 0; }
58
+ .Yahoo { background-position: 0 -51px; }
59
+ .AOL { background-position: 0 -102px; }
60
+ .OpenID { background-position: 0 -153px; }
61
+ .MyOpenID { background-position: 0 -204px; }
62
+ .Flickr { background-position: 0 -220px; }
63
+ .Technorati { background-position: -17px -220px; }
64
+ .Wordpress { background-position: -17px -204px; }
65
+ .Blogger { background-position: -34px -204px; }
66
+ .Verisign { background-position: -51px -220px; }
67
+ .Vidoop { background-position: -34px -220px; }
68
+ .ClaimID { background-position: -68px -204px; }
69
+ .LiveJournal { background-position: -51px -204px; }
70
+ .MySpace { background-position: -68px -220px; }
71
+
72
+ a.openid_large_btn:focus {
73
+ outline: none;
74
+ -moz-outline-style: none;
75
+ }
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6
+ <title>demo openID real selector</title>
7
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
9
+ <script type="text/javascript" src="js/jquery.openid.js"></script>
10
+ <script type="text/javascript"><!--//
11
+ $(function() {
12
+ $('#openid').openid({
13
+ img_path: '{{ MEDIA_URL }}img/openid/',
14
+ txt: {
15
+ label: 'Ingresá tu {username} de <b>{provider}</b>',
16
+ username: 'usuario',
17
+ title: 'Seleccioná la página donde tengas una cuenta.',
18
+ sign: 'Ir'
19
+ }
20
+ });
21
+ });
22
+ //--></script>
23
+ </head>
24
+ <body>
25
+ <form method="post" action="." id="openid"></form>
26
+ </body>
27
+ </html>
@@ -0,0 +1,181 @@
1
+ /*
2
+ OpenID Plugin
3
+ http://code.google.com/p/openid-realselector/
4
+
5
+ Martin Conte Mac Donell <Reflejo@gmail.com>
6
+ */
7
+
8
+ (function($) {
9
+ $.fn.openid = function(opt) {
10
+ var gprovider;
11
+ var INPUTID = 'openid_username';
12
+ var inputarea = $('#openid_inputarea').length ? $('#openid_inputarea'): $('<div id="openid_inputarea" />');
13
+
14
+ var defaults = {
15
+ txt: {
16
+ label: 'Enter your {provider} {username}',
17
+ username: 'username',
18
+ title: 'Select your openID provider',
19
+ sign: 'Sign-In'
20
+ },
21
+ /*
22
+ Default providers with url. "big" variable means that icon
23
+ will be big.
24
+ */
25
+ providers: [
26
+ {
27
+ name: 'Google',
28
+ url: 'https://www.google.com/accounts/o8/id',
29
+ label: null,
30
+ big: true
31
+ },
32
+ {
33
+ name: 'Yahoo',
34
+ url: 'http://yahoo.com/',
35
+ label: null,
36
+ big: true
37
+ },
38
+ {
39
+ name: 'AOL',
40
+ username_txt: 'screenname',
41
+ url: 'http://openid.aol.com/{username}',
42
+ big: true
43
+ },
44
+ {
45
+ name: 'OpenID',
46
+ username_txt: 'url',
47
+ big: true
48
+ },
49
+ {
50
+ name: 'MyOpenID',
51
+ url: 'http://{username}.myopenid.com/'
52
+ },
53
+ {
54
+ name: 'Flickr',
55
+ url: 'http://flickr.com/{username}/'
56
+ },
57
+ {
58
+ name: 'Technorati',
59
+ url: 'http://technorati.com/people/technorati/{username}/'
60
+ },
61
+ {
62
+ name: 'Wordpress',
63
+ url: 'http://{username}.wordpress.com/'
64
+ },
65
+ {
66
+ name: 'Blogger',
67
+ url: 'http://{username}.blogspot.com/'
68
+ },
69
+ {
70
+ name: 'Verisign',
71
+ url: 'http://{username}.pip.verisignlabs.com/'
72
+ },
73
+ {
74
+ name: 'Vidoop',
75
+ url: 'http://{username}.myvidoop.com/'
76
+ },
77
+ {
78
+ name: 'ClaimID',
79
+ url: 'http://claimid.com/{username}'
80
+ },
81
+ {
82
+ name: 'LiveJournal',
83
+ url: 'http://{username}.livejournal.com'
84
+ },
85
+ {
86
+ name: 'MySpace',
87
+ url: 'http://www.myspace.com/{username}'
88
+ }
89
+ ],
90
+ cookie_expires: 6 * 30, // in days.
91
+ cookie_path: '/',
92
+ img_path: '/img/'
93
+ };
94
+
95
+ var getBox = function(provider, idx, box_size) {
96
+ var a = $('<a title="' + provider + '" href="#" id="btn_' + idx +
97
+ '" class="openid_' + box_size + '_btn ' + provider + '" />');
98
+ return a.click(signIn);
99
+ };
100
+
101
+ var setCookie = function(value) {
102
+ var date = new Date();
103
+ date.setTime(date.getTime() + (settings.cookie_expires * 24 * 60 * 60 * 1000));
104
+ document.cookie = "openid_prov=" + value + "; expires=" + date.toGMTString() +
105
+ "; path=" + settings.cookie_path;
106
+ };
107
+
108
+ var readCookie = function(){
109
+ var c = document.cookie.split(';');
110
+ for(i in c){
111
+ if ((pos = c[i].indexOf("openid_prov=")) != -1)
112
+ return $.trim(c[i].slice(pos + 12));
113
+ }
114
+ };
115
+
116
+ var signIn = function(obj, tidx) {
117
+ var idx = $(tidx || this).attr('id').replace('btn_', '');
118
+ if (!(gprovider = settings.providers[idx]))
119
+ return;
120
+
121
+ // Hightlight
122
+ if (highlight = $('#openid_highlight'))
123
+ highlight.replaceWith($('#openid_highlight a')[0]);
124
+
125
+ $('#btn_' + idx).wrap('<div id="openid_highlight" />');
126
+ setCookie(idx);
127
+
128
+ // prompt user for input?
129
+ showInputBox();
130
+ if (gprovider.label === null) {
131
+ inputarea.text(settings.txt.title);
132
+ if (!tidx) {
133
+ inputarea.fadeOut();
134
+ form.submit();
135
+ }
136
+ }
137
+ return false;
138
+ };
139
+
140
+ var showInputBox = function() {
141
+ var lbl = (gprovider.label || settings.txt.label).replace(
142
+ '{username}', (gprovider.username_txt !== undefined) ? gprovider.username_txt: settings.txt.username
143
+ ).replace('{provider}', gprovider.name);
144
+
145
+ inputarea.empty().show().append('<span class="oidlabel">' + lbl + '</span><input id="' + INPUTID + '" type="text" ' +
146
+ ' name="username_txt" class="Verisign"/><input type="submit" value="' + settings.txt.sign + '"/>');
147
+
148
+ $('#' + INPUTID).focus();
149
+ };
150
+
151
+ var submit = function(){
152
+ var prov = (gprovider.url) ? gprovider.url.replace('{username}', $('#' + INPUTID).val()): $('#' + INPUTID).val();
153
+ form.append($('<input type="hidden" name="openid_identifier" value="' + prov + '" />'));
154
+ };
155
+
156
+ var settings = $.extend(defaults, opt || {});
157
+ var btns = $('<div id="openid_btns" />');
158
+
159
+ // Add box for each provider
160
+ var addbr = true;
161
+ $.each(settings.providers, function(i, val) {
162
+ if (!val.big && addbr) {
163
+ btns.append('<br />');
164
+ addbr = false;
165
+ }
166
+ btns.append(getBox(val.name, i, (val.big) ? 'large': 'small'));
167
+ });
168
+
169
+ var form = this;
170
+ form.css({'background-image': 'none'});
171
+ form.append(btns).submit(submit);
172
+ btns.append(inputarea);
173
+
174
+ if (idx = readCookie())
175
+ signIn(null, '#btn_' + idx);
176
+ else
177
+ inputarea.text(settings.txt.title).show();
178
+
179
+ return this;
180
+ };
181
+ })(jQuery);
@@ -0,0 +1,7 @@
1
+ /*
2
+ OpenID Plugin
3
+ http://code.google.com/p/openid-realselector/
4
+
5
+ Martin Conte Mac Donell <Reflejo@gmail.com>
6
+ */
7
+ (function($){$.fn.openid=function(e){var f;var g='openid_username';var h=$('#openid_inputarea').length?$('#openid_inputarea'):$('<div id="openid_inputarea" />');var j={txt:{label:'Enter your {provider} {username}',username:'username',title:'Select your openID provider',sign:'Sign-In'},providers:[{name:'Google',url:'https://www.google.com/accounts/o8/id',label:null,big:true},{name:'Yahoo',url:'http://yahoo.com/',label:null,big:true},{name:'AOL',username_txt:'screenname',url:'http://openid.aol.com/{username}',big:true},{name:'OpenID',username_txt:'url',big:true},{name:'MyOpenID',url:'http://{username}.myopenid.com/'},{name:'Flickr',url:'http://flickr.com/{username}/'},{name:'Technorati',url:'http://technorati.com/people/technorati/{username}/'},{name:'Wordpress',url:'http://{username}.wordpress.com/'},{name:'Blogger',url:'http://{username}.blogspot.com/'},{name:'Verisign',url:'http://{username}.pip.verisignlabs.com/'},{name:'Vidoop',url:'http://{username}.myvidoop.com/'},{name:'ClaimID',url:'http://claimid.com/{username}'},{name:'LiveJournal',url:'http://{username}.livejournal.com'},{name:'MySpace',url:'http://www.myspace.com/{username}'}],cookie_expires:6*30,cookie_path:'/',img_path:'/img/'};var k=function(b,c,d){var a=$('<a title="'+b+'" href="#" id="btn_'+c+'" class="openid_'+d+'_btn '+b+'" />');return a.click(n)};var l=function(a){var b=new Date();b.setTime(b.getTime()+(q.cookie_expires*24*60*60*1000));document.cookie="openid_prov="+a+"; expires="+b.toGMTString()+"; path="+q.cookie_path};var m=function(){var c=document.cookie.split(';');for(i in c){if((pos=c[i].indexOf("openid_prov="))!=-1)return $.trim(c[i].slice(pos+12))}};var n=function(a,b){var c=$(b||this).attr('id').replace('btn_','');if(!(f=q.providers[c]))return;if(highlight=$('#openid_highlight'))highlight.replaceWith($('#openid_highlight a')[0]);$('#btn_'+c).wrap('<div id="openid_highlight" />');l(c);o();if(f.label===null){h.text(q.txt.title);if(!b){h.fadeOut();t.submit()}}return false};var o=function(){var a=(f.label||q.txt.label).replace('{username}',(f.username_txt!==undefined)?f.username_txt:q.txt.username).replace('{provider}',f.name);h.empty().show().append('<span class="oidlabel">'+a+'</span><input id="'+g+'" type="text" '+' name="username_txt" class="Verisign"/><input type="submit" value="'+q.txt.sign+'"/>');$('#'+g).focus()};var p=function(){var a=(f.url)?f.url.replace('{username}',$('#'+g).val()):$('#'+g).val();t.append($('<input type="hidden" name="url" value="'+a+'" />'))};var q=$.extend(j,e||{});var r=$('<div id="openid_btns" />');var s=true;$.each(q.providers,function(i,a){if(!a.big&&s){r.append('<br />');s=false}r.append(k(a.name,i,(a.big)?'large':'small'))});var t=this;t.css({'background-image':'none'});t.append(r).submit(p);r.append(h);if(idx=m())n(null,'#btn_'+idx);else h.text(q.txt.title).show();return this}})(jQuery);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-rack-open-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Schenkman-Moore
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-15 00:00:00 -05:00
12
+ date: 2009-12-20 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -46,10 +46,19 @@ files:
46
46
  - Rakefile
47
47
  - VERSION
48
48
  - config.ru
49
+ - easy-rack-open-id.gemspec
49
50
  - lib/easy_rack_open_id.rb
50
51
  - lib/easy_rack_open_id_processing.rb
51
52
  - lib/generic_openid_form.html.erb
52
53
  - lib/nice_openid_form.html.erb
54
+ - lib/nicer_openid_form.html.erb
55
+ - public/easy-rack-openid-assets/openid-realselector/css/style.css
56
+ - public/easy-rack-openid-assets/openid-realselector/demo.html
57
+ - public/easy-rack-openid-assets/openid-realselector/img/balloon.png
58
+ - public/easy-rack-openid-assets/openid-realselector/img/indicator.gif
59
+ - public/easy-rack-openid-assets/openid-realselector/img/openid-icons.png
60
+ - public/easy-rack-openid-assets/openid-realselector/js/jquery.openid.js
61
+ - public/easy-rack-openid-assets/openid-realselector/js/jquery.openid.min.js
53
62
  - public/easy-rack-openid-assets/openid-selector/css/openid.css
54
63
  - public/easy-rack-openid-assets/openid-selector/demo.html
55
64
  - public/easy-rack-openid-assets/openid-selector/images/aol.gif