Class: ICFS::Demo::Auth Deprecated
- Inherits:
-
Object
- Object
- ICFS::Demo::Auth
- Defined in:
- lib/icfs/demo/auth.rb
Overview
Deprecated.
This is a horrible security implementation, DO NOT USE for anything other than testing.
Test authentication - Rack middleware
Instance Method Summary collapse
-
#call(env) ⇒ Object
Handle the calls.
-
#initialize(app, api, cfg) ⇒ Auth
constructor
New instance.
Constructor Details
#initialize(app, api, cfg) ⇒ Auth
New instance
32 33 34 35 36 |
# File 'lib/icfs/demo/auth.rb', line 32 def initialize(app, api, cfg) @app = app @api = api @cfg = cfg end |
Instance Method Details
#call(env) ⇒ Object
Handle the calls
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/icfs/demo/auth.rb', line 42 def call(env) # login if env['PATH_INFO'] == '/login'.freeze user = env['QUERY_STRING'] body = 'User set' # set the cookie rsp = Rack::Response.new( body, 200, {} ) rsp.( 'icfs-user', { value: user, expires: Time.now + 24*60*60 }) return rsp.finish end # pull the username from the cookie = Rack::Request.new(env). user = ['icfs-user'] if !user return [400, {'Content-Type' => 'text/plain'}, ['Login first'.freeze]] end # set up for the call @api.user = user env['icfs'] = @api @cfg.load(user) env['icfs.config'] = @cfg return @app.call(env) rescue ICFS::Error::NotFound, ICFS::Error::Value => err return [400, {'Content-Type' => 'text/plain'}, [err.]] end |