找不到resource_classomniauth

问题描述

在my-app中添加twitter omniauth登录后,出现一条错误消息,提示“ RuntimeError(未找到resource_class)”。

由Api :: V1 :: Auth :: OmniauthCallbacksController#omniauth_success处理为HTML 参数:{“ provider” =>“ twitter”} 完成500内部服务器错误 RuntimeError(未找到resource_class): app / controllers / api / v1 / auth / omniauth_callbacks_controller.rb:26:in get_resource_from_auth_hash' app/controllers/api/v1/auth/omniauth_callbacks_controller.rb:15:in omniauth_success'

  def get_resource_from_auth_hash
    super 
     @resource.credentials = auth_hash["credentials"]
     clean_resource
  end

config>初始化程序> omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do  
  provider :twitter,ENV.fetch("TWITTER_KEY"),ENV.fetch("TWITTER_SECRET"),callback_url:
  "http://localhost:3000/api/v1/auth/twitter/callback"
end

控制器> Api> V1>身份验证> OmniauthCallbacksController

module Api   module V1
    module Auth
      class OmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController

        skip_before_action :skip_session

        def redirect_callbacks
          super
        end
        def omniauth_success
          super
          update_auth_header
        end
        def omniauth_failure
          super
        end

        protected

          def get_resource_from_auth_hash
            super
             @resource.credentials = auth_hash["credentials"]
             clean_resource
          end

          def render_data_or_redirect(message,data,user_data = {})
            if Rails.env.production?
              if ['inAppBrowser','newWindow'].include?(omniauth_window_type)
                render_data(message,user_data.merge(data))
              elsif auth_origin_url
                redirect_to DeviseTokenAuth::Url.generate(auth_origin_url,data.merge(blank: true))
              else
                fallback_render data[:error] || 'An error occurred'
              end
            else
              render json: @resource,status: :ok
            end
          end

          def clean_resource
            @resource.username = strip_emoji(@resource.username)
          end
          def strip_emoji(str)
            str.encode('SJIS','UTF-8',invalid: :replace,undef: :replace,replace: '').encode('UTF-8')
          end
      end
    end
  end
end

route.rb

Rails.application.routes.draw do
  namespace :api,defaults: { format: :json } do
    scope :v1 do
      mount_devise_token_auth_for 'User',at: 'auth',controllers: {
        registrations: 'api/v1/auth/registrations',omniauth_callbacks: 'api/v1/auth/omniauth_callbacks'

      }
    end
  end
end

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...