This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
structure routes and controller actions to support multiple oauth models
- Loading branch information
Showing
6 changed files
with
56 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class AuthenticationsController < Devise::OmniauthCallbacksController | ||
def google_oauth2 | ||
# we override the devise mapping because routing sets it to user | ||
request.env["devise.mapping"] = Devise.mappings[session[:authenticating].to_sym] | ||
|
||
@user = ConnectWithOauthProvider.connect(request.env["omniauth.auth"]) | ||
|
||
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: "Google" | ||
sign_in_and_redirect @user, event: :authentication | ||
rescue Champaign::NotWhitelisted | ||
redirect_to new_user_session_path, flash: {error: t('oauth.not_authorised')} | ||
end | ||
|
||
def user_passthru | ||
session[:authenticating] = 'user' | ||
redirect_to "/auth/#{params[:provider]}" | ||
end | ||
|
||
def member_passthru | ||
session[:authenticating] = 'member' | ||
redirect_to "/auth/#{params[:provider]}" | ||
end | ||
|
||
def failure | ||
# this is mostly a standin and needs some work | ||
redirect_to new_user_session_path, flash: {error: error_message} | ||
redirect_to after_omniauth_failure_path_for(resource_name) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ==> OmniAuth | ||
# Devise does not support multiple models with :omniauthable, so we're following | ||
# their recommendations on https://github.com/plataformatec/devise/wiki/OmniAuth-with-multiple-models | ||
|
||
require 'omniauth-google-oauth2' | ||
|
||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider :google_oauth2, Rails.application.secrets.omniauth_client_id, Rails.application.secrets.omniauth_client_secret, { access_type: "offline", approval_prompt: "" } | ||
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