@malijs/metadata-auth
Version:
Mali metadata authorization middleware
37 lines (26 loc) • 2.16 kB
Markdown
# @malijs/metadata-auth
Mali metadata authorization middleware
[](https://www.npmjs.com/package/@malijs/metadata-auth)
[](https://travis-ci.org/malijs/metadata-auth)
[](https://standardjs.com)
[](https://raw.githubusercontent.com/malijs/metadata-auth/master/LICENSE)
## API Reference
<a name="module_@malijs/metadata-auth"></a>
### @malijs/metadata-auth
Mali authorization metadata middleware.
If the call has metadata with "authorization" string property the specified function is called
| Param | Type | Description |
| --- | --- | --- |
| options | <code>Options</code> | |
| options.error | <code>String</code> \| <code>Object</code> \| <code>function</code> | optional Error creation options. If <code>String</code> the message for Error to throw in case authorization is not present. If <code>Object</code> the error options with <code>message</code>, <code>code</code>, and <code>metadata</code> properties. See <code>create-grpc-error</code> module. If <code>Function</code> a function with signature <code>(ctx)</code> called to create an error. Must return an <code>Error</code> instanse. Default: <code>"Not Authorized"</code> |
| fn | <code>function</code> | The middleware function to execute |
**Example**
```js
const auth = require('@malijs/metadata-auth')
app.use(auth(async (authValue, ctx, next) => {
console.log(authValue)
await next()
})
```
## License
Apache-2.0