简体   繁体   中英

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:

1) How should i identify a user? My current understanding is on a http request header set access_token is this right?

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']

2) i can find a user.tokens like below:

 {"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 ?

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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