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

Closed
ashvushinde opened this issue Dec 23, 2015 · 8 comments

Comments

@ashvushinde
Copy link

@ashvushinde ashvushinde commented Dec 23, 2015

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
  else
    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?
      respond_to_on_destroy
    else
      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)
    end
  end

Model code of user.rb:

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


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

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?

@kiote
Copy link

@kiote kiote commented Mar 3, 2016

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

@connorshea
Copy link
Contributor

@connorshea connorshea commented Mar 5, 2016

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.

@connorshea
Copy link
Contributor

@connorshea connorshea commented Mar 5, 2016

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

@kiote
Copy link

@kiote 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 👍

@bsedat
Copy link
Member

@bsedat bsedat commented Mar 18, 2016

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

@bsedat bsedat closed this Mar 18, 2016
@AndrewRayCode
Copy link

@AndrewRayCode AndrewRayCode commented Apr 11, 2017

This ticket is confusing. The first question is asking about a different gem, https://github.com/Houdini/two_factor_authentication, and using two_factor_authenticatable, but I don't think anyone noticed?

@connorshea
Copy link
Contributor

@connorshea connorshea commented Apr 11, 2017

@AndrewRayCode whoops!

@krtschmr
Copy link

@krtschmr krtschmr commented Jan 28, 2019

@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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.