Ruby on rails Can';t使用Desive、Rails 4从Omniauth身份验证策略中检索访问令牌、刷新令牌

Ruby on rails Can';t使用Desive、Rails 4从Omniauth身份验证策略中检索访问令牌、刷新令牌,ruby-on-rails,ruby,ruby-on-rails-3,devise,omniauth,Ruby On Rails,Ruby,Ruby On Rails 3,Devise,Omniauth,我正在使用这样的宝石: gem "omniauth-yandex" gem 'devise' 我的设置 路线: devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" } config.omniauth :yandex, Rails.application.secrets.client_id , Rails.application.secrets.password, callback_url

我正在使用这样的宝石:

gem "omniauth-yandex"
gem 'devise'
我的设置

路线

 devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
config.omniauth :yandex, Rails.application.secrets.client_id , Rails.application.secrets.password, callback_url: "http://cb2bcdc4.ngrok.io/users/auth/yandex/callback"
devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:yandex]


   def self.from_omniauth(auth) 

      where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
        user.provider = auth.provider
        user.uid = auth.uid
        user.email =  auth.info.email
        user.password = Devise.friendly_token[0,20]
      end

  end
class CallbacksController < Devise::OmniauthCallbacksController        

    def yandex
       #empty
    end
end
设计初始值设定项

 devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
config.omniauth :yandex, Rails.application.secrets.client_id , Rails.application.secrets.password, callback_url: "http://cb2bcdc4.ngrok.io/users/auth/yandex/callback"
devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:yandex]


   def self.from_omniauth(auth) 

      where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
        user.provider = auth.provider
        user.uid = auth.uid
        user.email =  auth.info.email
        user.password = Devise.friendly_token[0,20]
      end

  end
class CallbacksController < Devise::OmniauthCallbacksController        

    def yandex
       #empty
    end
end
用户模型

 devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
config.omniauth :yandex, Rails.application.secrets.client_id , Rails.application.secrets.password, callback_url: "http://cb2bcdc4.ngrok.io/users/auth/yandex/callback"
devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:yandex]


   def self.from_omniauth(auth) 

      where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
        user.provider = auth.provider
        user.uid = auth.uid
        user.email =  auth.info.email
        user.password = Devise.friendly_token[0,20]
      end

  end
class CallbacksController < Devise::OmniauthCallbacksController        

    def yandex
       #empty
    end
end
回拨控制器

 devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
config.omniauth :yandex, Rails.application.secrets.client_id , Rails.application.secrets.password, callback_url: "http://cb2bcdc4.ngrok.io/users/auth/yandex/callback"
devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:yandex]


   def self.from_omniauth(auth) 

      where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
        user.provider = auth.provider
        user.uid = auth.uid
        user.email =  auth.info.email
        user.password = Devise.friendly_token[0,20]
      end

  end
class CallbacksController < Devise::OmniauthCallbacksController        

    def yandex
       #empty
    end
end
问题:我如何将访问令牌、Omniauth身份验证过程中的刷新令牌保存给用户,因为很明显(第7行),它使用我的客户端id和密码检索令牌,而不使用我的任何代码

谢谢

我尝试过的:

  <%= link_to "Sign in with Yandex", user_yandex_omniauth_authorize_path, id: "sign_in" %>
在用户模型中将
user.access\u token=auth.credentials.token
添加到
self.from\u omniauth(auth)
方法。但没有任何积极的变化

更新

 devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
config.omniauth :yandex, Rails.application.secrets.client_id , Rails.application.secrets.password, callback_url: "http://cb2bcdc4.ngrok.io/users/auth/yandex/callback"
devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:yandex]


   def self.from_omniauth(auth) 

      where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
        user.provider = auth.provider
        user.uid = auth.uid
        user.email =  auth.info.email
        user.password = Devise.friendly_token[0,20]
      end

  end
class CallbacksController < Devise::OmniauthCallbacksController        

    def yandex
       #empty
    end
end

同样的问题也存在于不同的平台上。例如,在共享主机和Linux Ubuntu中(全新的项目从无到有)。

访问令牌由yandex gem提供,或者更具体地说,由gem提供

只需执行以下操作即可进入控制器:
request.env[“omniauth.auth”].credentials.token


轰。那是你的通行证。(刷新令牌和到期数据也在
凭证
散列中,只需打印出来即可)

您是否尝试调试
CallbackController的
yandex
操作中的参数?类似于
放置参数的内容
?我很确定在
参数中返回的访问令牌不在
身份验证中。@是的,我试过了。我只得到'state'和'code'参数。请分享通过
p response.headers.fetch('Access-Token')
p response.headers.fetch('Access\u Token')
或只
p response.headers