Generic basic Authorization based on header field, according RFC 2617.
luarocks install basic-auth
See a example below using Pegasus.lua
local auth = require 'basic-auth'
local pegasus = require 'pegasus'
local server = pegasus:new('9090')
server:start(function (req, rep)
local user = auth(req)
if user then
--[[
Use credentials from database, file, memory, whatever.
This example was used vars :)
--]]
local fakeUserName = 'admin'
local fakePassWord = 'admin'
if user.name == fakeUserName and user.pass == fakePassWord then
rep:statusCode(200):write('Welcome')
else
rep:statusCode(403):write('Invalid credentials')
end
else
rep:addHeader('WWW-Authenticate', 'Basic realm="Restricted"')
rep:statusCode(401, 'Unauthorized'):write('Authentication required!')
end
end)
- fork
- add your contribution Thank's a lot !
- send pull request
See the issues here
busted
Inspired by jshttp and wsapi_basic_auth