Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jchannon/koa-statelessauth
https://github.com/jchannon/koa-statelessauth
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jchannon/koa-statelessauth
- Owner: jchannon
- License: mit
- Created: 2014-08-15T23:23:53.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-21T15:45:59.000Z (about 9 years ago)
- Last Synced: 2024-09-28T21:41:06.660Z (4 months ago)
- Language: JavaScript
- Size: 229 KB
- Stars: 13
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-koa - koa-statelessauth - 基于 `Authorization` header的自定义验证。 ![](https://img.shields.io/github/stars/jchannon/koa-statelessauth.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-statelessauth.svg?style=flat-square) (仓库 / 中间件)
README
#Koa StatelessAuth
This is a stateless auth library for `koa`. If there is no `Authorization` header or if is empty it will return `401` status code. The library accepts a validator object with a `validate` function. Pass in your own object to determine how it validates. If the validator does not return a `user` object a 401 is returned; You can also pass in an optional `options` object that can define paths to ignore and therefore `yield` to the next function without validating the request.
##Usage
```
var statelessauth = require('statelessauth');var validator = {
validate: function (token) {
//This should go to a DB etc to get your user based on token
if (token === '123') {
return;
}
return {
"name": "bob",
"role": "admin",
"email": "[email protected]"
};
}
};var statelessauthOptions = {
ignorePaths: ["/", "/nonsecure"]
};app.use(statelessauth(validator, statelessauthOptions));
app.use(function * (next) {
if (this.user) {
console.log(this.user.name);
console.log(this.user.email);
console.log(this.user.role);
}
yield next;
});
```##statelessauthOptions
* __ignorePaths:__ ( default: *[]* ) Array of Paths, that are ignored by the Authentification.
* __verbose:__ ( default: *false* ) Show verbose consolelogs if true.##TODO
Allow passthrough for cookie type authentication