[英]How can I sign in via api using Devise in Rails?
I use Devise gem for auth and gem 'devise_token_auth' for api auth. 我将Devise gem用于身份验证,将gem'devise_token_auth'用于api身份验证。 In my routes I defined the following
在我的路线中,我定义了以下内容
devise_for :users
# token auth routes available at /api/v1/auth
namespace :api do
scope :v1 do
mount_devise_token_auth_for 'User', at: 'auth'
end
But now I trying to sign in using curl and get an error: My request for simple devise auth 但是现在我尝试使用curl登录并得到一个错误:我对简单设计验证的请求
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST http://localhost:3000/users/sign_in -d "{'user' : { 'email' : 'admin@mail.ru', 'password' : 'r465ee'}}" -c cookie
Error 错误
ActionDispatch::ParamsParser::Parse Error in Devise::SessionsController#create
The same for the auth scope route. 对于auth作用域路由也是如此。
mount_devise_token_auth_for 'User', at: 'auth'
means you mounted the engine on /auth
path. 表示您将引擎安装在
/auth
路径上。 /users/sign_in
is the original devise(session/cookies based) login path. /users/sign_in
是原始设计(基于会话/ cookies)的登录路径。 Also you don't need to use -c cookie
anymore because it's token based. 同样,您不再需要使用
-c cookie
,因为它是基于令牌的。
Try 尝试
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST http://localhost:3000/auth/sign_in -d "{'user' : { 'email' : 'admin@mail.ru', 'password' : 'r465ee'}}"
or including namespace and scope 或包括名称空间和范围
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST http://localhost:3000/api/v1/auth/sign_in -d "{'user' : { 'email' : 'admin@mail.ru', 'password' : 'r465ee'}}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.