[英]How can I handle the access-token in devise_token_auth
I am trying to create an API for an application (both in Rails), but I have many doubts regarding authentication through an API. 我正在尝试为应用程序(都在Rails中)创建API,但是我对通过API进行身份验证有很多疑问。
Contextualizing a bit what I'm doing. 上下文化我在做什么。
Now the question I have is with respect to login, the description in devise_token_auth about the sign_in
path is: 现在我有关于登录的问题,在devise_token_auth中有关
sign_in
路径的描述是:
Email authentication. Requires email and password as params. This route will return a JSON representation of the User model on successful login along with the access-token and client in the header of the response.
The problem is that I don't know how to handle the access-token
, for example, if I execute this: 问题是,例如,如果执行此命令, 我将不知道如何处理
access-token
:
@result = HTTParty.post('url_of_my_api_on_heroku/auth/sign_in', :body => {"email": "someemail@example.com", "password": "ABCDEFGHI"}.to_json, :headers => { 'Content-Type' => 'application/json' })
On the application that will consume the API's services and I display the value of @result
I can see the user data successfully... BUT I don't know how to get the access-token
, nor use it . 在将使用API服务的应用程序上,我显示了
@result
的值,我可以成功看到用户数据... 但是我不知道如何获取access-token
,也不使用它 。
I need some help, please. 我需要一些帮助。
This is how you get the access-token: 这是获取访问令牌的方式:
@result = HTTParty.post('url_of_my_api_on_heroku/auth/sign_in', :body => {"email": "someemail@example.com", "password": "ABCDEFGHI"}.to_json, :headers => { 'Content-Type' => 'application/json' })
@access_token = @result_login.headers["access-token"]
Now @access_token
will have the current value of the access-token
. 现在,
@access_token
将具有access-token
的当前值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.