You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 25, 2019. It is now read-only.
constkoa=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})
Digest Authentication
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})