This repository was archived by the owner on Dec 25, 2019. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork1
HTTP authorization middleware of koa.
License
NotificationsYou must be signed in to change notification settings
Gerhut/koa-http-auth
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
SimpleHTTP Authentication middlewareof koa
$ npm install koa-http-authconstkoa=require('koa')constBasicAuth=require('koa-http-auth').Basicconstapp=koa()app.use(BasicAuth('Simple Application'))app.use(function*(next){if(this.request.auth==null){// No authorization providedthis.body='Please log in.'return// Middleware will auto give 401 response}if(this.request.auth.user!=='user'||this.request.auth.password('password')){this.body='Invalid user.'deletethis.request.auth// Delete request.auth ...return// ... will make middleware give 401 response too.}if(this.url==='/logout'){this.body='You are successfully logged out.'deletethis.request.auth// Delete request.auth unconditionally ...return// ... will make user logged out.}this.body='Welcome back!'yieldnext})
constkoa=require('koa')constDigestAuth=require('koa-http-auth').Digestconstapp=koa()app.use(DigestAuth('Simple Application'))app.use(function*(next){if(this.request.auth==null){// No authorization providedthis.body='Please log in.'return// Middleware will auto give 401 response}if(this.request.auth.user!=='user'||this.request.auth.password('password')){this.body='Invalid user.'deletethis.request.auth// Delete request.auth ...return// ... will make middleware give 401 response too.}if(this.url==='/logout'){this.body='You are successfully logged out.'deletethis.request.auth// Delete request.auth unconditionally ...return// ... will make user logged out.}this.body='Welcome back!'yieldnext})
About
HTTP authorization middleware of koa.
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.