Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

ruby on rails - Devise Omniauth : POST data using href link

I would like to create a link that could POST data. Actually, I have a front in vuejs and a backend in rails. I already have my own authentication system with Devise gem. And I would like a user (who is already logged in) to be able to connect to other omniauth services (github, google...).

The problem is that as soon as I go on the link /auth/github (for example) my backend tells me that I didn't send the user's authentication token because i don't know how to send it.

That's why I would like to send datas (here, the auth token) directly from the link

Thanks

question from:https://stackoverflow.com/questions/65916531/devise-omniauth-post-data-using-href-link

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Like @Eyeslandic pointed out, your title is misleading, you have an OAuth or OAuth2 problem not a link problem.

If I can guess correctly you are getting a Get response (the token is in the link) and you want it to be a post response (the token in the request body) ... Are you using passport.js ? Must be a matter of configuration.

There is nothing wrong with receiving the token in the link, OAuth protocols are secure enough, whether it's a Get or a Post response.

If you want to read the token from the link, check this answer.

login.get('/p', function(req, res) {
    const token = req.query.theReturnedTokenNameInTheLink
    res.send("My token is " + token);
});

And the token is just a key that give you access to the host (github, google, facebook ...) Api, you should make another request to those API's, in order to get the user data, you could use a library like passport.js to simplify things, here is one of the tutorials, I found on how to use passport.js

Good luck.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...