twilio / authy-devise

Authy Devise plugin to add Two-Factor Authentication
MIT License
201 stars 84 forks source link

Custom action controller #113

Closed kori22 closed 2 years ago

kori22 commented 5 years ago

Hi, we have some issue for intgration, currently when login we need 3 information data like username, password, and code. 2 step authentication is work and cool. but jus only validate username and password, and our need is also to validate the code to select group user. so we need custom action after submit token. is there solustion for this issues ?

philnash commented 5 years ago

Hello, I'm not quite sure what you're asking for here. Could you explain the full user flow you are hoping to build and I'll see what I can suggest.

kori22 commented 5 years ago

Hi, so in our product we need 3 paramatter for login username, password, and code. the code here use for filter group of company user. you can see on this link https://www.greenhcm.com/users/sign_in?locale=en , on devise, we set custom action for decalre session code when sign in. but after we implement authy, code is not setting up into session, so i need custom action after success login with authy.

philnash commented 5 years ago

How were you storing the code before you implemented Authy?

kori22 commented 5 years ago

like this code

class Devise::SessionsController < DeviseController

  # POST /resource/sign_in
  def create
    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?

    # for active or inactive user
    # respond_with resource, location: after_sign_in_path_for(resource) # default redirect sign_in function
    company = ActiveRecord::Base.connection_pool.with_connection do
      Company.find_by_code(params[:company_code])
    end

    # company = Company.joins("LEFT JOIN user_companies ON user_companies.company_id = companies.id JOIN users ON users.id = user_companies.user_id").where("companies.code = ? and users.id = ?", params[:company_code], resource.id).first || {}
    if company.present?
      user_company = ActiveRecord::Base.connection_pool.with_connection do
        UserCompany.find_by_user_id_and_company_id(resource.id, company.id) 
      end 
    end

    company_active = (company.valid_datetime > DateTime.now) if company.present?
    if company.present? and user_company.present? and user_company.is_active and company_active
      if params[:user][:remember_me] == "1"
        cookies.permanent[:regcom] = company.auth_token
      else
        cookies[:regcom] = company.auth_token
      end
      respond_with resource, location: after_sign_in_path_for(resource)
    end

  end
end
kori22 commented 5 years ago

hi, now i can customize GET_verify_authy on devise_authy_controller.rb, but the sign_in parameter not included on there, as you see my system have Company code paramaeter on sign in like this link https://www.greenhcm.com/users/sign_in?locale=en , can i get sign_in paramater specially code parameter on GET_verify_authy ?

philnash commented 2 years ago

This library is no longer actively maintained. The Authy API has been replaced with the Twilio Verify API. Twilio will support the Authy API through November 1, 2022 for SMS/Voice. After this date, we’ll start to deprecate the service for SMS/Voice. Any requests sent to the API after May 1, 2023, will automatically receive an error. Push and TOTP will continue to be supported through July 2023.

Learn more about migrating from Authy to Verify.

Please visit the Twilio Docs for:

Please direct any questions to Twilio Support. Thank you!