Skip to content

Repository files navigation

SincereAuthMiddleware

Vapor package to consume the tokens created by an SincereAuth server instance.

Installation

In the dependencies section of your Package.swift, add

.package(url: "https://github.com/DanielSincere/SincereAuth", from: "0.3.0"),

And in your server's target's dependencies section, add

.product(name: "SincereAuthMiddleware", package: "SincereAuthMiddleware")

Environment setup

Provide your auth private key as a Base64-encoded string in the environment variable AUTH_PRIVATE_KEY. This needs to be the same key used by your main instance of SincereAuth.

Usage

In your routes declaration, import SincereAuthMiddleware

routes
  .group(SincereAuthMiddleware()) { protected in
    protected.get("protected") { req in
      return "Logged in"
    }
  }

To require a certain role for a route, add it to the initializer of the middleware:

routes
  .group(SincereAuthMiddleware(requiredRole: "admin")) { admin in
    admin.get("admin") { req in
      return "Logged in as an admin"
    }
  }

Example

For an example, see https://github.com/DanielSincere/SincereAuth-Sample-Microservice

Sponsor me

If you learned something or found this useful, you can show your appreciation by sponsoring me here on GitHub https://github.com/sponsors/DanielSincere

About

Vapor middleware for SincereAuth

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages