未发送刷新令牌
The refresh token isn't being sent
我正在使用 gem 'omniauth-google-oauth2'
#initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider(:google_oauth2, 'client_id', 'client_secret')
end
然后
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
@user = User.find_for_google_oauth2(request.env['omniauth.auth'], current_user)
#...
然后我明白了
request.env['omniauth.auth'][:credentials]
=> {"token"=> "some token", "expires_at"=>1421821319, "expires"=>true}
我想知道,刷新令牌在哪里?根据文档
access_type: Defaults to offline, so a refresh token is sent to be
used when the user is not present at the browser. Can be set to
online.
但是没有发送,是吗?
我猜您指的是文档中的 omniauth-google-oauth2 自述文件。它还说 "if you need a refresh token, google requires you to also to specify the option prompt: 'consent', which is not a default"。所以尝试将提示选项传递给提供者方法。
Rails.application.config.middleware.use OmniAuth::Builder do
provider(:google_oauth2, 'client_id', 'client_secret', { prompt: 'consent' })
end
我正在使用 gem 'omniauth-google-oauth2'
#initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider(:google_oauth2, 'client_id', 'client_secret')
end
然后
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
@user = User.find_for_google_oauth2(request.env['omniauth.auth'], current_user)
#...
然后我明白了
request.env['omniauth.auth'][:credentials]
=> {"token"=> "some token", "expires_at"=>1421821319, "expires"=>true}
我想知道,刷新令牌在哪里?根据文档
access_type: Defaults to offline, so a refresh token is sent to be used when the user is not present at the browser. Can be set to online.
但是没有发送,是吗?
我猜您指的是文档中的 omniauth-google-oauth2 自述文件。它还说 "if you need a refresh token, google requires you to also to specify the option prompt: 'consent', which is not a default"。所以尝试将提示选项传递给提供者方法。
Rails.application.config.middleware.use OmniAuth::Builder do
provider(:google_oauth2, 'client_id', 'client_secret', { prompt: 'consent' })
end