We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

Togor's avatar
Togor
Explorer | Level 3
6 years ago

Ruby API v2 Client got Internal Server Error after redirected from oauth2.authorize

I deployed my Ruby app in GAE, and browsed it with url: https://xxxxxxxxxxxxxx.appspot.com/.

After directed to https://www.dropbox.com/oauth2/authorize, I click the Allow, the the page was directed to 

https://xxxxxxxxxxxxxx.appspot.com/auth, and only showed: Internal Server Error

 

Part of my code is pasted below:

def authenticator
    # Create dropbox session object and serialize it to the Sinatra session
    authenticator = DropboxApi::Authenticator.new(APP_KEY, APP_SECRET)
end

enable :sessions

get '/' do
    @loggedin = (session[:dropbox] != nil)
    erb :index
end

get '/login' do
    session[:dropbox] = 'init'
    # redirect user to Dropbox auth page
    redirect authenticator.authorize_url :redirect_uri => URL #= dropbox_session.get_authorize_url(URL)
end

get '/auth' do

    redirect 'login' unless session[:dropbox] == 'init'

    auth = authenticator.get_token(params['code'], :redirect_uri => URL)
    token = auth.token

    session[:dropbox] = token
    redirect '/write'
end

 

 

This is the log: 

2020-07-05 11:47:50 default[20200705t193819] https://xxxxxxxxxxxxxx.appspot.com/ -> /login
2020-07-05 11:48:47 default[20200705t193819] "GET /write?code=jezOSqKvFNAAAAAAAAAAT42cxSNkV3SGaY2HhBnt-28 HTTP/1.1" 302
2020-07-05 11:48:47 default[20200705t193819] 112.120.226.172, 169.254.1.1 - - [05/Jul/2020 11:48:47] "GET /write?code=jezOSqKvFNAAAAAAAAAAT42cxSNkV3SGaY2HhBnt-28 HTTP/1.1" 302 - 0.0007
2020-07-05 11:48:47 default[20200705t193819] 127.0.0.1 - - [05/Jul/2020:11:48:47 UTC] "GET /write?code=jezOSqKvFNAAAAAAAAAAT42cxSNkV3SGaY2HhBnt-28 HTTP/1.1" 302 0
2020-07-05 11:48:47 default[20200705t193819] https://xxxxxxxxxxxxxx.appspot.com/ -> /write?code=jezOSqKvFNAAAAAAAAAAT42cxSNkV3SGaY2HhBnt-28
2020-07-05 11:48:48 default[20200705t193819] "GET /auth HTTP/1.1" 500
2020-07-05 11:48:49 default[20200705t193819] OAuth2::Error - invalid_request: "code": must not be empty
2020-07-05 11:48:49 default[20200705t193819] {"error_description": "\"code\": must not be empty", "error": "invalid_request"}:
2020-07-05 11:48:49 default[20200705t193819] /layers/google.ruby.bundle/gems/.bundle/gems/ruby/2.5.0/gems/oauth2-1.3.1/lib/oauth2/client.rb:119:in `request'
2020-07-05 11:48:49 default[20200705t193819] /layers/google.ruby.bundle/gems/.bundle/gems/ruby/2.5.0/gems/oauth2-1.3.1/lib/oauth2/client.rb:146:in `get_token'
2020-07-05 11:48:49 default[20200705t193819] /layers/google.ruby.bundle/gems/.bundle/gems/ruby/2.5.0/gems/oauth2-1.3.1/lib/oauth2/strategy/auth_code.rb:30:in `get_token'
2020-07-05 11:48:49 default[20200705t193819] app.rb:44:in `block in <main>'

1 Reply

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    6 years ago

    The '"code": must not be empty' comes from the Dropbox API /oauth2/token endpoint, and indicates that the client did not supply the required "code" parameter. 

     

    You'll need to debug your app to see why you're not sending up the expected code value, which seems like it's supposed to be in the 'params['code']' in your case. I can't offer help with Ruby or your web framework itself though.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 9 months ago
411 Following

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!