问题
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