Sha256: d6f79b5befd57f8cacfdb39cf10eecc30a86ae20ac3585e359db279884647b98
Contents?: true
Size: 1.34 KB
Versions: 5
Compression:
Stored size: 1.34 KB
Contents
require 'rest-client' require 'omniauth/basic' module OmniAuth module Strategies class HttpBasic include OmniAuth::Strategy def initialize(app, name, endpoint = nil, headers = {}, &block) super @endpoint = endpoint @request_headers = headers end attr_reader :endpoint, :request_headers def request_phase if env['REQUEST_METHOD'] == 'GET' get_credentials else perform end end def title name.split('_').map{|s| s.capitalize}.join(' ') end def get_credentials OmniAuth::Form.build(title) do text_field 'Username', 'username' password_field 'Password', 'password' end.to_response end def perform @response = perform_authentication(endpoint) @env['omniauth.auth'] = auth_hash @env['REQUEST_METHOD'] = 'GET' @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback" call_app! rescue RestClient::Request::Unauthorized => e fail!(:invalid_credentials, e) end def perform_authentication(uri, headers = request_headers) RestClient.get(uri, headers) end def callback_phase fail!(:invalid_credentials) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems