Sha256: 25ef43f384790a915a4584372bc2b38736a1123b2c01e08366a0404641656c66

Contents?: true

Size: 764 Bytes

Versions: 3

Compression:

Stored size: 764 Bytes

Contents

Warden::Strategies.add(:token_authentication) do
  def subdomain
    ActionDispatch::Http::URL.extract_subdomains(request.host, 1)
  end

  def json_params
    unless params.empty?
      params
    else
      @json ||= env['rack.input'].gets
      JSON.parse(@json)
    end
  end

  def valid?
    subdomain.present? && json_params["auth_token"]
  end

  def authenticate!
    account = Cadenero::V1::Account.get_by_subdomain(subdomain)
    if account
      member = account.members.where(auth_token: json_params["auth_token"]).first
      u = nil
      u = member.user unless member.nil?
      if u.nil? || u.blank?
        fail!
      else
        env['warden'].set_user(u.id, :scope => :user)
        success!(u)
      end
    else
      fail!
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cadenero-0.0.2.b10 config/initializers/warden/strategies/token_authentication.rb
cadenero-0.0.2.b8 config/initializers/warden/strategies/token_authentication.rb
cadenero-0.0.2.b7 config/initializers/warden/strategies/token_authentication.rb