0
儘管在我的/config/initializers/omniauth.rb文件中添加了「hd:」標記,但不在域中的用戶仍然可以登錄。Omniauth 2.0 + Google「hd:」標記不起作用
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, Rails.application.secrets.secret_key_base, Rails.application.secrets.secret_token,
skip_jwt: true,
scope: 'profile, email',
image_aspect_ratio: 'square',
image_size: 48,
access_type: 'online',
hd: 'domain.com',
name: 'google'
end
使用具有域@ gmail.com的帳戶登錄時,用戶仍能夠登錄。
櫃面這是利用:
user.rb
class User < ActiveRecord::Base
class << self
def from_omniauth(auth_hash)
user = find_or_create_by(uid: auth_hash['uid'], provider: auth_hash['provider'])
user.name = auth_hash['info']['name']
user.location = auth_hash['info']['location']
user.image_url = auth_hash['info']['image']
user.url = auth_hash['info']['urls']['user.provide.capitalize']
user.email = auth_hash['info']['email']
user.save!
user
end
end
end
建議來解決這個問題,或者替代解決方案?