Skip to content

Instantly share code, notes, and snippets.

@maxloncar
Last active November 17, 2022 12:31
Show Gist options
  • Save maxloncar/3f039e6bb7df88d15e5285cfdaaadf8a to your computer and use it in GitHub Desktop.
Save maxloncar/3f039e6bb7df88d15e5285cfdaaadf8a to your computer and use it in GitHub Desktop.
For Devise to understand additional logic happening during the authentication process
# 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