add MS oauth
This commit is contained in:
committed by
Pete Matsyburka
parent
83ce401cf2
commit
9f48c6e625
@@ -21,7 +21,9 @@ gem 'jwt'
|
|||||||
gem 'lograge'
|
gem 'lograge'
|
||||||
gem 'mysql2', require: false
|
gem 'mysql2', require: false
|
||||||
gem 'oj'
|
gem 'oj'
|
||||||
|
gem 'omniauth-github'
|
||||||
gem 'omniauth-google-oauth2'
|
gem 'omniauth-google-oauth2'
|
||||||
|
gem 'omniauth-microsoft-office365'
|
||||||
gem 'omniauth-rails_csrf_protection'
|
gem 'omniauth-rails_csrf_protection'
|
||||||
gem 'pagy'
|
gem 'pagy'
|
||||||
gem 'pdf-reader'
|
gem 'pdf-reader'
|
||||||
|
|||||||
@@ -328,11 +328,17 @@ GEM
|
|||||||
hashie (>= 3.4.6)
|
hashie (>= 3.4.6)
|
||||||
rack (>= 2.2.3)
|
rack (>= 2.2.3)
|
||||||
rack-protection
|
rack-protection
|
||||||
|
omniauth-github (2.0.1)
|
||||||
|
omniauth (~> 2.0)
|
||||||
|
omniauth-oauth2 (~> 1.8)
|
||||||
omniauth-google-oauth2 (1.1.1)
|
omniauth-google-oauth2 (1.1.1)
|
||||||
jwt (>= 2.0)
|
jwt (>= 2.0)
|
||||||
oauth2 (~> 2.0.6)
|
oauth2 (~> 2.0.6)
|
||||||
omniauth (~> 2.0)
|
omniauth (~> 2.0)
|
||||||
omniauth-oauth2 (~> 1.8.0)
|
omniauth-oauth2 (~> 1.8.0)
|
||||||
|
omniauth-microsoft-office365 (0.0.8)
|
||||||
|
omniauth
|
||||||
|
omniauth-oauth2
|
||||||
omniauth-oauth2 (1.8.0)
|
omniauth-oauth2 (1.8.0)
|
||||||
oauth2 (>= 1.4, < 3)
|
oauth2 (>= 1.4, < 3)
|
||||||
omniauth (~> 2.0)
|
omniauth (~> 2.0)
|
||||||
@@ -589,7 +595,9 @@ DEPENDENCIES
|
|||||||
lograge
|
lograge
|
||||||
mysql2
|
mysql2
|
||||||
oj
|
oj
|
||||||
|
omniauth-github
|
||||||
omniauth-google-oauth2
|
omniauth-google-oauth2
|
||||||
|
omniauth-microsoft-office365
|
||||||
omniauth-rails_csrf_protection
|
omniauth-rails_csrf_protection
|
||||||
pagy
|
pagy
|
||||||
pdf-reader
|
pdf-reader
|
||||||
|
|||||||
+4
-1
@@ -58,7 +58,10 @@ class User < ApplicationRecord
|
|||||||
has_many :email_messages, dependent: :destroy
|
has_many :email_messages, dependent: :destroy
|
||||||
|
|
||||||
devise :two_factor_authenticatable, :recoverable, :rememberable, :validatable, :trackable
|
devise :two_factor_authenticatable, :recoverable, :rememberable, :validatable, :trackable
|
||||||
devise :registerable, :omniauthable, omniauth_providers: [:google_oauth2] if Docuseal.multitenant?
|
|
||||||
|
if Docuseal.multitenant?
|
||||||
|
devise :registerable, :omniauthable, omniauth_providers: %i[google_oauth2 microsoft_office365 github]
|
||||||
|
end
|
||||||
|
|
||||||
attribute :role, :string, default: ADMIN_ROLE
|
attribute :role, :string, default: ADMIN_ROLE
|
||||||
attribute :uuid, :string, default: -> { SecureRandom.uuid }
|
attribute :uuid, :string, default: -> { SecureRandom.uuid }
|
||||||
|
|||||||
@@ -16,11 +16,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if devise_mapping.omniauthable? %>
|
<% if devise_mapping.omniauthable? %>
|
||||||
<%= form_for '', url: omniauth_authorize_path(resource_name, :google_oauth2), data: { turbo: false }, method: :post do |f| %>
|
<div class="space-y-4">
|
||||||
<set-timezone data-input-id="state" data-params="true"></set-timezone>
|
<%= form_for '', url: omniauth_authorize_path(resource_name, :google_oauth2), data: { turbo: false }, method: :post do |f| %>
|
||||||
<%= hidden_field_tag :state, { redir: params[:redir].to_s }.compact_blank.to_query %>
|
<set-timezone data-input-id="state" data-params="true"></set-timezone>
|
||||||
<%= f.button button_title(title: 'Sign up with Google', icon: svg_icon('brand_google', class: 'w-6 h-6')), class: 'white-button w-full mt-4' %>
|
<%= hidden_field_tag :state, { redir: params[:redir].to_s }.compact_blank.to_query %>
|
||||||
<% end %>
|
<%= f.button button_title(title: 'Sign up with Google', icon: svg_icon('brand_google', class: 'w-6 h-6')), class: 'white-button w-full mt-4' %>
|
||||||
|
<% end %>
|
||||||
|
<%= form_for '', url: omniauth_authorize_path(resource_name, :microsoft_office365), data: { turbo: false }, method: :post do |f| %>
|
||||||
|
<set-timezone data-input-id="state_microsoft" data-params="true"></set-timezone>
|
||||||
|
<%= hidden_field_tag :state, { redir: params[:redir].to_s }.compact_blank.to_query, id: 'state_microsoft' %>
|
||||||
|
<%= f.button button_title(title: 'Sign up with Microsoft', icon: svg_icon('brand_microsoft', class: 'w-6 h-6')), class: 'white-button w-full' %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= render 'devise/shared/links' %>
|
<%= render 'devise/shared/links' %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,11 +20,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if devise_mapping.omniauthable? %>
|
<% if devise_mapping.omniauthable? %>
|
||||||
<%= form_for '', url: omniauth_authorize_path(resource_name, :google_oauth2), data: { turbo: false }, method: :post do |f| %>
|
<div class="space-y-4">
|
||||||
<set-timezone data-input-id="state" data-params="true"></set-timezone>
|
<%= form_for '', url: omniauth_authorize_path(resource_name, :google_oauth2), data: { turbo: false }, method: :post do |f| %>
|
||||||
<%= hidden_field_tag :state, { redir: params[:redir].to_s }.compact_blank.to_query %>
|
<set-timezone data-input-id="state" data-params="true"></set-timezone>
|
||||||
<%= f.button button_title(title: 'Sign in with Google', icon: svg_icon('brand_google', class: 'w-6 h-6')), class: 'white-button w-full mt-4' %>
|
<%= hidden_field_tag :state, { redir: params[:redir].to_s }.compact_blank.to_query %>
|
||||||
<% end %>
|
<%= f.button button_title(title: 'Sign in with Google', icon: svg_icon('brand_google', class: 'w-6 h-6')), class: 'white-button w-full mt-4' %>
|
||||||
|
<% end %>
|
||||||
|
<%= form_for '', url: omniauth_authorize_path(resource_name, :microsoft_office365), data: { turbo: false }, method: :post do |f| %>
|
||||||
|
<set-timezone data-input-id="state_microsoft" data-params="true"></set-timezone>
|
||||||
|
<%= hidden_field_tag :state, { redir: params[:redir].to_s }.compact_blank.to_query, id: 'state_microsoft' %>
|
||||||
|
<%= f.button button_title(title: 'Sign in with Microsoft', icon: svg_icon('brand_microsoft', class: 'w-6 h-6')), class: 'white-button w-full' %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= render 'devise/shared/links' %>
|
<%= render 'devise/shared/links' %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" x="0px" y="0px" width="100" height="100" viewBox="0 0 48 48">
|
||||||
|
<path fill="#ff5722" d="M6 6H22V22H6z" transform="rotate(-180 14 14)"></path><path fill="#4caf50" d="M26 6H42V22H26z" transform="rotate(-180 34 14)"></path><path fill="#ffc107" d="M26 26H42V42H26z" transform="rotate(-180 34 34)"></path><path fill="#03a9f4" d="M6 26H22V42H6z" transform="rotate(-180 14 34)"></path>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 463 B |
@@ -14,6 +14,7 @@ Devise.otp_allowed_drift = 60.seconds
|
|||||||
#
|
#
|
||||||
# Use this hook to configure devise mailer, warden hooks and so forth.
|
# Use this hook to configure devise mailer, warden hooks and so forth.
|
||||||
# Many of these configuration options can be set straight in your model.
|
# Many of these configuration options can be set straight in your model.
|
||||||
|
# rubocop:disable Metrics/BlockLength
|
||||||
Devise.setup do |config|
|
Devise.setup do |config|
|
||||||
config.warden do |manager|
|
config.warden do |manager|
|
||||||
manager.default_strategies(scope: :user).unshift(:two_factor_authenticatable)
|
manager.default_strategies(scope: :user).unshift(:two_factor_authenticatable)
|
||||||
@@ -277,6 +278,12 @@ Devise.setup do |config|
|
|||||||
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
||||||
# up on your models and hooks.
|
# up on your models and hooks.
|
||||||
config.omniauth :google_oauth2, ENV.fetch('GOOGLE_CLIENT_ID', nil), ENV.fetch('GOOGLE_CLIENT_SECRET', nil), {}
|
config.omniauth :google_oauth2, ENV.fetch('GOOGLE_CLIENT_ID', nil), ENV.fetch('GOOGLE_CLIENT_SECRET', nil), {}
|
||||||
|
config.omniauth :microsoft_office365, ENV.fetch('OFFICE365_CLIENT_ID', nil),
|
||||||
|
ENV.fetch('OFFICE365_CLIENT_SECRET', nil), {}
|
||||||
|
|
||||||
|
if ENV['GITHUB_CLIENT_ID']
|
||||||
|
config.omniauth :github, ENV.fetch('GITHUB_CLIENT_ID', nil), ENV.fetch('GITHUB_CLIENT_SECRET', nil), {}
|
||||||
|
end
|
||||||
|
|
||||||
# ==> Warden configuration
|
# ==> Warden configuration
|
||||||
# If you want to use other strategies, that are not supported by Devise, or
|
# If you want to use other strategies, that are not supported by Devise, or
|
||||||
@@ -316,3 +323,4 @@ Devise.setup do |config|
|
|||||||
# changed. Defaults to true, so a user is signed in automatically after changing a password.
|
# changed. Defaults to true, so a user is signed in automatically after changing a password.
|
||||||
# config.sign_in_after_change_password = true
|
# config.sign_in_after_change_password = true
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/BlockLength
|
||||||
|
|||||||
+13
-4
@@ -4,12 +4,21 @@ module Users
|
|||||||
module_function
|
module_function
|
||||||
|
|
||||||
def from_omniauth(oauth)
|
def from_omniauth(oauth)
|
||||||
user = User.find_by(email: oauth.info.email)
|
user = User.find_by(email: oauth.info.email.to_s.downcase)
|
||||||
|
|
||||||
return user if user
|
return user if user
|
||||||
|
|
||||||
User.new(email: oauth.info.email,
|
case oauth['provider'].to_s
|
||||||
first_name: oauth.extra.id_info.given_name,
|
when 'google_oauth2'
|
||||||
last_name: oauth.extra.id_info.family_name)
|
User.new(email: oauth.info.email,
|
||||||
|
first_name: oauth.extra.id_info.given_name,
|
||||||
|
last_name: oauth.extra.id_info.family_name)
|
||||||
|
when 'microsoft_office365'
|
||||||
|
User.new(email: oauth.info.email,
|
||||||
|
first_name: oauth.info.first_name,
|
||||||
|
last_name: oauth.info.last_name)
|
||||||
|
when 'github'
|
||||||
|
User.new(email: oauth.info.email, first_name: oauth.info.name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user