gazelle_jwt 0.7.0 copy "gazelle_jwt: ^0.7.0" to clipboard
gazelle_jwt: ^0.7.0 copied to clipboard

Plugin for JSON Web Token (JWT) authentication in Gazelle, providing functionality to sign, verify, and handle JWT tokens during HTTP request processing.

Gazelle JWT Plugin #

The Gazelle JWT Plugin provides JSON Web Token (JWT) authentication capabilities for the Gazelle framework. This plugin allows you to easily secure your routes by integrating JWT-based authentication into your Gazelle application.

This plugin is based on dart_jsonwebtoken.

Getting started #

Installation #

To install the Gazelle JWT Plugin, add it to your pubspec.yaml file:

dependencies:
  gazelle_core: <latest-version>
  gazelle_jwt: <latest-version> 

Then, run dart pub get or flutter pub get to install the package.

Example usage #

Here's a quick example on how to use the GazelleJwtPlugin:

import 'package:gazelle_core/gazelle_core.dart';
import 'package:gazelle_jwt/gazelle_jwt.dart';

void main() async {
  // Initialize your Gazelle app.
  final app = GazelleApp(
    routes: [
      GazelleRoute(
        name: "login",
        post: (context, request, response) async {
          // Use the request to get data sent from the client.
          return GazelleResponse(
            statusCode: GazelleHttpStatusCode.success.ok_200,
            // Sign a token and send it back to the client.
            body: context.getPlugin<GazelleJwtPlugin>().sign({"test": "123"}),
          );
        },
      ),
      GazelleRoute(
        name: "hello_world",
        get: (context, request, response) async {
          return GazelleResponse(
            statusCode: GazelleHttpStatusCode.success.ok_200,
            body: "Hello, World!",
          );
        },
        // Add the authentication hook provided by the plugin to guard your routes.
        preRequestHooks: (context) => [
          context.getPlugin<GazelleJwtPlugin>().authenticationHook,
        ],
      ),
    ],
    plugins: [GazelleJwtPlugin(SecretKey("supersecret"))],
  );

  // Start your server.
  await app.start();
}
4
likes
160
points
52
downloads

Publisher

verified publisherintales.it

Weekly Downloads

Plugin for JSON Web Token (JWT) authentication in Gazelle, providing functionality to sign, verify, and handle JWT tokens during HTTP request processing.

Repository (GitHub)
Contributing

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

dart_jsonwebtoken, gazelle_core

More

Packages that depend on gazelle_jwt