# frozen_string_literal: true require 'cgi' module ShibRack # Handler for authenticating to an application in development mode, using # sample identities for local testing. class DevelopmentHandler < Handler class < v) } end end end def call(env) case env['PATH_INFO'] when '/login' login(env) when '/development' development else super end end private def login(env) params = CGI.parse(env['QUERY_STRING']) st, = params['identity'] identity = st && DevelopmentHandler.resolve_identity(st) return super(env.merge(identity)) if identity [302, { 'Location' => "#{env['SCRIPT_NAME']}/development" }, []] end def development [ 200, { 'Content-Type' => 'text/html; charset=utf-8' }, [development_html] ] end def development_html <<~EOF Development Login

Please select an identity

#{identities_html} EOF end def identities_html DevelopmentHandler.identities.map { |i| identity_html(i) }.join end def identity_html(identity) <<~EOF

#{JSON.pretty_generate(identity)}
EOF end end end