简体   繁体   English

devise_token_auth如何通过令牌识别用户

[英]devise_token_auth how to identify a user by token

I am new to use gem devise_token_auth and working on a mobile client api, two questions: 我是第一次使用gem devise_token_auth并使用移动客户端api,这是两个问题:

1) How should i identify a user? 1)我应该如何识别用户? My current understanding is on a http request header set access_token is this right? 我目前的理解是在http请求标头集access_token上对吗?

But seems from the source code i should provide for uid , access_token , client link uid = request.headers['did'] @token = request.headers['access-token'] @client_id = request.headers['client'] 但是从源代码看来,我应该提供uidaccess_token客户端 链接 uid = request.headers['did'] @token = request.headers['access-token'] @client_id = request.headers['client']

2) i can find a user.tokens like below: 2)我可以找到一个user.tokens如下:

 {"AOYZdDmwI7WQr8I6T4PpPw"=>{"token"=>"$2a$10$C/5f3JV7.9DZG8w.ggdCPelB6kzitWuGK4rfozHv15Hhf/x9DaCcO", "expiry"=>1473485374, "last_token"=>"$2a$10$abctsIP5bHPIm2nMXFTUH.1jPWQ5LiGTTrENjoqihWgcCkwRqbxb6", "updated_at"=>"2016-08-27T13:29:34.948+08:00"}}

which is client and which is access-token ? 哪个是client ,哪个是访问令牌

Thank you! 谢谢!

 headers = JSON.parse(cookies['authHeaders']) uid = headers['uid'] token = headers['access-token'] client_id = headers['client'] user = User.find_by_uid(uid) if !user || !user.valid_token?(token, client_id) render json: {error: "Usuario no autorizado."}, status: 401 end 

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

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