简体   繁体   English

Rails 5 API令牌认证

[英]Rails 5 API Token authentication

I'm building an API with rails 5 and I want to make token authentication to consomme it with angular 2 as frontend part, I've installed devise for that, I made some research and I'm seeing that all tutorial use devise_token_auth to manage that ! 我正在使用Rails 5构建一个API,并且我想进行令牌认证以将angular 2作为前端组件来完善它,为此我安装了devise,进行了一些研究,我发现所有教程都使用devise_token_auth进行管理那! can someone one can clarify this point for me ? 有人可以为我澄清这一点吗?

when I installed devise gem and test the sign_in route for an admin that I create it with postman, it return some thing like this : 当我安装devise gem并测试由邮递员创建的admin的sign_in路由时,它返回类似以下内容:

"exception": "#<ActionDispatch::Http::Parameters::ParseError: 822: unexpected token at '------WebKitFormBoundary6qQtmAd3sD9tG4pG\r\nContent-Disposition: form-data; name=\"email\"\r\n\r\nadmin@example.com\r\n------WebKitFormBoundary6qQtmAd3sD9tG4pG\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\nadmin1\r\n------WebKitFormBoundary6qQtmAd3sD9tG4pG--\r\n'>",

this the route.rb file : 这是route.rb文件:

Rails.application.routes.draw do
  devise_for :employes
  devise_for :admins

  namespace :admin do
    resources :vacation_applications
    resources :employes
  end



  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

admin class : 管理类:

class Admin < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, #:registerable,
         :recoverable, :rememberable, :trackable, :validatable
end

cans some one guide me to solve that please ? 能不能有人指导我解决这个问题?

Go to post man and select Body then select raw radio button. 转到发布人并选择“ 身体”,然后选择“ 原始”单选按钮。 There will be a drop down just beside the binary radio button on the same window. 同一窗口中的二进制单选按钮旁边将出现一个下拉列表。 Click and select JSON(application/json) . 单击并选择JSON(application / json)

Below you will find a text box after selecting raw . 选择raw之后,您会在下面找到一个文本框。 Insert a valid json payload to send as parameter. 插入有效的json有效负载以作为参数发送。

Example: 例:

{

 "user_email": "test@gmail.com",
 "password": "abc"

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM