You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法运行Ruby omniauth-ebay-oauth gem示例代码求助

修复方案

核心说明

你无需自行声明/auth/ebay路由,该路由由OmniAuth中间件自动生成处理,出现找不到路由的报错是因为代码配置有误,导致OmniAuth中间件未正常加载eBay授权策略。

1. 补全依赖配置

确保你的Gemfile包含所有所需依赖:

source 'https://rubygems.org'
gem 'sinatra'
gem 'omniauth'
gem 'omniauth-ebay-oauth'

执行bundle install完成依赖安装。

2. 修正主程序代码

原有代码存在两处核心错误:未引入Sinatra依赖、provider配置未在OmniAuth::Builder代码块内生效。修正后的完整代码如下:

require 'sinatra'
require 'omniauth-ebay-oauth'

# 开启Sinatra内置session,适配OmniAuth
enable :sessions
set :session_secret, ENV['SESSION_SECRET'] || 'dev-secret-keep-safe-in-production'

use OmniAuth::Builder do
  # provider配置必须缩进在当前块内
  provider :ebay_oauth, ENV['EBAY_CLIENT_ID'], ENV['EBAY_CLIENT_SECRET'],
    callback_url: ENV['EBAY_RU_NAME'],
    name: 'ebay'
end

get '/' do
  redirect '/auth/ebay'
end

get '/auth/ebay/callback' do
  auth_info = request.env['omniauth.auth']
  "Hello, #{auth_info.dig('info', 'name')}"
end

# 可选:添加授权失败处理路由,方便排查问题
get '/auth/failure' do
  "授权错误:#{params[:message]}"
end

3. 配置校验

  • 确认EBAY_RU_NAME为eBay开发者后台对应应用的Redirect URL (RuName)值,不是完整的回调地址
  • 确认eBay开发者后台填写的回调地址和你实际应用的/auth/ebay/callback地址完全一致
  • 启动应用后访问根路径http://localhost:4567即可自动跳转至eBay授权页面

内容的提问来源于stack exchange,提问作者wulfshade

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 21:30:05