Sha256: d720cefec4099c6d57c389c419b2a116cf90cf13d8ef26e221445553aad946ed
Contents?: true
Size: 1.59 KB
Versions: 10
Compression:
Stored size: 1.59 KB
Contents
module Conjur module WebServer class Login attr_reader :sessionid def initialize(sessionid) @sessionid = sessionid end def call(env) if sessionid = token_valid?(env) require 'conjur/authn' require 'base64' token = Conjur::Authn.authenticate api = Conjur::API.new_from_token token userid = [ Conjur.configuration.account, "user", api.username ].join(':') env["rack.session"][:sessionid] = sessionid response = Rack::Response.new(env) configuration = { account: Conjur.configuration.account, stack: Conjur.configuration.stack, appliance_url: Conjur.configuration.appliance_url, login: Conjur::Authn.get_credentials[0] } response.status = 302 response.set_cookie('conjur_configuration', value: JSON.pretty_generate(configuration), path: '/') response.set_cookie('conjur_userid', value: userid, path: '/') response['Location'] = "/ui" response.finish else [ 403, {}, ["Authorization is missing or invalid"] ] end end protected def token_valid?(env) token = extract_token(env) if token == sessionid sessionid else nil end end def extract_token(env) require 'cgi' require 'uri' query = URI.parse(env['REQUEST_URI']).query query && ( sessionid = CGI.parse(query)['sessionid'] ) && sessionid[0] end end end end
Version data entries
10 entries across 10 versions & 3 rubygems