Sha256: 989aa85375ac8acafc1371616a2ba8a52a69a368d5c22d3a6f0a05e1254c31d7

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require 'sinatra'
require 'omniauth'

module Chronicle
  module ETL
    class AuthorizationServer < Sinatra::Base
      class << self
        attr_accessor :latest_authorization
      end

      configure do
        set :inline_templates, true
        set :dump_errors, false
        set :raise_errors, true
        disable :logging
        set :sessions, true
        set :quiet, true
        set :threaded, true
        set :environment, ENV['APP_ENV'] == 'test' ? :test : :production
      end

      use OmniAuth::Builder do
        Chronicle::ETL::OauthAuthorizer.all.each do |klass|
          args = [klass.client_id, klass.client_secret, klass.options].compact
          provider(
            klass.strategy,
            *args
          )
        end
      end

      OmniAuth.config.logger = Chronicle::ETL::Logger
      OmniAuth.config.silence_get_warning = true
      OmniAuth.config.allowed_request_methods = %i[get]

      get '/auth/:provider/callback' do
        authorization = request.env['omniauth.auth'].to_h.deep_transform_keys(&:to_sym)
        self.class.latest_authorization = authorization
        erb "<h1>Settings saved for #{params[:provider]}</h1><p>You can now close this tab and return to your terminal!</p>"
      end

      get '/auth/failure' do
        # TODO: handle this
        erb "<h1>Authentication Failed:</h1><h3>message:<h3> <pre>#{params}</pre>"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chronicle-etl-0.6.1 lib/chronicle/etl/authorization_server.rb
chronicle-etl-0.5.5 lib/chronicle/etl/authorization_server.rb
chronicle-etl-0.5.4 lib/chronicle/etl/authorization_server.rb