devise_social_login 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +52 -0
- data/Rakefile +24 -0
- data/app/assets/config/devise_social_login_manifest.js +2 -0
- data/app/assets/javascripts/devise_social_login/application.js +13 -0
- data/app/assets/stylesheets/devise_social_login/application.css +15 -0
- data/app/controllers/devise_social_login/application_controller.rb +5 -0
- data/app/controllers/devise_social_login/omniauth_callbacks_controller.rb +24 -0
- data/app/helpers/devise_social_login/application_helper.rb +4 -0
- data/app/jobs/devise_social_login/application_job.rb +4 -0
- data/app/mailers/devise_social_login/application_mailer.rb +6 -0
- data/app/models/concerns/devise_social_login/user_from_auth.rb +25 -0
- data/app/models/devise_social_login/application_record.rb +5 -0
- data/app/models/devise_social_login/social_profile.rb +6 -0
- data/app/views/layouts/devise_social_login/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20161029094557_create_devise_social_login_social_profiles.rb +12 -0
- data/lib/devise_social_login.rb +5 -0
- data/lib/devise_social_login/engine.rb +5 -0
- data/lib/devise_social_login/version.rb +3 -0
- data/lib/tasks/devise_social_login_tasks.rake +4 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0d7ce654ac2d914b41693c715b2273109c4f4545
|
4
|
+
data.tar.gz: 174ce3fe38ba0b575873987f0ec5a198d2959ed6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ced8e6b224a4f13ebe4c9cc3390aa21c6a736e3568903256954edd8f74a00eb3ebe05d40a1fe51c2bf36d0eb909e7b835ca2113018a0a564ea61a987ef676ad
|
7
|
+
data.tar.gz: 88ffb7548c449eba7e0dbe770131cc6d282acf9b32eea2f33af48abfce1f5a0054e9e53a0b58c20082e0bf433e52858999c7ea9e660ff2ceab6c80e387afe8e4
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 blueplanet
|
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.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# DeviseSocialLogin
|
2
|
+
Add omniauth login to Rails Application via Devise.
|
3
|
+
Support follwing provider:
|
4
|
+
|
5
|
+
- [x] Facebook
|
6
|
+
- [ ] Twitter
|
7
|
+
- [ ] Github
|
8
|
+
- [ ] Google
|
9
|
+
- [ ] Line
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'devise_social_login'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
```bash
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
```bash
|
25
|
+
$ gem install devise_social_login
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
1. Add `omniauth_callbacks` key to the route setting:
|
30
|
+
|
31
|
+
```rb
|
32
|
+
# config/routes.rb
|
33
|
+
|
34
|
+
devise_for :users, controllers: { omniauth_callbacks: 'devise_social_login/omniauth_callbacks' }
|
35
|
+
```
|
36
|
+
|
37
|
+
2. Add provider settings to devise:
|
38
|
+
|
39
|
+
```rb
|
40
|
+
# config/initializer/devise.rb
|
41
|
+
|
42
|
+
...
|
43
|
+
config.omniauth :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'], scope: 'email', callback_url: 'http://localhost:3000/users/auth/facebook/callback'
|
44
|
+
config.omniauth :twitter, ENV['TWITTER_APP_ID'], ENV['TWITTER_APP_SECRET']
|
45
|
+
...
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
Contribution directions go here.
|
50
|
+
|
51
|
+
## License
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
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
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'DeviseSocialLogin'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
require 'bundler/gem_tasks'
|
24
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module DeviseSocialLogin
|
2
|
+
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
3
|
+
include Devise::Controllers::Rememberable
|
4
|
+
|
5
|
+
def facebook
|
6
|
+
auth = request.env['omniauth.auth']
|
7
|
+
|
8
|
+
@user = User.from_auth auth
|
9
|
+
if @user.persisted?
|
10
|
+
sign_in_and_redirect @user, event: :authentication
|
11
|
+
set_flash_message :notice, :success, kind: 'Facebook' if is_navigational_format?
|
12
|
+
else
|
13
|
+
session['devise.facebook_data'] = auth
|
14
|
+
redirect_to new_user_registration_url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def failure
|
21
|
+
redirect_to root_path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module DeviseSocialLogin
|
2
|
+
module UserFromAuth
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included do
|
5
|
+
has_many :social_profiles, dependent: :destroy
|
6
|
+
|
7
|
+
devise :omniauthable, omniauth_providers: Devise.omniauth_providers
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def from_auth(auth)
|
12
|
+
find_or_initialize_by(email: auth.info.email).tap do |user|
|
13
|
+
if user.new_record?
|
14
|
+
user.password = Devise.friendly_token[0, 20]
|
15
|
+
user.confirmed_at = Time.current
|
16
|
+
end
|
17
|
+
|
18
|
+
user.social_profiles.find_or_initialize_by(provider: :facebook, uid: auth.uid)
|
19
|
+
|
20
|
+
user.save!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Devise social login</title>
|
5
|
+
<%= stylesheet_link_tag "devise_social_login/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "devise_social_login/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateDeviseSocialLoginSocialProfiles < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :devise_social_login_social_profiles do |t|
|
4
|
+
t.string :provider, null: false
|
5
|
+
t.string :uid, null: false
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :devise_social_login_social_profiles, [:provider, :uid], unique: true
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise_social_login
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- blueplanet
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-01 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: 5.0.0
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.0.0.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.0.0
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.0.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: devise
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: omniauth-facebook
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec-rails
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: Social login for devise via omniauth.
|
76
|
+
email:
|
77
|
+
- erguolinge@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- MIT-LICENSE
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- app/assets/config/devise_social_login_manifest.js
|
86
|
+
- app/assets/javascripts/devise_social_login/application.js
|
87
|
+
- app/assets/stylesheets/devise_social_login/application.css
|
88
|
+
- app/controllers/devise_social_login/application_controller.rb
|
89
|
+
- app/controllers/devise_social_login/omniauth_callbacks_controller.rb
|
90
|
+
- app/helpers/devise_social_login/application_helper.rb
|
91
|
+
- app/jobs/devise_social_login/application_job.rb
|
92
|
+
- app/mailers/devise_social_login/application_mailer.rb
|
93
|
+
- app/models/concerns/devise_social_login/user_from_auth.rb
|
94
|
+
- app/models/devise_social_login/application_record.rb
|
95
|
+
- app/models/devise_social_login/social_profile.rb
|
96
|
+
- app/views/layouts/devise_social_login/application.html.erb
|
97
|
+
- config/routes.rb
|
98
|
+
- db/migrate/20161029094557_create_devise_social_login_social_profiles.rb
|
99
|
+
- lib/devise_social_login.rb
|
100
|
+
- lib/devise_social_login/engine.rb
|
101
|
+
- lib/devise_social_login/version.rb
|
102
|
+
- lib/tasks/devise_social_login_tasks.rake
|
103
|
+
homepage: https://github.com/blueplanet/devise_social_login
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.5.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Social login for devise via omniauth.
|
127
|
+
test_files: []
|