omniauth-generator 0.1.0 → 0.1.2
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.
- checksums.yaml +4 -4
- data/README.md +24 -2
- data/lib/omniauth/generator/install_generator.rb +4 -3
- data/lib/omniauth/generator/templates/_social_buttons.html.erb +143 -137
- data/lib/omniauth/generator/templates/_user.rb +53 -21
- data/lib/omniauth/generator/templates/omniauth_callbacks_controller.rb +3 -1
- data/lib/omniauth/generator/version.rb +1 -1
- metadata +4 -7
- data/CHANGELOG.md +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d351d58c977e211e3f060d4a3eaf93e54969ee8a798b23bbcc62e4dd91112a5
|
4
|
+
data.tar.gz: afd00eeb75dc3eeb9d35e2fbf6ef86b661a7fefdb89566146ffc09aff42b7cc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c42ad9765b5abfb5fbae9a0b9b60fd05a62a3607244fbbfd5384827f8637c8d4e8d5135c9618fc7db31199ed6cc39a51ed7208e4a9a2a44b07ccdb5ed278c4f3
|
7
|
+
data.tar.gz: d4007e2d5ba711b19e3288549828465cc4e279335f191b12da9e6b61ada85076ff8871028db8fe2d136b22f5de4a76ad563bb0ab1baad0c1ed7daee9e78a1ad2
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ This project contains helpers for the following social login buttons:
|
|
12
12
|
- [Microsoft](https://learn.microsoft.com/en-us/entra/identity-platform/howto-add-branding-in-apps)
|
13
13
|
- [Apple](https://developer.apple.com/design/human-interface-guidelines/sign-in-with-apple)
|
14
14
|
- Facebook
|
15
|
-
- LinkedIn
|
15
|
+
- LinkedIn - [omniauth-linkedin-openid](https://github.com/jclusso/omniauth-linkedin-openid)
|
16
16
|
- [GitHub](https://github.com/logos) (they don't have a guideline for how to style their login button)
|
17
17
|
|
18
18
|
The buttons have basic styling and should look pretty when `<buttons>` are already styled. This is how they look out of the box with [PicoCSS](https://picocss.com/):
|
@@ -41,7 +41,7 @@ bundle add omniauth-generator --group development
|
|
41
41
|
# Install at least one omniauth gem/strategy, e.g. of the following
|
42
42
|
bundle add omniauth-google-oauth2
|
43
43
|
bundle add omniauth-facebook
|
44
|
-
bundle add omniauth-linkedin
|
44
|
+
bundle add omniauth-linkedin-openid
|
45
45
|
bundle add omniauth-github
|
46
46
|
bundle add omniauth-azure-activedirectory-v2
|
47
47
|
bundle add omniauth-apple
|
@@ -69,7 +69,29 @@ rails server
|
|
69
69
|
- All styling and CSS is inlined in the `Helper` so this Gem should work with any js and css bundler.
|
70
70
|
- Put all the social buttons into a separate renderer and separate them from `app/views/devise/shared/_links.html.erb`
|
71
71
|
|
72
|
+
## Changelog
|
73
|
+
|
74
|
+
### [Unreleased]
|
75
|
+
|
76
|
+
### [0.1.2] - 2024-12-20
|
77
|
+
|
78
|
+
- Recommend to use `omniauth-linkedin-openid` for LinkedIn
|
79
|
+
- Add index to `users` table for [`uid`, `provider`]
|
80
|
+
- Fix initiliazation of provider/uid for existing users
|
81
|
+
- Add template code for providers which don't provide emails for some users
|
82
|
+
- Add a HR between Login and Social buttons
|
83
|
+
- Revert override of `def failure` to flash+redirect
|
84
|
+
|
85
|
+
### [0.1.1] - 2024-10-18
|
86
|
+
|
87
|
+
- Fixed a bug where the app would not start in an environment where no credentials are available.
|
88
|
+
|
89
|
+
### [0.1.0] - 2024-10-17
|
90
|
+
|
91
|
+
- Initial release
|
92
|
+
|
72
93
|
## Limitations
|
73
94
|
|
74
95
|
- The generator is able to support multiple `omniauth-xxx` gems at the same time, but users can not log into the same account from multiple providers when those providers provide the same email back. Compare this answer on SO: https://stackoverflow.com/a/22126562/278842
|
75
96
|
- The generator is using secrets from the Rails credentials file. If you prefer to use ENV you need to adjust the code in `config/initializers/devise.rb` accordingly.
|
97
|
+
- I did remove a line from the Omniauth callback controller for `google-oauth2` which didn't make sense to me. It might break something. https://github.com/zquestz/omniauth-google-oauth2/issues/466
|
@@ -9,15 +9,15 @@ module Devise
|
|
9
9
|
|
10
10
|
def dependencies
|
11
11
|
|
12
|
-
|
12
|
+
omniauth_gems = {
|
13
13
|
google: :GoogleOauth2,
|
14
14
|
facebook: :Facebook,
|
15
|
-
linkedin: :
|
15
|
+
linkedin: :LinkedinOpenid,
|
16
16
|
github: :GitHub,
|
17
17
|
microsoft: :AzureActivedirectoryV2,
|
18
18
|
apple: :Apple
|
19
19
|
}
|
20
|
-
if !
|
20
|
+
if !omniauth_gems.any? { |_, strategy_class| Gem.loaded_specs.has_key?("omniauth-#{strategy_class.to_s.underscore.gsub('_', '-')}") }
|
21
21
|
say_error("Omniauth-generator: Need at least one OmniAuth strategy gem to be installed. Obvious candidates not found.")
|
22
22
|
ask("Would you like to continue? (y/n)") do |answer|
|
23
23
|
Kernel.exit(1) unless answer.downcase == 'y'
|
@@ -29,6 +29,7 @@ module Devise
|
|
29
29
|
|
30
30
|
def database_update
|
31
31
|
generate :migration, "AddOmniauthToUsers provider:string uid:string"
|
32
|
+
insert_into_file Dir.glob("db/migrate/*_add_omniauth_to_users.rb").first, before: ' end', ' add_index :users, [ :uid, :provider ]\n'
|
32
33
|
end
|
33
34
|
|
34
35
|
def update_application
|
@@ -1,156 +1,162 @@
|
|
1
|
-
<%- resource_class.omniauth_providers.
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
border-radius: 4px;
|
11
|
-
font-family: 'Roboto', Arial, sans-serif;
|
12
|
-
color: #1f1f1f;
|
13
|
-
font-weight: 500;
|
14
|
-
box-shadow: 0 1px 2px rgba(60, 64, 67, 0.30), 0 1px 3px rgba(60, 64, 67, 0.15);
|
15
|
-
outline: none;" do %>
|
16
|
-
<svg xmlns="http://www.w3.org/2000/svg" style="width:20px;height:20px;margin-right:12px" viewBox="0 0 48 48">
|
17
|
-
<path fill="#EA4335" d="M24 10c4 0 7 1 9 3l7-7c-4-4-10-6-16-6C15 0 7 5 3 13l8 6c1-5 7-9 13-9z"/>
|
18
|
-
<path fill="#4285F4" d="M47 25v-5H24v9h13c-1 3-2 6-5 7l8 6c4-4 7-10 7-17z"/>
|
19
|
-
<path fill="#FBBC05" d="m11 29-1-5 1-5-8-6a24 24 0 0 0 0 22l8-6z"/>
|
20
|
-
<path fill="#34A853" d="M24 48c6 0 12-2 16-6l-8-6c-2 2-5 2-8 2-6 0-12-4-13-9l-8 6c4 8 12 13 21 13z"/>
|
21
|
-
<path fill="none" d="M0 0h48v48H0z"/>
|
22
|
-
</svg>
|
23
|
-
<span>
|
24
|
-
Sign <%= controller_name == 'registrations' ? 'up' : 'in' %> with <%= OmniAuth::Utils.camelize(provider) %>
|
25
|
-
</span>
|
26
|
-
<% end %>
|
27
|
-
|
28
|
-
<%- when :microsoft -%>
|
29
|
-
<%= button_to omniauth_authorize_path(resource_name, provider), data: { turbo: false }, method: :post, style: "
|
1
|
+
<%- if devise_mapping.omniauthable? && resource_class.omniauth_providers.size > 0 %>
|
2
|
+
<div style="display: flex; align-items: center; justify-content: center; margin: 0.75rem 0;">
|
3
|
+
<hr style="flex: 1;"><small style="padding: 0 1em; margin-bottom: 0.2em;">or</small><hr style="flex: 1;">
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<%- resource_class.omniauth_providers.each do |provider| -%>
|
7
|
+
<%- case provider -%>
|
8
|
+
<%- when :google -%>
|
9
|
+
<%= button_to omniauth_authorize_path(resource_name, provider), data: { turbo: false }, method: :post, style: "
|
30
10
|
display: flex;
|
31
11
|
align-items: center;
|
32
12
|
justify-content: center;
|
33
|
-
background-color:
|
34
|
-
border: 1px solid #
|
13
|
+
background-color: white;
|
14
|
+
border: 1px solid #747775;
|
35
15
|
border-radius: 4px;
|
36
|
-
font-family: '
|
37
|
-
color: #
|
38
|
-
font-weight:
|
16
|
+
font-family: 'Roboto', Arial, sans-serif;
|
17
|
+
color: #1f1f1f;
|
18
|
+
font-weight: 500;
|
39
19
|
box-shadow: 0 1px 2px rgba(60, 64, 67, 0.30), 0 1px 3px rgba(60, 64, 67, 0.15);
|
40
|
-
outline: none;
|
41
|
-
|
42
|
-
|
43
|
-
<
|
44
|
-
<
|
45
|
-
<
|
46
|
-
<
|
20
|
+
outline: none;" do %>
|
21
|
+
<svg xmlns="http://www.w3.org/2000/svg" style="width:20px;height:20px;margin-right:12px" viewBox="0 0 48 48">
|
22
|
+
<path fill="#EA4335" d="M24 10c4 0 7 1 9 3l7-7c-4-4-10-6-16-6C15 0 7 5 3 13l8 6c1-5 7-9 13-9z"/>
|
23
|
+
<path fill="#4285F4" d="M47 25v-5H24v9h13c-1 3-2 6-5 7l8 6c4-4 7-10 7-17z"/>
|
24
|
+
<path fill="#FBBC05" d="m11 29-1-5 1-5-8-6a24 24 0 0 0 0 22l8-6z"/>
|
25
|
+
<path fill="#34A853" d="M24 48c6 0 12-2 16-6l-8-6c-2 2-5 2-8 2-6 0-12-4-13-9l-8 6c4 8 12 13 21 13z"/>
|
26
|
+
<path fill="none" d="M0 0h48v48H0z"/>
|
47
27
|
</svg>
|
48
|
-
<span
|
28
|
+
<span>
|
49
29
|
Sign <%= controller_name == 'registrations' ? 'up' : 'in' %> with <%= OmniAuth::Utils.camelize(provider) %>
|
50
30
|
</span>
|
51
31
|
<% end %>
|
32
|
+
|
33
|
+
<%- when :microsoft -%>
|
34
|
+
<%= button_to omniauth_authorize_path(resource_name, provider), data: { turbo: false }, method: :post, style: "
|
35
|
+
display: flex;
|
36
|
+
align-items: center;
|
37
|
+
justify-content: center;
|
38
|
+
background-color: #FFFFFF;
|
39
|
+
border: 1px solid #8C8C8C;
|
40
|
+
border-radius: 4px;
|
41
|
+
font-family: 'Segoe UI', Arial, sans-serif;
|
42
|
+
color: #5E5E5E;
|
43
|
+
font-weight: 600;
|
44
|
+
box-shadow: 0 1px 2px rgba(60, 64, 67, 0.30), 0 1px 3px rgba(60, 64, 67, 0.15);
|
45
|
+
outline: none;
|
46
|
+
" do %>
|
47
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21 21" style="width: 20px; height: 20px; margin-right: 12px;">
|
48
|
+
<rect x="1" y="1" width="9" height="9" fill="#f25022"/>
|
49
|
+
<rect x="1" y="11" width="9" height="9" fill="#00a4ef"/>
|
50
|
+
<rect x="11" y="1" width="9" height="9" fill="#7fba00"/>
|
51
|
+
<rect x="11" y="11" width="9" height="9" fill="#ffb900"/>
|
52
|
+
</svg>
|
53
|
+
<span style="margin-bottom: 0.1em;">
|
54
|
+
Sign <%= controller_name == 'registrations' ? 'up' : 'in' %> with <%= OmniAuth::Utils.camelize(provider) %>
|
55
|
+
</span>
|
56
|
+
<% end %>
|
52
57
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
58
|
+
<%- when :facebook -%>
|
59
|
+
<%= button_to omniauth_authorize_path(resource_name, provider), data: { turbo: false }, method: :post, style: "
|
60
|
+
display: flex;
|
61
|
+
align-items: center;
|
62
|
+
justify-content: center;
|
63
|
+
background-color: #1877F2;
|
64
|
+
border: none;
|
65
|
+
border-radius: 4px;
|
66
|
+
color: #FFFFFF;
|
67
|
+
font-weight: 600;
|
68
|
+
box-shadow: 0 1px 2px rgba(60, 64, 67, 0.30), 0 1px 3px rgba(60, 64, 67, 0.15);
|
69
|
+
outline: none;
|
70
|
+
" do %>
|
71
|
+
<svg xmlns="http://www.w3.org/2000/svg" style="width:30px;height:30px;margin-right:12px" viewBox="0 0 666.7 666.7">
|
72
|
+
<defs>
|
73
|
+
<clipPath id="a" clipPathUnits="userSpaceOnUse">
|
74
|
+
<path d="M0 700h700V0H0Z"/>
|
75
|
+
</clipPath>
|
76
|
+
</defs>
|
77
|
+
<g clip-path="url(#a)" transform="matrix(1.3333333 0 0 -1.3333333 -133 800)">
|
78
|
+
<path d="M0 0a250 250 0 1 1-310-243v167h-52V0h52v33c0 85 38 124 122 124 15 0 43-3 54-6V82l-29 1c-41 0-57-16-57-56V0h82l-14-76h-68v-172A250 250 0 0 1 0 0" style="fill:#fff;fill-opacity:1;fill-rule:nonzero;stroke:none" transform="translate(600 350)"/>
|
79
|
+
<path d="m0 0 14 76h-82v27c0 41 16 56 57 56l29-1v70c-11 3-38 6-54 6-84 0-122-40-122-125V76h-52V0h52v-166a251 251 0 0 1 90-6V0Z" style="fill:#1877f2;fill-opacity:1;fill-rule:nonzero;stroke:none" transform="translate(448 274)"/>
|
80
|
+
</g>
|
81
|
+
</svg>
|
82
|
+
<span>
|
83
|
+
<%= controller_name == 'registrations' ? 'Continue' : 'Log in' %> with <%= OmniAuth::Utils.camelize(provider) %>
|
84
|
+
</span>
|
85
|
+
<% end %>
|
81
86
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
87
|
+
<%- when :github -%>
|
88
|
+
<%= button_to omniauth_authorize_path(resource_name, provider), data: { turbo: false }, method: :post, style: "
|
89
|
+
display: flex;
|
90
|
+
align-items: center;
|
91
|
+
justify-content: center;
|
92
|
+
background-color: #000000;
|
93
|
+
border: none;
|
94
|
+
border-radius: 4px;
|
95
|
+
color: #FFFFFF;
|
96
|
+
font-weight: 600;
|
97
|
+
box-shadow: 0 1px 2px rgba(60, 64, 67, 0.30), 0 1px 3px rgba(60, 64, 67, 0.15);
|
98
|
+
outline: none;
|
99
|
+
" do %>
|
100
|
+
<svg xmlns="http://www.w3.org/2000/svg" style="width:30px;height:30px;margin-right:12px" viewBox="0 0 96 98">
|
101
|
+
<path fill="#fff" fill-rule="evenodd" d="M48.9 0a49.2 49.2 0 0 0-15.4 96c2.3.4 3.2-1.2 3.2-2.5v-9c-13.6 2.9-16.5-6-16.5-6-2.2-5.7-5.4-7.1-5.4-7.1-4.4-3 .3-3 .3-3 5 .3 7.5 5 7.5 5 4.4 7.5 11.5 5.4 14.3 4 .4-3 1.7-5.3 3-6.5-10.8-1.1-22.2-5.4-22.2-24.3 0-5.4 2-9.8 5-13.2-.5-1.2-2.2-6.3.5-13 0 0 4.1-1.3 13.4 5A47 47 0 0 1 49 23.8c4 0 8.3.6 12.2 1.6 9.3-6.3 13.4-5 13.4-5 2.7 6.7 1 11.8.5 13 3.1 3.4 5 7.8 5 13.2 0 19-11.4 23-22.3 24.3 1.7 1.5 3.3 4.5 3.3 9.1v13.5c0 1.3.8 2.9 3.2 2.4a49.2 49.2 0 0 0 33.4-46.7A49 49 0 0 0 49 0z" clip-rule="evenodd"/>
|
102
|
+
</svg>
|
103
|
+
<span>
|
104
|
+
Sign <%= controller_name == 'registrations' ? 'up' : 'in' %> with GitHub
|
105
|
+
</span>
|
106
|
+
<% end %>
|
102
107
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
108
|
+
<%- when :linkedin -%>
|
109
|
+
<%= button_to omniauth_authorize_path(resource_name, provider), data: { turbo: false }, method: :post, style: "
|
110
|
+
display: flex;
|
111
|
+
align-items: center;
|
112
|
+
justify-content: center;
|
113
|
+
background-color: #0077B5;
|
114
|
+
border: none;
|
115
|
+
border-radius: 4px;
|
116
|
+
color: #FFFFFF;
|
117
|
+
font-weight: 600;
|
118
|
+
box-shadow: 0 1px 2px rgba(60, 64, 67, 0.30), 0 1px 3px rgba(60, 64, 67, 0.15);
|
119
|
+
outline: none;
|
120
|
+
" do %>
|
121
|
+
<svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px;margin-right:12px" viewBox="0 0 72 72">
|
122
|
+
<g fill="none" fill-rule="evenodd">
|
123
|
+
<path fill="#FFF" d="M8 72h56c4 0 8-4 8-8V8c0-4-4-8-8-8H8C4 0 0 4 0 8v56c0 4 4 8 8 8Z"/>
|
124
|
+
<path fill="#007EBB" d="M62 62H51V44c0-5-2-8-6-8s-6 3-6 8v18H29V27h10v5s3-6 10-6c8 0 13 5 13 14v22ZM16 23c-3 0-6-3-6-7 0-3 3-6 6-6 4 0 7 3 7 6 0 4-3 7-7 7Zm-5 39h11V27H11v35Z"/>
|
125
|
+
</g>
|
126
|
+
</svg>
|
127
|
+
<span>
|
128
|
+
Sign <%= controller_name == 'registrations' ? 'up' : 'in' %> with <%= OmniAuth::Utils.camelize(provider) %>
|
129
|
+
</span>
|
130
|
+
<% end %>
|
126
131
|
|
127
|
-
|
132
|
+
<%- when :apple -%>
|
128
133
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
134
|
+
<%= button_to omniauth_authorize_path(resource_name, provider), data: { turbo: false }, method: :post, style: "
|
135
|
+
display: flex;
|
136
|
+
align-items: center;
|
137
|
+
justify-content: center;
|
138
|
+
background-color: #000000;
|
139
|
+
border: none;
|
140
|
+
border-radius: 4px;
|
141
|
+
color: #FFFFFF;
|
142
|
+
font-weight: 600;
|
143
|
+
box-shadow: 0 1px 2px rgba(60, 64, 67, 0.30), 0 1px 3px rgba(60, 64, 67, 0.15);
|
144
|
+
outline: none;" do %>
|
145
|
+
<svg xmlns="http://www.w3.org/2000/svg" style="width:30px;height:30px;margin-right:5px" viewBox="13 13 30 30">
|
146
|
+
<g fill="none" fill-rule="evenodd">
|
147
|
+
<path fill="#000" d="M6 6h44v44H6z"/>
|
148
|
+
<path fill="#FFF" fill-rule="nonzero" d="M28.2 20.4c.9 0 1.9-.6 2.5-1.4a4 4 0 0 0 1-2.6V16c-1 0-2 .6-2.8 1.4-.5.7-1 1.6-1 2.6v.4h.3Zm-3 14.6c1.2 0 1.7-.8 3.2-.8 1.4 0 1.7.8 3 .8 1.2 0 2-1.2 2.8-2.4 1-1.3 1.3-2.6 1.3-2.7 0 0-2.5-1-2.5-3.8 0-2.4 2-3.5 2-3.6a4.3 4.3 0 0 0-3.6-2c-1.4 0-2.6 1-3.3 1-.7 0-1.8-.9-3-.9-2.3 0-4.6 2-4.6 5.7 0 2.3.9 4.7 2 6.3.8 1.3 1.6 2.4 2.8 2.4Z"/>
|
149
|
+
</g>
|
150
|
+
</svg>
|
151
|
+
<span>
|
152
|
+
Sign <%= controller_name == 'registrations' ? 'up' : 'in' %> with <%= OmniAuth::Utils.camelize(provider) %>
|
153
|
+
</span>
|
154
|
+
<% end %>
|
150
155
|
|
151
|
-
|
156
|
+
<%- else -%>
|
152
157
|
|
153
|
-
|
158
|
+
<%= button_to "Sign #{controller_name == 'registrations' ? "up" : "in" } with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), data: { turbo: false } %>
|
154
159
|
|
160
|
+
<%- end -%>
|
155
161
|
<%- end -%>
|
156
162
|
<%- end -%>
|
@@ -1,26 +1,58 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
devise :omniauthable, omniauth_providers: Devise.omniauth_providers
|
2
|
+
devise :omniauthable, omniauth_providers: Devise.omniauth_providers
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
# # If you only want to allow sign-up from Omniauth providers,
|
5
|
+
# # which provide an email address, you can uncomment the following:
|
6
|
+
# validate :oauth_email_presence, on: :create
|
7
|
+
# def oauth_email_presence
|
8
|
+
# if provider.present? && email.blank?
|
9
|
+
# errors.add(:email, "wasn't provided by the login provider. Please sign up using an email address.")
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# # Also you need to override this method from Validatable (if used)
|
13
|
+
# # so that the email presence validation is not showing as a secondary error.
|
14
|
+
# def email_required?
|
15
|
+
# !provider.present?
|
16
|
+
# end
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# end
|
18
|
+
def self.from_omniauth(auth)
|
19
|
+
where(provider: auth.provider, uid: auth.uid)
|
20
|
+
.or(where(uid: nil, provider: nil, email: auth.info.email.downcase.strip))
|
21
|
+
.first_or_create do |user|
|
17
22
|
|
18
|
-
|
19
|
-
|
23
|
+
user.provider ||= auth.provider
|
24
|
+
user.uid ||= auth.uid
|
25
|
+
user.email = auth.info.email
|
26
|
+
user.password ||= Devise.friendly_token[0, 20]
|
27
|
+
|
28
|
+
# # Depending on the provider various infos might be available. Make sure your model has the necessary fields
|
29
|
+
#
|
30
|
+
# if auth.info.last_name.present? && auth.info.first_name.present?
|
31
|
+
# user.nickname = "#{auth.info.first_name} #{auth.info.last_name[0]}."
|
32
|
+
# elsif auth.info.name.present?
|
33
|
+
# user.nickname = auth.info.name
|
34
|
+
# end
|
35
|
+
# user.first_name = auth.info.first_name
|
36
|
+
# user.last_name = auth.info.last_name
|
37
|
+
# user.name = auth.info.name
|
38
|
+
# user.image_url = auth.info.image
|
20
39
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
40
|
+
# If you are using confirmable and the provider(s) you use validate emails,
|
41
|
+
# you can call `user.skip_confirmation!` to skip the confirmation emails.
|
42
|
+
#
|
43
|
+
# For example for LinkedIn OpenID Connect:
|
44
|
+
#
|
45
|
+
# if auth.provider == 'linkedin'
|
46
|
+
# if user.class.devise_modules.include?(:confirmable)
|
47
|
+
# if user.email.present? && auth.extra&.raw_info&.email_verified
|
48
|
+
# user.skip_confirmation!
|
49
|
+
# end
|
50
|
+
# else
|
51
|
+
# if user.email.present? && !auth.extra&.raw_info&.email_verified
|
52
|
+
# # We can't rely on this email really
|
53
|
+
# user.email = nil
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
end
|
58
|
+
end
|
@@ -33,8 +33,10 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|
33
33
|
error.to_s.humanize if error
|
34
34
|
end
|
35
35
|
|
36
|
+
# Might want to override default behaviour: set flash and redirect to
|
37
|
+
# after_omniauth_failure_path_for(resource_name)
|
36
38
|
def failure
|
37
39
|
# Might want to log this/instrument/notify
|
38
|
-
|
40
|
+
super
|
39
41
|
end
|
40
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
|
+
original_platform: ''
|
6
7
|
authors:
|
7
8
|
- Christopher Oezbek
|
8
|
-
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rails generator to create an Omniauth installation for Devise including
|
14
14
|
social login buttons.
|
@@ -18,7 +18,6 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- CHANGELOG.md
|
22
21
|
- README.md
|
23
22
|
- Rakefile
|
24
23
|
- lib/omniauth/generator.rb
|
@@ -36,7 +35,6 @@ metadata:
|
|
36
35
|
homepage_uri: https://github.com/coezbek/omniauth-generator
|
37
36
|
source_code_uri: https://github.com/coezbek/omniauth-generator
|
38
37
|
changelog_uri: https://github.com/coezbek/omniauth-generator/README.md#Changelog
|
39
|
-
post_install_message:
|
40
38
|
rdoc_options: []
|
41
39
|
require_paths:
|
42
40
|
- lib
|
@@ -51,8 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
49
|
- !ruby/object:Gem::Version
|
52
50
|
version: '0'
|
53
51
|
requirements: []
|
54
|
-
rubygems_version: 3.
|
55
|
-
signing_key:
|
52
|
+
rubygems_version: 3.6.1
|
56
53
|
specification_version: 4
|
57
54
|
summary: Rails generator to create an Omniauth installation for Devise
|
58
55
|
test_files: []
|