Skip to content
Basic auth in Lua
Lua
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
rockspecs
spec
.editorconfig
.gitignore
LICENSE
README.md
basic-auth.lua

README.md

Basic Auth

Build Status

Generic basic Authorization based on header field, according RFC 2617.

Installation

luarocks install basic-auth

How to works ?

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)

Contributing

  • fork
  • add your contribution Thank's a lot !
  • send pull request

Issues

See the issues here

Tests

 busted

About

Inspired by jshttp and wsapi_basic_auth

License

MIT

You can’t perform that action at this time.