Last active
November 17, 2022 12:31
-
-
Save maxloncar/3f039e6bb7df88d15e5285cfdaaadf8a to your computer and use it in GitHub Desktop.
For Devise to understand additional logic happening during the authentication process
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
# app/controller/omniauth_callbacks_controller.rb | |
class OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def microsoft_office365 | |
callback_from :microsoft_office365 | |
end | |
def failure | |
redirect_to after_omniauth_failure_path_for(resource_name) | |
end | |
private | |
def callback_from(provider) | |
@user = User.find_for_oauth(request.env['omniauth.auth']) | |
if @user.persisted? | |
sign_in_and_redirect @user | |
else | |
flash[:error]='There was a problem signing you in through Office 365. Please register or try signing in later.' | |
redirect_to new_user_registration_url | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment