简体   繁体   中英

How to store github access_token in rails app?

I want to integrate GitHub OAuth to my rails app, I don't want to use the the third party gems, like OmniAuth, warden-github and so on. According to GitHub Basics of Authentication , I got the access_token. The Guide store the access_token to the session:

...
session[:access_token] = JSON.parse(result)['access_token']
...

but if another user login my app by github account, the value of session[:access_token] will be override, how to handle this situation?Hope someone can give me some good ideas, thanks in advance!

As both @dimakura and @Max Williams have pointed out - Rails stores that data in its session object in a cookie, which is stored on the client/user's computer. Thus, each user will have his own session[:access_token] which you can use to perform calls to the GitHub API for that particular user.

For a more thorough description on how Rails uses the session object I highly recommend this article by Justin Weiss.

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