Can't customize params to be jsonapi compliant
I want to have a jsonapi compliant way to log in.
My payload to the devise/sessions#create action is:
{"data"=>{"type"=>"sessions", "attributes"=>{"email"=>"[email protected]", "password"=>"123456"}}, "subdomain"=>"api", "format"=>:json, "controller"=>"devise/sessions", "action"=>"create", "session"=>{"data"=>{"type"=>"sessions", "attributes"=>{"email"=>"[email protected]", "password"=>"123456"}}}}
the authenticatable base strategy is not valid because there is no params[scope] since scope is user.
Why does the authenticatable strategy use the params object and not the devise_param_sanitizer?
I did this and it ought to work:
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_in) do |user_params|
x = params.require(:data).permit(:type, { attributes: [:email, :password] })
x[:attributes]
end
end
I'm trying to do the same. Any solution?
The only way i found to solve this was to override all the resource_params methods (also sing_up_params, sign_in_params... etc) on all devise controllers.
And after i solved this issue, i found out that warden authentication also failed due to this change in the request params.
Specifically the valid_for_params_auth? method on the Devise::Strategies::Authenticatable strategy
Seems like the devise_parameter_sanitizer solution should work.
I'm willing to accept a pull request that makes it possible to do it like in the provided example.
Hello,
I am looking to make my first open source contribution. Is this a good issue to take on? If not, feel free to point me other issues that might be good for someone that's new to open source. Thanks!
@aamarill I'm not sure what is the complexity of this one. It might be difficult or not. If you want to work on this, I can help with any doubts you have along the way. I'd start by creating a failing test of the desired behavior. The code mentioned on the issue should work, but currently, it doesn't:
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_in) do |user_params|
x = params.require(:data).permit(:type, { attributes: [:email, :password] })
x[:attributes]
end
end
So I think it's a good start to create a test with this implementation and them try to find out what's missing.
@tegon I think this method is also related:
https://github.com/plataformatec/devise/blob/1c8e97c75ace52be4e2d0531dd4fc70e95d3cb83/lib/devise/strategies/authenticatable.rb#L77