项目作者: jairojair

项目描述 :
Basic auth in Lua
高级语言: Lua
项目地址: git://github.com/jairojair/basic-auth.git
创建时间: 2015-04-21T04:04:40Z
项目社区:https://github.com/jairojair/basic-auth

开源协议:MIT License

下载


Basic Auth

Build Status

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

Installation

  1. luarocks install basic-auth

How to works ?

See a example below using Pegasus.lua

  1. local auth = require 'basic-auth'
  2. local pegasus = require 'pegasus'
  3. local server = pegasus:new('9090')
  4. server:start(function (req, rep)
  5. local user = auth(req)
  6. if user then
  7. --[[
  8. Use credentials from database, file, memory, whatever.
  9. This example was used vars :)
  10. --]]
  11. local fakeUserName = 'admin'
  12. local fakePassWord = 'admin'
  13. if user.name == fakeUserName and user.pass == fakePassWord then
  14. rep:statusCode(200):write('Welcome')
  15. else
  16. rep:statusCode(403):write('Invalid credentials')
  17. end
  18. else
  19. rep:addHeader('WWW-Authenticate', 'Basic realm="Restricted"')
  20. rep:statusCode(401, 'Unauthorized'):write('Authentication required!')
  21. end
  22. end)

Contributing

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

Issues

See the issues here

Tests

  1. busted

About

Inspired by jshttp and wsapi_basic_auth

License

MIT