没有路由匹配 [POST] OmniAuth Steam 回调
No route matches [POST] OmniAuth Steam Callback
我正在为 AngularJS 应用构建 Rails API。我正在使用 devise_token_auth
和 omniauth-steam
gem。当我尝试使用 Steam 验证用户时出现错误:
ActionController::RoutingError (No route matches [POST] "/omniauth/steam/callback"
我添加了 devise_token_auth
路由,但它们没有创建 POST 回调。我试过手动创建 POST 回调路由,但它没有用,我不确定它是否是正确的解决方案。我试图从昨天开始解决这个问题,但找不到有类似问题的人。
config/routes.rb
Rails.application.routes.draw do
namespace 'api' do
namespace 'v1' do
mount_devise_token_auth_for 'Api::V1::User', at: 'auth'
end
end
end
config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :steam, ENV['steam_api_key']
end
我使用 figaro
gem 并在 application.yml
文件中保存 steam_api_key。
rake 路线任务
Prefix Verb URI Pattern Controller#Action
new_api_v1_api_v1_user_session GET /api/v1/auth/sign_in(.:format) devise_token_auth/sessions#new
api_v1_api_v1_user_session POST /api/v1/auth/sign_in(.:format) devise_token_auth/sessions#create
destroy_api_v1_api_v1_user_session DELETE /api/v1/auth/sign_out(.:format) devise_token_auth/sessions#destroy
api_v1_api_v1_user_password POST /api/v1/auth/password(.:format) devise_token_auth/passwords#create
new_api_v1_api_v1_user_password GET /api/v1/auth/password/new(.:format) devise_token_auth/passwords#new
edit_api_v1_api_v1_user_password GET /api/v1/auth/password/edit(.:format) devise_token_auth/passwords#edit
PATCH /api/v1/auth/password(.:format) devise_token_auth/passwords#update
PUT /api/v1/auth/password(.:format) devise_token_auth/passwords#update
cancel_api_v1_api_v1_user_registration GET /api/v1/auth/cancel(.:format) devise_token_auth/registrations#cancel
api_v1_api_v1_user_registration POST /api/v1/auth(.:format) devise_token_auth/registrations#create
new_api_v1_api_v1_user_registration GET /api/v1/auth/sign_up(.:format) devise_token_auth/registrations#new
edit_api_v1_api_v1_user_registration GET /api/v1/auth/edit(.:format) devise_token_auth/registrations#edit
PATCH /api/v1/auth(.:format) devise_token_auth/registrations#update
PUT /api/v1/auth(.:format) devise_token_auth/registrations#update
DELETE /api/v1/auth(.:format) devise_token_auth/registrations#destroy
api_v1_api_v1_user_confirmation POST /api/v1/auth/confirmation(.:format) devise_token_auth/confirmations#create
new_api_v1_api_v1_user_confirmation GET /api/v1/auth/confirmation/new(.:format) devise_token_auth/confirmations#new
GET /api/v1/auth/confirmation(.:format) devise_token_auth/confirmations#show
api_v1_auth_validate_token GET /api/v1/auth/validate_token(.:format) devise_token_auth/token_validations#validate_token
api_v1_auth_failure GET /api/v1/auth/failure(.:format) devise_token_auth/omniauth_callbacks#omniauth_failure
GET /api/v1/auth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#omniauth_success
GET /omniauth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#redirect_callbacks
omniauth_failure GET /omniauth/failure(.:format) devise_token_auth/omniauth_callbacks#omniauth_failure
GET /api/v1/auth/:provider(.:format) redirect(301)
我知道因为命名空间有点乱,但应该不会导致这个问题吧?
编辑:
我做了一些研究,这里是 link https://github.com/lynndylanhurley/devise_token_auth#usage-tldr 它说 /:provider/callback
url 应该有 GET/POST 行动,但我们可以看到我没有POST 回调操作。
最后,我通过在 routes.rb
文件中添加以下行解决了这个问题。
post '/omniauth/steam/callback', to: 'overrides/omniauth_callbacks#redirect_callbacks'
我在 controllers/overrides
文件夹中创建了 omniauth_callbacks_controller.rb
文件并删除了下面一行。
skip_before_action :set_user_by_token, raise: false
最后一步是使用重定向路由编辑行。我改变了这个:
redirect_route = "#{request.protocol}#{request.host_with_port}/#{Devise.mappings[devise_mapping].fullpath}/#{params[:provider]}/callback"
到硬编码路线。
redirect_route = "/api/v1/auth/steam/callback"
我正在为 AngularJS 应用构建 Rails API。我正在使用 devise_token_auth
和 omniauth-steam
gem。当我尝试使用 Steam 验证用户时出现错误:
ActionController::RoutingError (No route matches [POST] "/omniauth/steam/callback"
我添加了 devise_token_auth
路由,但它们没有创建 POST 回调。我试过手动创建 POST 回调路由,但它没有用,我不确定它是否是正确的解决方案。我试图从昨天开始解决这个问题,但找不到有类似问题的人。
config/routes.rb
Rails.application.routes.draw do
namespace 'api' do
namespace 'v1' do
mount_devise_token_auth_for 'Api::V1::User', at: 'auth'
end
end
end
config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :steam, ENV['steam_api_key']
end
我使用 figaro
gem 并在 application.yml
文件中保存 steam_api_key。
rake 路线任务
Prefix Verb URI Pattern Controller#Action
new_api_v1_api_v1_user_session GET /api/v1/auth/sign_in(.:format) devise_token_auth/sessions#new
api_v1_api_v1_user_session POST /api/v1/auth/sign_in(.:format) devise_token_auth/sessions#create
destroy_api_v1_api_v1_user_session DELETE /api/v1/auth/sign_out(.:format) devise_token_auth/sessions#destroy
api_v1_api_v1_user_password POST /api/v1/auth/password(.:format) devise_token_auth/passwords#create
new_api_v1_api_v1_user_password GET /api/v1/auth/password/new(.:format) devise_token_auth/passwords#new
edit_api_v1_api_v1_user_password GET /api/v1/auth/password/edit(.:format) devise_token_auth/passwords#edit
PATCH /api/v1/auth/password(.:format) devise_token_auth/passwords#update
PUT /api/v1/auth/password(.:format) devise_token_auth/passwords#update
cancel_api_v1_api_v1_user_registration GET /api/v1/auth/cancel(.:format) devise_token_auth/registrations#cancel
api_v1_api_v1_user_registration POST /api/v1/auth(.:format) devise_token_auth/registrations#create
new_api_v1_api_v1_user_registration GET /api/v1/auth/sign_up(.:format) devise_token_auth/registrations#new
edit_api_v1_api_v1_user_registration GET /api/v1/auth/edit(.:format) devise_token_auth/registrations#edit
PATCH /api/v1/auth(.:format) devise_token_auth/registrations#update
PUT /api/v1/auth(.:format) devise_token_auth/registrations#update
DELETE /api/v1/auth(.:format) devise_token_auth/registrations#destroy
api_v1_api_v1_user_confirmation POST /api/v1/auth/confirmation(.:format) devise_token_auth/confirmations#create
new_api_v1_api_v1_user_confirmation GET /api/v1/auth/confirmation/new(.:format) devise_token_auth/confirmations#new
GET /api/v1/auth/confirmation(.:format) devise_token_auth/confirmations#show
api_v1_auth_validate_token GET /api/v1/auth/validate_token(.:format) devise_token_auth/token_validations#validate_token
api_v1_auth_failure GET /api/v1/auth/failure(.:format) devise_token_auth/omniauth_callbacks#omniauth_failure
GET /api/v1/auth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#omniauth_success
GET /omniauth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#redirect_callbacks
omniauth_failure GET /omniauth/failure(.:format) devise_token_auth/omniauth_callbacks#omniauth_failure
GET /api/v1/auth/:provider(.:format) redirect(301)
我知道因为命名空间有点乱,但应该不会导致这个问题吧?
编辑:
我做了一些研究,这里是 link https://github.com/lynndylanhurley/devise_token_auth#usage-tldr 它说 /:provider/callback
url 应该有 GET/POST 行动,但我们可以看到我没有POST 回调操作。
最后,我通过在 routes.rb
文件中添加以下行解决了这个问题。
post '/omniauth/steam/callback', to: 'overrides/omniauth_callbacks#redirect_callbacks'
我在 controllers/overrides
文件夹中创建了 omniauth_callbacks_controller.rb
文件并删除了下面一行。
skip_before_action :set_user_by_token, raise: false
最后一步是使用重定向路由编辑行。我改变了这个:
redirect_route = "#{request.protocol}#{request.host_with_port}/#{Devise.mappings[devise_mapping].fullpath}/#{params[:provider]}/callback"
到硬编码路线。
redirect_route = "/api/v1/auth/steam/callback"