Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

oly-security

1.0.0 • Public • Published

oly security

Secure a REST API.

oly security is an extension of oly api.

import { inject, Kernel } from "oly";
import { ApiProvider, get } from "oly-api";
import { auth, JwtAuth, Auth } from "oly-security";
 
class Api {
  @inject auth: Auth;
 
  @get("/token") token() {
    return this.auth.createToken({id: "0", roles: ["ADMIN"]});
  }
 
  @auth("ADMIN")
  @get("/secret") secret() {
    return {ok: true, id: this.auth.token.id};
  }
}
 
Kernel
  .create()
  .with({provide: Auth, use: JwtAuth})
  .with(Api, ApiProvider)
  .start()
  .catch(console.error);

Installation

$ npm install oly oly-api

Dependencies

JSON Web Token jsonwebtoken
Hashing bcryptjs

Install

npm i oly-security

DownloadsWeekly Downloads

5

Version

1.0.0

License

MIT

Unpacked Size

56.9 kB

Total Files

78

Last publish

Collaborators

  • avatar