簡體   English   中英

使用devise_token_auth的Rails Api給出了“ ActiveModel :: ForbiddenAttributesError:

[英]Rails Api with devise_token_auth gives "ActiveModel::ForbiddenAttributesError:

我想用Facebook登錄來構建RailsAPI,所以我選擇了devise_token_auth 我按照說明運行rails g devise_token_auth:install User auth ,我的路由看起來像

routes.rb

Rails.application.routes.draw do
  mount_devise_token_auth_for 'User', at: 'auth'
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

所以這是來自發電機的東西。 我在Facebook上為開發人員注冊了我的應用程序,並將facebook-key和facebook-secret存儲在env文件中。 當我第一次訪問localhost:3000/auth/facebook它將我重定向到facebook auth彈出窗口,我單擊了按鈕,然后出現錯誤。

在此處輸入圖片說明

我應該用自己的設計覆蓋控制器嗎? 怎么做? 還是有其他解決方案?

我想提一下,這是我第一次使用Rails構建API。

重寫assign_provider_attrs時,我已經解決了問題

route.rb mount_devise_token_auth_for 'User', at: 'auth' , controllers: { omniauth_callbacks: 'authentication_rails/omniauth_callbacks' }

控制器/問題/ authentication_rails / omniauth_callbacks_controller

module AuthenticationRails class OmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController protected # break out provider attribute assignment for easy method extension def assign_provider_attrs(user, auth_hash) if auth_hash['provider'] == 'facebook' user.assign_attributes({ nickname: auth_hash['info']['nickname'], name: auth_hash['info']['name'], image: auth_hash['info']['image'], email: auth_hash['info']['email'] }) else super end end end end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM