Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example app missing POST /oauth/token #64

Open
tomas opened this issue Nov 28, 2013 · 1 comment
Open

Example app missing POST /oauth/token #64

tomas opened this issue Nov 28, 2013 · 1 comment

Comments

@tomas
Copy link

tomas commented Nov 28, 2013

First of all, good job fine sir.

I was looking at the example app and trying to make a consumer for it using Omniauth (specifically, the omniauth-oauth2 gem). However, during the callback process, the Omniauth strategy sends a POST request to the provider at /oauth/token, and it's getting a 404 response which blows up everything.

From what I've been reading, that endpoint is supposed to verify the code that is sent and return the access_token, so that the full authorization cycle is completed. However that logic isn't there and I couldn't find anything in the documentation to point me in the right direction.

I assume I'd need to add something like:

post '/oauth/token' do
  @auth = Songkick::OAuth2::Model::Authorization.find_by_code(params[:code])

  return halt 400 unless @auth
  @auth.generate_access_token if @auth.expired?

  JSON.unparse({
    'access_token'  => @auth.access_token,
    'token_type'    => 'Bearer',
    'expires_in'    => @auth.expires_in,
    'refresh_token' => @auth.refresh_token
  })
end

Or will hell break loose if I do that?

@jon-eachscape
Copy link

It isn't entirely clear in the documentation, but the /oauth/authorize endpoint in their example handles this token exchange for you. I'd advise you follow that, as it takes care of all the validations and response generation.

In my case, I ended up setting up /oauth/authorize and /oauth/token to go to the same place, but with their Sinatra example, you'd have to tell omniauth to use /oauth/authorize for both the authorize_url and token_url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants