devise-multi_auth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +15 -0
- data/README.md +24 -0
- data/Rakefile +21 -0
- data/app/controllers/devise/multi_auth/authentications_controller.rb +24 -0
- data/app/models/devise/multi_auth/authentication.rb +32 -0
- data/app/services/devise/multi_auth/capture_successful_external_authentication.rb +21 -0
- data/db/migrate/20140204141526_create_authentications.rb +14 -0
- data/lib/devise-multi_auth.rb +1 -0
- data/lib/devise/multi_auth/engine.rb +13 -0
- data/lib/devise/multi_auth/version.rb +5 -0
- data/lib/devise_multi_auth.rb +12 -0
- data/lib/generators/devise/multi_auth/install/install_generator.rb +29 -0
- data/lib/generators/devise/multi_auth/install/templates/devise_multi_auth_initializer.rb.erb +6 -0
- data/lib/tasks/devise-multi_auth_tasks.rake +4 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae3b0ba3b76d347c3066987da790718277cb5866
|
4
|
+
data.tar.gz: 68445355bd5e0fb023c6490311a8210e3533c530
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa8ebce498b76bf2729b4839e47f493a11b223efc7d85b685c15d2528b4c492490ec15160de2fa3a1577af39cd5bfc5d7ad37331f3f20010c1fe7d8cd53c1d8a
|
7
|
+
data.tar.gz: 014f8eed0e6694b66d6f8c7572c6e67d067fb675635cbcf56c3dfe10e8d85e770f8ce0110052085cd26b6b3cba167f985c25db5aebd1681d88349c9343a1d9d1
|
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
##########################################################################
|
2
|
+
#
|
3
|
+
# Copyright 2014 Jeremy Friesen
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Devise::MultiAuth [![Version](https://badge.fury.io/rb/devise-multi_auth.png)](http://badge.fury.io/rb/devise-multi_auth)
|
2
|
+
|
3
|
+
A [Devise](https://github.com/plataformatec/devise) plugin leveraging [omniauth](https://github.com/intridea/omniauth) to
|
4
|
+
expose alternate means for authenticating existing users.
|
5
|
+
|
6
|
+
```gherkin
|
7
|
+
Scenario: As a Developer
|
8
|
+
Given that I am using Devise
|
9
|
+
And that I have an existing user Signup process
|
10
|
+
When I use Devise::MultiAuth
|
11
|
+
Then I can expose alternate means of authenticating existing users.
|
12
|
+
```
|
13
|
+
|
14
|
+
## Getting Started
|
15
|
+
|
16
|
+
Add the following line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'devise-multi_auth'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
```bash
|
22
|
+
$ bundle
|
23
|
+
$ rails generate devise:multi_auth:install
|
24
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
APP_RAKEFILE = File.expand_path("../spec/internal/Rakefile", __FILE__)
|
8
|
+
load 'rails/tasks/engine.rake'
|
9
|
+
|
10
|
+
require 'engine_cart/rake_task'
|
11
|
+
|
12
|
+
Bundler::GemHelper.install_tasks
|
13
|
+
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
|
16
|
+
RSpec::Core::RakeTask.new(:spec)
|
17
|
+
|
18
|
+
namespace :spec do
|
19
|
+
desc 'Rebuild and run the specs'
|
20
|
+
task :travis => ['engine_cart:clean', 'engine_cart:generate', 'spec']
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Devise::MultiAuth
|
2
|
+
class AuthenticationsController < Devise::OmniauthCallbacksController
|
3
|
+
|
4
|
+
Devise.omniauth_providers.each do |provider|
|
5
|
+
define_method(provider) do
|
6
|
+
authentication_from_external_app
|
7
|
+
end unless methods.include?(provider)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def authentication_from_external_app
|
13
|
+
omni = request.env["omniauth.auth"]
|
14
|
+
if @user = Authentication.find_user_by_provider_and_uid(omni['provider'], omni['uid'])
|
15
|
+
set_flash_message(:notice, :success, kind: omni['provider']) if is_navigational_format?
|
16
|
+
sign_in_and_redirect @user, event: :authentication
|
17
|
+
else
|
18
|
+
session["devise.auth_data"] = request.env["omniauth.auth"].except('extra')
|
19
|
+
redirect_to new_user_registration_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Devise::MultiAuth
|
2
|
+
class Authentication < ActiveRecord::Base
|
3
|
+
belongs_to :user
|
4
|
+
self.table_name = 'devise_multi_auth_authentications'
|
5
|
+
|
6
|
+
def self.to_access_token(options)
|
7
|
+
uid = options.fetch(:uid)
|
8
|
+
client = options.fetch(:client)
|
9
|
+
provider = options.fetch(:provider)
|
10
|
+
where(provider: provider, uid: uid).first!.to_access_token(client: client)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.find_user_by_provider_and_uid(provider, uid)
|
14
|
+
if auth = find_by_provider_and_uid(provider, uid)
|
15
|
+
auth.user
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.find_by_provider_and_uid(provider, uid)
|
22
|
+
where(provider: provider, uid: uid).includes(:user).first
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_access_token(config = {})
|
26
|
+
# @TODO - Need an alternate oauth_client
|
27
|
+
client = config.fetch(:client) { Orcid.oauth_client }
|
28
|
+
tokenizer = config.fetch(:tokenizer) { ::OAuth2::AccessToken.method(:new) }
|
29
|
+
tokenizer.call(client, access_token, refresh_token: refresh_token)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Devise::MultiAuth
|
2
|
+
class CaptureSuccessfulExternalAuthentication
|
3
|
+
def self.call(user, auth = {})
|
4
|
+
return true unless auth.present?
|
5
|
+
new(user, auth).call
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :user, :auth
|
9
|
+
def initialize(user, auth)
|
10
|
+
@user = user
|
11
|
+
@auth = auth
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
object = Authentication.where(user: user).where(auth.slice(:provider, :uid)).first_or_initialize
|
16
|
+
object.access_token = auth.fetch(:credentials)[:token]
|
17
|
+
object.refresh_token = auth.fetch(:credentials)[:refresh_token]
|
18
|
+
object.save!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateAuthentications < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :devise_multi_auth_authentications do |t|
|
4
|
+
t.integer :user_id, index: true, null: false
|
5
|
+
t.string :provider, null: false
|
6
|
+
t.string :uid, null: false
|
7
|
+
t.string :access_token
|
8
|
+
t.string :refresh_token
|
9
|
+
t.timestamp :expires_at, index: true
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
add_index :devise_multi_auth_authentications, [:provider, :uid], unique: true
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'devise_multi_auth'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Devise::MultiAuth
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Devise::MultiAuth
|
4
|
+
|
5
|
+
initializer 'devise-multi_auth.initializers' do |app|
|
6
|
+
app.config.paths.add 'app/services', eager_load: true
|
7
|
+
app.config.autoload_paths += %W(
|
8
|
+
#{config.root}/app/services
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "devise"
|
2
|
+
require "devise/multi_auth/engine"
|
3
|
+
|
4
|
+
module Devise::MultiAuth
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def capture_successful_external_authentication(user, auth, options = {})
|
8
|
+
service = options.fetch(:service) { CaptureSuccessfulExternalAuthentication }
|
9
|
+
service.call(user, auth)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Devise::MultiAuth
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
class_option :install_devise, default: false, type: :boolean
|
8
|
+
|
9
|
+
def install_devise
|
10
|
+
if options[:install_devise]
|
11
|
+
generate 'devise:install'
|
12
|
+
generate 'devise User'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def install_authentications_controller
|
17
|
+
routing_code = %(, controllers: { omniauth_callbacks: 'devise/multi_auth/authentications' }\n)
|
18
|
+
insert_into_file 'config/routes.rb', routing_code, { :after => /devise_for :users/, :verbose => false }
|
19
|
+
end
|
20
|
+
|
21
|
+
def install_warden_initializer
|
22
|
+
template('devise_multi_auth_initializer.rb.erb', 'config/initializers/devise_multi_auth_initializer.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
def install_migrations
|
26
|
+
rake 'devise_multi_auth:install:migrations'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise-multi_auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jeremy.n.friesen@gmail.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: devise
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: omniauth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.2.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: database_cleaner
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: engine_cart
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: omniauth-github
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: factory_girl
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: A Devise plugin for exposing multiple authentication providers via omniauth.
|
140
|
+
email:
|
141
|
+
- jeremy.n.friesen@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- app/controllers/devise/multi_auth/authentications_controller.rb
|
147
|
+
- app/models/devise/multi_auth/authentication.rb
|
148
|
+
- app/services/devise/multi_auth/capture_successful_external_authentication.rb
|
149
|
+
- db/migrate/20140204141526_create_authentications.rb
|
150
|
+
- lib/devise/multi_auth/engine.rb
|
151
|
+
- lib/devise/multi_auth/version.rb
|
152
|
+
- lib/devise-multi_auth.rb
|
153
|
+
- lib/devise_multi_auth.rb
|
154
|
+
- lib/generators/devise/multi_auth/install/install_generator.rb
|
155
|
+
- lib/generators/devise/multi_auth/install/templates/devise_multi_auth_initializer.rb.erb
|
156
|
+
- lib/tasks/devise-multi_auth_tasks.rake
|
157
|
+
- LICENSE
|
158
|
+
- Rakefile
|
159
|
+
- README.md
|
160
|
+
homepage: https://github.com/jeremyf/devise-multi_auth
|
161
|
+
licenses: []
|
162
|
+
metadata: {}
|
163
|
+
post_install_message:
|
164
|
+
rdoc_options: []
|
165
|
+
require_paths:
|
166
|
+
- lib
|
167
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
requirements: []
|
178
|
+
rubyforge_project:
|
179
|
+
rubygems_version: 2.0.14
|
180
|
+
signing_key:
|
181
|
+
specification_version: 4
|
182
|
+
summary: A Devise plugin for exposing multiple authentication providers via omniauth.
|
183
|
+
test_files: []
|