监狱长身份验证返回 401
warden authentication returning 401
warden.authenticate!(auth_options)
这些参数工作正常:
{"utf8"=>"✓",
"authenticity_token"=>"5BMAUoZLUEgPZBVOAcQ8lFD4+pumP9kEvvXyelbnjeO36AZJQt2oRlraicQ6quvh/dccS0ELUkxjACgFcWFYAg==",
"user"=>{"email"=>"vijay@xyz.com", "password"=>"xyz",
"phone"=>"9443429932"}, "action"=>"create", "controller"=>"sessions",
"format"=>"json", "session"=>{"user"=>{"email"=>"vijay@xyz.com",
"password"=>"xyz", "phone"=>"9443429932"}}}
但这些都失败了:
{"utf8"=>"✓",
"authenticity_token"=>"/ly2phwfsD3HEVkHK39ajYQGv6R4uj2z3B+3eiZEU0qtp7C92IlIM5KvxY0QEY34KSlZdJ+OtvsB6m0FAcKGqw==",
"user"=>{"phone"=>"9443429932", "password"=>"xyz",
"email"=>"vijay@xyz.com"}, "action"=>"create",
"controller"=>"sessions", "format"=>"json",
"session"=>{"user"=>{"phone"=>"9443429932", "password"=>"xyz",
"email"=>"vijay@xyz.com"}}}
除了顺序不同,两种情况下的数据都是一样的。
坚持了很长时间。
这是日志:
Started POST "/users/sign_in.json" for 127.0.0.1 at 2017-04-10
10:53:07 +0530 Processing by SessionsController#create as JSON
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"XVMbYLTgv4eFbv9pX5lJD3U6DHF17o18rVIjqQLo4skOqB17cHZHidDQY+Nk95562BXqoZLaBjRwp/nWJW43KA==",
"user"=>{"phone"=>"9443429932", "password"=>"[FILTERED]"},
"session"=>{"user"=>{"phone"=>"9443429932",
"password"=>"[FILTERED]"}}} User Load (0.3ms) SELECT users
.* FROM
users
WHERE users
.id
= 12422916 AND (invitation_token is null)
LIMIT 1 Completed 401 Unauthorized in 15ms
发现问题。
典狱长正在阅读来自 request.params 的参数
我已经编辑了参数,但它没有反映在 request.params.
request.params[:user].merge!(params[:user])
这解决了问题。
warden.authenticate!(auth_options)
这些参数工作正常:
{"utf8"=>"✓", "authenticity_token"=>"5BMAUoZLUEgPZBVOAcQ8lFD4+pumP9kEvvXyelbnjeO36AZJQt2oRlraicQ6quvh/dccS0ELUkxjACgFcWFYAg==", "user"=>{"email"=>"vijay@xyz.com", "password"=>"xyz", "phone"=>"9443429932"}, "action"=>"create", "controller"=>"sessions", "format"=>"json", "session"=>{"user"=>{"email"=>"vijay@xyz.com", "password"=>"xyz", "phone"=>"9443429932"}}}
但这些都失败了:
{"utf8"=>"✓", "authenticity_token"=>"/ly2phwfsD3HEVkHK39ajYQGv6R4uj2z3B+3eiZEU0qtp7C92IlIM5KvxY0QEY34KSlZdJ+OtvsB6m0FAcKGqw==", "user"=>{"phone"=>"9443429932", "password"=>"xyz", "email"=>"vijay@xyz.com"}, "action"=>"create", "controller"=>"sessions", "format"=>"json", "session"=>{"user"=>{"phone"=>"9443429932", "password"=>"xyz", "email"=>"vijay@xyz.com"}}}
除了顺序不同,两种情况下的数据都是一样的。 坚持了很长时间。
这是日志:
Started POST "/users/sign_in.json" for 127.0.0.1 at 2017-04-10 10:53:07 +0530 Processing by SessionsController#create as JSON
Parameters: {"utf8"=>"✓", "authenticity_token"=>"XVMbYLTgv4eFbv9pX5lJD3U6DHF17o18rVIjqQLo4skOqB17cHZHidDQY+Nk95562BXqoZLaBjRwp/nWJW43KA==", "user"=>{"phone"=>"9443429932", "password"=>"[FILTERED]"}, "session"=>{"user"=>{"phone"=>"9443429932", "password"=>"[FILTERED]"}}} User Load (0.3ms) SELECTusers
.* FROMusers
WHEREusers
.id
= 12422916 AND (invitation_token is null) LIMIT 1 Completed 401 Unauthorized in 15ms
发现问题。 典狱长正在阅读来自 request.params 的参数 我已经编辑了参数,但它没有反映在 request.params.
request.params[:user].merge!(params[:user])
这解决了问题。