Sha256: df9e81412e3ad894e9bca712146b35746252ad6b5ab1d21eb6dea5b6d6fc4034
Contents?: true
Size: 1.89 KB
Versions: 18
Compression:
Stored size: 1.89 KB
Contents
require 'roo_on_rails/config' module RooOnRails module Railties class GoogleOAuth < Rails::Railtie initializer 'roo_on_rails.google_auth.middleware' do |app| Rails.logger.with initializer: 'roo_on_rails.google_auth' do |log| next unless Config.google_auth_enabled? log.debug 'loading' _add_middleware(app) _add_routes(app) end end private def _add_middleware(app) require 'omniauth' require 'omniauth-google-oauth2' require 'active_support/core_ext/object/blank' options = { path_prefix: Config.google_auth_path_prefix, prompt: 'consent', # https://stackoverflow.com/questions/45271730/jwtinvalidissuererror-invalid-issuer-expected-accounts-google-com-received # https://github.com/zquestz/omniauth-google-oauth2/issues/197 skip_jwt: true, } domain_list = ENV.fetch('GOOGLE_AUTH_ALLOWED_DOMAINS', '').split(',').reject(&:blank?) options[:hd] = domain_list if domain_list.any? app.config.middleware.use ::OmniAuth::Builder do provider :google_oauth2, ENV.fetch('GOOGLE_AUTH_CLIENT_ID'), ENV.fetch('GOOGLE_AUTH_CLIENT_SECRET'), options end end def _add_routes(app) prefix = Config.google_auth_path_prefix ctrl = Config.google_auth_controller app.routes.prepend do get "#{prefix}/google_oauth2", controller: ctrl, action: 'failure' get "#{prefix}/google_oauth2/callback", controller: ctrl, action: 'create' post "#{prefix}/google_oauth2/callback", controller: ctrl, action: 'create' get "#{prefix}/failure", controller: ctrl, action: 'failure' get "#{prefix}/logout", controller: ctrl, action: 'destroy' end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems