Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should I integrate Devise two factor authentication with custom sessions controller? #61

ashvushinde opened this issue Dec 23, 2015 · 8 comments


Copy link

I integrated the Houdini two factor authentication with existing rails application.
First I doesn't have any custom sessions_controller then the two_factor_authentication is working fine.
But whereas I written custom create action in Sessions Controller then it doesn't authenticated by two_factor_authentication.

Here is the custom code for create action of Sessions Controller.

  if status_response.nil?
    render :file => 'public/api_not_found.html', :status => :not_found, :layout => false
    if status_response['code'].to_i == 1
      signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
      flash[:alert] = 'Invalid Email ID or password.'
      yield if block_given?
      self.resource = warden.authenticate!(auth_options)
      set_flash_message(:notice, :signed_in) if is_flashing_format?
      sign_in(resource_name, resource)
      yield resource if block_given?
      respond_with resource, location: after_sign_in_path_for(resource)

Model code of user.rb:

  devise :two_factor_authenticatable, :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable,
     :confirmable, password_length: 8..30

  def send_two_factor_authentication_code
    puts ">>>>>>>>>>>>>>> otp_secret_key: #{otp_secret_key}, otp_code: #{otp_code}"

I know if we are customizing the create action of Sessions Controller then we should call the two_factor_authentication. I tried to invoke this in controller but it throws an error.

So my question how should i integrate the two_factor_authentication with custom create action of Session Controller?

Copy link

kiote commented Mar 3, 2016

I'm on same page now, so if you have any answer, please, share!

Copy link

GitLab does this and is fully open source. I unfortunately don't know the exact location of the relevant code, but you can look through the repository and try to find it.

Copy link

Here's the Merge Request that introduced it, as well.

Copy link

kiote commented Mar 5, 2016

oh, thanks @connorshea, really!

I was thinking that I just need something equals to github have, but didn't remember about gitlab 🐠

Thanks 👍

Copy link

bsedat commented Mar 18, 2016

Glad you found an example! Thank you for the guidance @connorshea!

@bsedat bsedat closed this as completed Mar 18, 2016
Copy link

This ticket is confusing. The first question is asking about a different gem,, and using two_factor_authenticatable, but I don't think anyone noticed?

Copy link

@AndrewRayCode whoops!

Copy link

@AndrewRayCode happened to me like crazy. i tried both gems and for each i used the other gem doc and ragedquitted as nothing worked, created stupid issues and stuff. lololol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

6 participants