Skip to content

Commit

Permalink
allowing authenticating using headers as well as a post request
Browse files Browse the repository at this point in the history
  • Loading branch information
ingolfured committed Mar 16, 2016
1 parent b675af8 commit 5243f1a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/controllers/devise_token_auth/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def resource_errors
protected

def params_for_resource(resource)
devise_parameter_sanitizer.instance_values['permitted'][resource].each do |type|

This comment has been minimized.

Copy link
@MiguelMachadoPalisis

MiguelMachadoPalisis Jun 14, 2016

Hi, I don't know if this is the correct place to put this comment or not, but I'm having an issue in this line due to the next reason. Here, my values are the next:

[1] pry(#DeviseTokenAuth::SessionsController)> devise_parameter_sanitizer.instance_values['permitted']
{
:sign_in => #Proc:0x007f0eabb845a0@app/controllers/application_controller.rb:18,
:sign_up => #Proc:0x007f0eabb845c8@/app/controllers/application_controller.rb:10,
:account_update => [
[0] :email,
[1] :password,
[2] :password_confirmation,
[3] :current_password
]
}

:sign_in and :sign_up both are Proc objects that lack "each" method, and that is firing me the next error:

NoMethodError - undefined method each' for #<Proc:0x007f0ea8951ec0>: () home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/devise_token_auth-bc047473ba7c/app/controllers/devise_token_auth/application_controller.rb:21:inparams_for_resource'
() home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/devise_token_auth-bc047473ba7c/app/controllers/devise_token_auth/sessions_controller.rb:144:in resource_params' () home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/devise_token_auth-bc047473ba7c/app/controllers/devise_token_auth/sessions_controller.rb:13:increate'

Here is how my application_controller is defined:

before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) do |user_params|
user_params.permit(:email, :password, :password_confirmation)
end
devise_parameter_sanitizer.permit(:sign_in) do |user_params|
user_params.permit(:email, :password, :session)
end
end

I don't know if I'm missing something, or doing something wrong to get those values as Proc objects.

Thanks

params[type.to_s] ||= request.headers[type.to_s] unless request.headers[type.to_s].nil?
end
devise_parameter_sanitizer.instance_values['permitted'][resource]
end

Expand Down
15 changes: 15 additions & 0 deletions test/controllers/devise_token_auth/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
end
end

describe 'header sign_in is supported' do
before do
request.headers.merge!(
'email' => @existing_user.email,
'password' => 'secret123')

xhr :head, :create
@data = JSON.parse(response.body)
end

test 'user can sign in using header request' do
assert_equal 200, response.status
end
end

describe 'alt auth keys' do
before do
xhr :post, :create, {
Expand Down

0 comments on commit 5243f1a

Please sign in to comment.