Eventbrite authentication using OAuth2.0 Rails

萝らか妹 提交于 2020-01-24 19:54:12

问题


Iam creating an application where I am trying to authentivate a user with eventbrite. With reference of doc I include the javascript in my application and it generates a CONNECT WITH EVENTBRITE link in my app.

When I click this button It takes me to the url:

https://www.eventbrite.com/oauth/authorize?response_type=token&client_id=xxxxxxxxxxxx

(Here client id is the eventbrite app key of my application.)

When the user ALLOWS the application to access the evenbrite account it redirects me to my application with the following url:

http://localhost:3000/#token_type=Bearer&access_token=yyyyyyyyyyyyyyyyyyyy

I want the access token in the url to access a user's information. I tried to parse url using URI. But I didn't find it the best way to do so.. Can anyone please tell me a good solution to extract the access_token from the above url.


回答1:


For server-side OAuth2.0, I'd use response_type=code in your initial URL:

https://www.eventbrite.com/oauth/authorize?response_type=code&client_id=xxxxxxxxxxxx

To find the access_code, grab the 'code' parameter from the querystring:

require 'uri'
uri = URI("http://localhost:3000/?code=XVYMCZOHM4D2GBXTJZG6")
access_code = uri.query.split('&')[0].split('=')[1]

The next step is to make a server-side POST to https://www.eventbrite.com/oauth/token with the temporary access_code, your client_secret, and a few other details (outlined here: http://developer.eventbrite.com/doc/authentication/oauth2/)

code=THE_USERS_AUTH_CODE&client_secret=YOUR_CLIENT_SECRET&client_id=YOUR_API_KEY&grant_type=authorization_code

The user's access_token should be available in the POST response.



来源:https://stackoverflow.com/questions/12365331/eventbrite-authentication-using-oauth2-0-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!