我有一个客户端和提供商根据这些回购的代码设置了doorkeeper和omniauth-oauth2:
我对代码进行了更新和定制,但基本概念是相同的。 The provider是使用门卫的Rails应用程序,the client是另一个使用so_auth作为gem配置oauth交互的Rails应用程序。它在开发中工作正常,但我在生产中的子目录中有提供程序。这是简化的请求日志:
05.930552 Started GET "/private"
05.947759 Redirected to https://example.com/auth/stm?origin=https://example.com/private
05.965877 Started GET "/auth/stm?origin=https://example.com/private"
05.993805 Started GET "/provider/oauth/authorize?client_id=449ecb&redirect_uri=https%3A%2F%2Fexample.com%2Fauth%2Fstm%2Fcallback&response_type=code"
06.021069 Redirected to https://example.com/auth/stm/callback?code=7fdbc57c
06.043829 Started GET "/auth/stm/callback?code=7fdbc57c51"
08.997899 Started POST "/oauth/token"
ActionController::RoutingError (No route matches [POST] "/oauth/token")
问题似乎是它在客户端应用而不是提供商应用上寻找/oauth/token
,因为网址应该在provider/oauth/token
。在该POST请求之前,GET /auth/stm/callback
请求应该转到UserSessionsController#create
操作,但无论我放在哪个调试代码中,它都不会被调用。它直接针对以下POST /oauth/token
请求。这是路线:
get '/auth/:provider/callback', :to => 'so_auth/user_sessions#create'
行动:
def create
omniauth = env['omniauth.auth']
user = User.find_by_id(omniauth['uid'])
if not user
# New user registration
user = User.new
user.id = omniauth['uid']
end
user.email = omniauth['info']['email'] if user.respond_to?(:email)
user.save
session[:user_id] = user.id
flash[:notice] = "Successfully logged in"
redirect_to request.env['omniauth.origin'] || root_path
end
我无法弄清楚如何在客户端日志的后半部分中处理GET
和POST
请求。如果我在应用程序控制器中设置一个记录器来记录控制器action_name
,它将运行所有其他控制器操作,但{I}}试图找出的create
操作除外。如果不运行GET "/auth/stm/callback"
操作,为什么会从POST "/oauth/token"
跳到UserSessionsController#create
?核心问题仍然存在,为什么会转到/oauth/token
而不是/provider/oauth/token
?