2016-02-29 20 views
2

我正在爲AngularJS應用構建Rails API。我正在使用devise_token_authomniauth-steam寶石。當我嘗試驗證用戶使用的蒸汽有一個錯誤:沒有路由匹配[POST] OmniAuth 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 

配置/初始化/ omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do 
    provider :steam, ENV['steam_api_key'] 
end 

我用​​寶石和保存steam_api_key在application.yml文件。

耙路線任務

       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) 

我知道那是因爲命名空間的有點亂,但它不應該引起這個問題,對不對?

編輯: 我做了一些研究,並在這裏是說,/:provider/callback網址應該有GET/POST動作,但我們可以看到,我沒有回調POST操作的鏈接https://github.com/lynndylanhurley/devise_token_auth#usage-tldr

+0

請向我們展示您的routes.rb文件。 –

+0

@TamerShlash'routes.rb'文件已添加。 – mparkitny

+0

如[Github doc](https://github.com/lynndylanhurley/devise_token_auth#omniauth-authentication)所述,您是否在'config/initializers'中添加了omniauth-steam作爲提供程序?如果是這樣,請向我們展示初始化工具,並向我們展示運行'rake:routes'的輸出。 –

回答

1

最後我解決了這個問題,在routes.rb文件中加入了下面一行。

post '/omniauth/steam/callback', to: 'overrides/omniauth_callbacks#redirect_callbacks' 

我創建omniauth_callbacks_controller.rb文件夾controllers/overrides及以下線路中刪除。

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" 
相關問題