-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1286 - Adopter Authentication: Add Oauth with google (#1309)
* Google Login implementation * lint fix and removed unwanted file * Comment for setting oauth and nesting modules * Remove password fields from settings for Google oauth users * Lint fix * Add production client ID and secret --------- Co-authored-by: Ben <robinsonbena@gmail.com>
- Loading branch information
1 parent
fe539e7
commit 437fe9d
Showing
18 changed files
with
283 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Users | ||
class OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
include OrganizationScopable | ||
|
||
def google_oauth2 | ||
@user = User.from_omniauth(request.env["omniauth.auth"]) | ||
if @user.persisted? | ||
sign_in_and_redirect @user, event: :authentication | ||
set_flash_message(:notice, :success, kind: "Google") if is_navigational_format? | ||
else | ||
session["devise.google_data"] = request.env["omniauth.auth"].except(:extra) | ||
redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n") | ||
end | ||
end | ||
|
||
def failure | ||
redirect_to root_path | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Omniauthable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
devise :omniauthable, omniauth_providers: [:google_oauth2] | ||
end | ||
|
||
class_methods do | ||
def from_omniauth(auth) | ||
where(provider: auth.provider, uid: auth.uid, organization_id: Current.organization.id).first_or_create do |user| | ||
user.assign_attributes_from_auth(auth) | ||
user.set_adopter_role | ||
end | ||
end | ||
end | ||
|
||
def assign_attributes_from_auth(auth) | ||
self.email = auth.info.email | ||
self.password = Devise.friendly_token[0, 20] | ||
self.first_name = auth.info.first_name if respond_to?(:first_name) | ||
self.last_name = auth.info.last_name if respond_to?(:last_name) | ||
end | ||
|
||
def set_adopter_role | ||
add_role("adopter", Current.organization) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4ERfYFtT9kWCK++LezB5gW0pmP8hN+mI1HQ9+Hx9N5TWfR7eIsQFlCoKKFrM3RSe3p5ZSDL5YTdFBKIFscYa23Sx9sgb0dw8hLc1Q0ItD4sfVqnbZPctFrWnUIlLihLth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930K34o13h6ifRVd7GUviezeOdzsAQRDe1THc0Hvrs09E8qXixXPqdpSWEceozMgXaeK/ZyixRHJ9Xl4u8RzAPc70QJUh6zRY/Mf+QRBsv4czmzjoskaIpMpXohA/SbQzSUfrsYQBEnYEaocxS9S1CI6ikwGWU0trXj77kzB4TUqK640k+KS4DNQe3F/2Lbf0Gu8D+msnrIusi5GnuOfXFjS109RO7faUngVxSpVxuBLcKErzpA96IKsCTMeJq+6N/2WwryW9rzRbtFKLKR6Ip8C0d+RysVA/Qe4RV3nujLhncyUHd1TGmUiCwX--D/R1K1hn1a4Zav38--9R0KJV0yoSyKYDs4fBxyXg== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OmniAuth.config.allowed_request_methods = [:get, :post] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddOmniauthToUsers < ActiveRecord::Migration[8.0] | ||
def change | ||
add_column :users, :provider, :string | ||
add_column :users, :uid, :string | ||
end | ||
end |
Oops, something went wrong.