Sha256: 895870c9feeadda0bc0d8eea82596effa2cfb3ccd7ae2214903ee29c55c8e1b2
Contents?: true
Size: 1.03 KB
Versions: 4
Compression:
Stored size: 1.03 KB
Contents
module Strategies class OauthAuthentication < ::Warden::Strategies::Base def valid? request.env['omniauth.auth'].present? end def authenticate! auth = request.env['omniauth.auth'] if authorized_domain?(auth) identity = Identity.find_identity(auth['uid'], auth['provider']) || create_identity(auth) return success! identity end fail! I18n.t('sessions.create.unauthorized_domain') end private def authorized_domain?(auth) if Rails.application.config.respond_to?(:authentication_domain) && Rails.application.config.authentication_domain.present? return auth['info']['email'].split('@').last == Rails.application.config.authentication_domain end true end def create_identity(auth) params = { uid: auth['uid'], provider: auth['provider'], name: auth['info']['name'], email: auth['info']['email'] } Identity.create! params end end end Warden::Strategies.add(:oauth_authentication, Strategies::OauthAuthentication)
Version data entries
4 entries across 4 versions & 1 rubygems