1.1.3 • Published 2 months ago

@sigiljs-community/auth-plugin v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Sigil Auth Plugin

Plugin for SigilJS framework that provides authentication with JWT-like tokens

Installation

npm install @sigiljs-community/auth-plugin
# or
yarn add @sigiljs-community/auth-plugin

Usage

Import and register the plugin

import { Sigil } from "@sigiljs/sigil"
import { AuthPlugin } from "@sigiljs-community/auth-plugin"

const app = new Sigil()

// Register plugin with settings
app.addPlugin(AuthPlugin, {
  /**
   * Secret key for tokens generation
   *
   * While optional, it is strongly recommended to set up
   * your own secret token for production environments
   *
   * @default Random 32 bytes long key
   */
  secretKey: "",

  /**
   * List of protected routes
   *
   * If not set up, you will need to manually add modifier to each protected route
   */
  protectedRoutes: [],

  /**
   * Define custom names for refresh and access token headers
   *
   * @default X-Sigil-Refresh-Token, Authorization
   */
  authHeaders: {
    refreshToken: "X-Refresh-Token",
    accessToken: "Authorization"
  }
})

See available plugin methods for more information

Protecting specified route

If protected routes not set up, you will need to provide AuthModifier for each protected route manually

AuthModifier also injects following fields in the request: accessToken, accessTokenValid, refreshToken, so it is still useful even if protected routes are set up

import { AuthModifier } from "@sigiljs-community/auth-plugin"

const route = app.createRoute("/", {
  modifiers: [AuthModifier]
})

route.get("/", request => {
  return request.accessToken // <- string or null
})

License

You can copy and paste the MIT license summary from below.

MIT License

Copyright (c) 2022 Kurai Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1.1.3

2 months ago

1.1.2

2 months ago

1.1.1

2 months ago

1.1.0

2 months ago

1.0.0

2 months ago