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>'