multiauth 0.2.0 → 0.2.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -0,0 +1,33 @@
1
+ module Multiauth
2
+ class SessionsController < ApplicationController
3
+ def new
4
+ end
5
+
6
+ def auth
7
+ # see http://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
8
+ if logged_in?
9
+ self.current_user.connect(params['auth'] || request.env['rack.auth'])
10
+ else
11
+ self.current_user = User.authenticate(params['auth'] || request.env['rack.auth'])
12
+ end
13
+
14
+ if logged_in?
15
+ redirect_to root_path
16
+ else
17
+ render 'new'
18
+ end
19
+ end
20
+
21
+ def failure
22
+ flash.now[:error] = params[:message]
23
+ render 'new'
24
+ end
25
+
26
+ def destroy
27
+ self.current_user = nil
28
+ redirect_to root_path
29
+ end
30
+
31
+ protected
32
+ end
33
+ end
@@ -14,7 +14,7 @@
14
14
  <% providers.each_slice(3) do |column| %>
15
15
  <div class="column">
16
16
  <% column.each do |provider, config| %>
17
- <a id="btn_<%= count+=1 %>" class="<%= provider %> openid_btn <%= config[:class] %>" title="<%= provider %>" href="<%= config[:url].kind_of?(Proc) ? instance_exec(&config[:url]) : config[:url] %>" data-real="<%= config[:real] || false %>"></a>
17
+ <a id="btn_<%= count+=1 %>" class="<%= provider %> openid_btn <%= config[:class] %>" title="<%= provider %>" href="/auth/<%= config["openid"] ? "open_id?openid_url=#{config["openid"]}" : "#{provider.downcase}" %>"></a>
18
18
  <% end %>
19
19
  </div>
20
20
  <% end %>
@@ -0,0 +1 @@
1
+ = multiauth_box
@@ -11,8 +11,8 @@ module Multiauth
11
11
  copy_file "multiauth.js", "public/javascripts/multiauth.js"
12
12
  end
13
13
 
14
- def copy_twitter
15
- copy_file "devise_twitter.rb", "config/initializers/devise_twitter.rb"
14
+ def copy_config_file
15
+ copy_file "auth_providers.yml", "config/auth_providers.yml"
16
16
  end
17
17
 
18
18
  def show_readme
@@ -3,98 +3,57 @@
3
3
 
4
4
  Some setup you must do manually if you haven't yet:
5
5
 
6
- 1. configure your model, for example:
7
-
8
- class User
9
- devise :database_authenticatable, :openid_authenticatable, :rememberable,
10
- :trackable, :validatable, :twitter_oauth, :oauthable
11
-
12
- def self.find_for_github_oauth(access_token, signed_in_resource=nil)
13
- data = ActiveSupport::JSON.decode(access_token.get('/api/v2/json/user/show'))["user"]
14
-
15
- if user = User.find_by_email(data["email"])
16
- user
17
- else
18
- User.create!(:name => data["name"], :email => data["email"],
19
- :github_id => data["id"])
6
+ 1. configure your User model (mongo_mapper example):
7
+
8
+ class User
9
+ ...
10
+ key :auth_keys, Array
11
+
12
+ def self.authenticate(fields)
13
+ auth_key = "#{fields["provider"]}_#{fields["uid"]}"
14
+ user = User.first(:auth_keys => auth_key)
15
+ if user.nil?
16
+ user = User.new(:auth_keys => [auth_key])
17
+ user.send(:auth_fields=, fields["user_info"])
18
+ user.save!
20
19
  end
21
- end
22
-
23
- def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
24
- data = ActiveSupport::JSON.decode(access_token.get('/me'))
25
20
 
26
- if user = User.find_by_email(data["email"])
27
- user
28
- else
29
- User.create!(:name => data["name"], :email => data["email"],
30
- :facebook_id => data["id"], :facebook_profile => data["link"])
31
- end
21
+ user
32
22
  end
33
23
 
34
- def self.create_from_identity_url(identity_url)
35
- self.create(:identity_url => identity_url)
36
- end
24
+ def connect(fields)
25
+ auth_key = "#{fields["provider"]}_#{fields["uid"]}"
26
+ user = User.first(:auth_keys => auth_key, :select => [:id])
27
+ if user.present? && user.id != self.id
28
+ user.destroy if merge_account(user)
29
+ end
37
30
 
38
- def self.openid_required_fields
39
- ["fullname", "email", "http://axschema.org/pref/language", "http://axschema.org/contact/email"]
31
+ self.push_uniq(:auth_keys => auth_key)
40
32
  end
41
33
 
42
- def self.openid_optional_fields
43
- %w[
44
- http://axschema.org/namePerson/friendly
45
- http://axschema.org/namePerson
46
- http://axschema.org/birthDate
47
- gender
48
- http://axschema.org/person/gender
49
- http://axschema.org/contact/postalCode/home
50
- country
51
- http://axschema.org/contact/country/home
52
- language
53
- http://axschema.org/pref/language
54
- http://axschema.org/pref/timezone
55
- ]
34
+ def merge_account(other_user)
35
+ # return true to delete the old user
36
+ true
56
37
  end
57
38
 
58
- def openid_fields=(fields)
59
- logger.info "OPENID FIELDS: #{fields.inspect}"
60
- fields.each do |key, value|
61
- if value.is_a? Array
62
- value = value.first
63
- end
64
-
65
- case key.to_s
66
- when "fullname", "http://axschema.org/namePerson"
67
- self.full_name = value
68
- when "email", "http://axschema.org/contact/email"
69
- self.email = value
70
- when "gender", "http://axschema.org/person/gender"
71
- self.gender = value
72
- else
73
- logger.error "Unknown OpenID field: #{key}"
74
- end
39
+ def auth_fields=(info)
40
+ Rails.logger.info "FIELDS: #{info.inspect}"
41
+ info.each_pair do |k, v|
42
+ self[k] = v
75
43
  end
76
44
  end
45
+ end
77
46
 
78
- def password_required?
79
- return false if self[:identity_url].present? || self[:facebook_id].present? || self[:github_id].present?
80
-
81
- (encrypted_password.blank? || !password.blank?)
82
- end
83
- end
84
-
85
- 2. to include the javascripts do
86
- <%= multiauth_assets %>
87
-
88
- to render the multiauth box do
89
- <%= multiauth_box %>
47
+ 2. configure the service keys at config/auth_providers.yml
90
48
 
91
- 3. configure your twitter, facebook and github keys
92
49
 
93
- You can config providers in an initializer, for example:
50
+ Default routes:
51
+ /sessions/sign_in
52
+ /sessions/sign_out
94
53
 
95
- Multiauth::PROVIDERS.delete("Vidoop")
96
- Multiauth::PROVIDERS.delete("Github")
97
- Multiauth::PROVIDERS["Google"][:class] = "selected"
54
+ you can override them using the following routes:
55
+ match "/login" => "multiauth/sessions#new", :as => :new_session
56
+ match "/logout" => "multiauth/sessions#destroy", :method => :get, :as => :destroy_session
98
57
 
99
58
 
100
59
  ===============================================================================
@@ -0,0 +1,47 @@
1
+ base: &common
2
+ Twitter:
3
+ id: <TWITTER ID>
4
+ token: <TWITTER TOKEN>
5
+ Facebook:
6
+ id: <FACEBOOK ID>
7
+ token: <FACEBOOK TOKEN>
8
+ Github:
9
+ id: <GITHUB ID>
10
+ token: <GITHUB TOKEN>
11
+ Google:
12
+ openid: https://www.google.com/accounts/o8/id
13
+ Yahoo:
14
+ openid: http://yahoo.com
15
+ AOL:
16
+ openid: http://openid.aol.com/{user_name}
17
+ MySpace:
18
+ openid: http://www.myspace.com/{user_name}
19
+ MyOpenID:
20
+ openid: http://{user_name}.myopenid.com/
21
+ Wordpress:
22
+ openid: http://{user_name}.wordpress.com/
23
+ Blogger:
24
+ openid: http://{user_name}.blogspot.com/
25
+ Flickr:
26
+ openid: http://flickr.com/{user_name}/
27
+ Launchpad:
28
+ openid: https://launchpad.net/~{user_name}
29
+ Vidoop:
30
+ openid: http://{user_name}.myvidoop.com/
31
+ ClaimID:
32
+ openid: http://claimid.com/{user_name}
33
+ Technorati:
34
+ openid: http://technorati.com/people/technorati/{user_name}/
35
+ Verisign:
36
+ openid: http://{user_name}.pip.verisignlabs.com/
37
+ LiveJournal:
38
+ openid: http://{user_name}.livejournal.com
39
+ OpenId:
40
+ openid: {user_name}
41
+
42
+ development:
43
+ <<: *common
44
+ production:
45
+ <<: *common
46
+ test:
47
+ <<: *common
@@ -0,0 +1,22 @@
1
+ module Multiauth
2
+ module Helpers
3
+ def self.included(base)
4
+ base.class_eval do
5
+ helper_method :current_user, :logged_in?
6
+ end
7
+ end
8
+
9
+ def current_user=(new_user)
10
+ session[:user] = (new_user.nil? || new_user.is_a?(Symbol)) ? nil : new_user.id
11
+ @current_user = new_user
12
+ end
13
+
14
+ def current_user
15
+ @current_user ||= User.first(:_id => session[:user]) if session[:user]
16
+ end
17
+
18
+ def logged_in?
19
+ !!self.current_user
20
+ end
21
+ end
22
+ end
@@ -1 +1,37 @@
1
- ActionController::Base.append_view_path File.expand_path("../../../app/views", __FILE__)
1
+ ::ActionView::Base.send :include, Multiauth::ViewsHelper
2
+
3
+ module Multiauth
4
+ class Engine < ::Rails::Engine
5
+ paths.app.controllers = File.expand_path("../../../app/controllers", __FILE__)
6
+ paths.app.views = File.expand_path("../../../app/views", __FILE__)
7
+ paths.config.routes = File.expand_path("../routes.rb", __FILE__)
8
+
9
+ initializer "multiauth" do |app|
10
+ config_file = Rails.root+"config/auth_providers.yml"
11
+ providers = YAML::load(ERB.new(File.read(config_file)).result)
12
+ if providers[Rails.env].nil?
13
+ raise ArgumentError, "cannot find section for #{Rails.env} environment in #{config_file}"
14
+ end
15
+
16
+ Multiauth.providers = providers[Rails.env]
17
+
18
+ require 'omniauth/openid'
19
+ require 'openid/store/filesystem'
20
+
21
+ app.config.middleware.use OmniAuth::Strategies::OpenID, OpenID::Store::Filesystem.new('/tmp') # FIXME: mm store
22
+
23
+ app.config.middleware.use OmniAuth::Builder do
24
+ Multiauth.providers.each do |provider, config|
25
+ next if config["token"].blank?
26
+
27
+ puts ">> Setting up #{provider} provider"
28
+ provider provider.downcase.to_sym, config["id"], config["token"]
29
+ end
30
+ end
31
+ end
32
+
33
+ config.to_prepare do
34
+ ApplicationController.send(:include, Multiauth::Helpers)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ Rails::Application.routes.draw do
2
+ match '/sessions/sign_in' => "multiauth/sessions#new", :as => :new_session
3
+ match '/sessions/sign_out' => "multiauth/sessions#destroy", :method => :get, :as => :destroy_session
4
+
5
+ match "/auth/:provider/callback" => "multiauth/sessions#auth"
6
+ end
@@ -10,9 +10,8 @@ module Multiauth
10
10
  end
11
11
 
12
12
  def multiauth_providers
13
- Multiauth::PROVIDERS
13
+ Multiauth.providers || []
14
14
  end
15
15
  end
16
16
  end
17
17
 
18
- ::ActionView::Base.send :include, Multiauth::ViewsHelper
data/lib/multiauth.rb CHANGED
@@ -1,64 +1,14 @@
1
- require 'multiauth/rails'
2
1
  require 'multiauth/views_helper'
2
+ require 'multiauth/helpers'
3
+ require 'multiauth/rails'
4
+
3
5
 
4
6
  module Multiauth
5
- PROVIDERS = {
6
- 'Google' => {
7
- :url => '/auth/open_id?openid_url=https://www.google.com/accounts/o8/id'
8
- },
9
- 'Twitter' => {
10
- :url => '/auth/twitter',
11
- :real => true
12
- },
13
- 'Facebook' => {
14
- :url => '/auth/facebook',
15
- :real => true
16
- },
17
- 'Yahoo' => {
18
- :url => '/auth/open_id?openid_url=http://yahoo.com/'
19
- },
20
- 'AOL' => {
21
- :url => '/auth/open_id?openid_url=http://openid.aol.com/{user_name}'
22
- },
23
- 'MySpace' => {
24
- :url => '/auth/open_id?openid_url=http://www.myspace.com/{user_name}'
25
- },
26
- 'Github' => {
27
- :url => '/auth/github',
28
- :real => true
29
- },
30
- 'MyOpenID' => {
31
- :url => '/auth/open_id?openid_url=http://{user_name}.myopenid.com/'
32
- },
33
- 'Wordpress' => {
34
- :url => '/auth/open_id?openid_url=http://{user_name}.wordpress.com/'
35
- },
36
- 'Blogger' => {
37
- :url => '/auth/open_id?openid_url=http://{user_name}.blogspot.com/'
38
- },
39
- 'Flickr' => {
40
- :url => '/auth/open_id?openid_url=http://flickr.com/{user_name}/'
41
- },
42
- 'Launchpad' => {
43
- :url => '/auth/open_id?openid_url=https://launchpad.net/~{user_name}'
44
- },
45
- 'Vidoop' => {
46
- :url => '/auth/open_id?openid_url=http://{user_name}.myvidoop.com/'
47
- },
48
- 'ClaimID' => {
49
- :url => '/auth/open_id?openid_url=http://claimid.com/{user_name}'
50
- },
51
- 'Technorati' => {
52
- :url => '/auth/open_id?openid_url=http://technorati.com/people/technorati/{user_name}/'
53
- },
54
- 'Verisign' => {
55
- :url => '/auth/open_id?openid_url=http://{user_name}.pip.verisignlabs.com/'
56
- },
57
- 'LiveJournal' => {
58
- :url => '/auth/open_id?openid_url=http://{user_name}.livejournal.com'
59
- },
60
- 'OpenID' => {
61
- :url => '/auth/open_id'
62
- }
63
- }
7
+ def self.providers=(providers)
8
+ @providers = providers
9
+ end
10
+
11
+ def self.providers
12
+ @providers
13
+ end
64
14
  end
data/multiauth.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{multiauth}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David A. Cuadrado"]
12
- s.date = %q{2010-10-05}
12
+ s.date = %q{2010-10-06}
13
13
  s.description = %q{multi authentication gem using devise & co}
14
14
  s.email = %q{krawek@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,9 +25,12 @@ Gem::Specification.new do |s|
25
25
  "README.rdoc",
26
26
  "Rakefile",
27
27
  "VERSION",
28
+ "app/controllers/multiauth/sessions_controller.rb",
28
29
  "app/views/multiauth/_box.html.erb",
30
+ "app/views/multiauth/sessions/new.html.haml",
29
31
  "lib/generators/multiauth/multiauth_generator.rb",
30
32
  "lib/generators/templates/README",
33
+ "lib/generators/templates/auth_providers.yml",
31
34
  "lib/generators/templates/devise_twitter.rb",
32
35
  "lib/generators/templates/images/arrow.gif",
33
36
  "lib/generators/templates/images/balloon.png",
@@ -36,7 +39,9 @@ Gem::Specification.new do |s|
36
39
  "lib/generators/templates/multiauth.css",
37
40
  "lib/generators/templates/multiauth.js",
38
41
  "lib/multiauth.rb",
42
+ "lib/multiauth/helpers.rb",
39
43
  "lib/multiauth/rails.rb",
44
+ "lib/multiauth/routes.rb",
40
45
  "lib/multiauth/views_helper.rb",
41
46
  "multiauth.gemspec",
42
47
  "spec/multiauth_spec.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - David A. Cuadrado
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-05 00:00:00 -05:00
17
+ date: 2010-10-06 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -80,9 +80,12 @@ files:
80
80
  - README.rdoc
81
81
  - Rakefile
82
82
  - VERSION
83
+ - app/controllers/multiauth/sessions_controller.rb
83
84
  - app/views/multiauth/_box.html.erb
85
+ - app/views/multiauth/sessions/new.html.haml
84
86
  - lib/generators/multiauth/multiauth_generator.rb
85
87
  - lib/generators/templates/README
88
+ - lib/generators/templates/auth_providers.yml
86
89
  - lib/generators/templates/devise_twitter.rb
87
90
  - lib/generators/templates/images/arrow.gif
88
91
  - lib/generators/templates/images/balloon.png
@@ -91,7 +94,9 @@ files:
91
94
  - lib/generators/templates/multiauth.css
92
95
  - lib/generators/templates/multiauth.js
93
96
  - lib/multiauth.rb
97
+ - lib/multiauth/helpers.rb
94
98
  - lib/multiauth/rails.rb
99
+ - lib/multiauth/routes.rb
95
100
  - lib/multiauth/views_helper.rb
96
101
  - multiauth.gemspec
97
102
  - spec/multiauth_spec.rb