Skip to content

A single user authentication service that is simple and fun - like a picnic.

License

Notifications You must be signed in to change notification settings

simonneutert/picnic-auth

Repository files navigation

Picnic Auth

A single user authentication service that is simple and fun - like a picnic.

Picnic Auth Logo - a lock with a smiley face locking a picnic basket

Auth made easy. Inspired by Moron CMS.

The Stupidly Simple Authentication Server

This project is a Deno 🦕 server that handles authentication using bearer tokens. It includes routes for user authentication, JWT (Bearer) validation functionality.

Do not take this project too seriously. It is a simple project to demonstrate how to use JWTs for authentication in Deno.


Read the Official Documentation.


Table of Contents

Installation

  1. Clone the repository.

    git clone https://github.com/yourusername/your-repo-name.git
    cd your-repo-name
  2. Install Deno if you haven't already.

  3. Run the server.

    deno run --allow-net --allow-read --allow-env server.ts

Usage

The server exposes three main routes for authentication:

  • /auth - Handles user authentication.
  • /auth/bearer - Validates bearer tokens.

Routes

POST /auth

Authenticates the user and returns a bearer token.

  • Request Body: JSON object containing username and password.
  • Response: JSON object containing the bearer token.

POST /auth/bearer

Validates the provided bearer token.

  • Headers: Authentication header with the bearer token.
  • Response: JSON object containing user information if the token is valid.

Environment Variables

The server uses environment variables for configuration. You can set these variables in a .env file or directly in your environment.

  • PICNIC_USERNAME - The username for authentication.
    (Default: "picnic")
  • PICNIC_PASSWORD_BCRYPT - The hashed password for authentication.
    (Default: "mypicnic")
  • PICNIC_JWT_SECRET - The secret key for signing JWT tokens.
  • PICNIC_JWT_EXPIRATION_TIME - The duration for which the bearer token is valid.
    (Default: "60m")
  • PICNIC_PORT - The port on which the server will run. (Default: 8000)

JWT Expiration Time Settings

The PICNIC_JWT_EXPIRATION_TIME environment variable should be a string that is an Integer followed by a time unit.

Expand for more details

The time unit can be one of the following:

  • "sec"
  • "secs"
  • "second"
  • "seconds"
  • "s"
  • "minute"
  • "minutes"
  • "min"
  • "mins"
  • "m"
  • "hour"
  • "hours"
  • "hr"
  • "hrs"
  • "h"
  • "day"
  • "days"
  • "d"
  • "week"
  • "weeks"
  • "w"
  • "year"
  • "years"
  • "yr"
  • "yrs"
  • "y"

Examples of valid expiration times:

  • 1m - 1 minute
  • 1h - 1 hour
  • 1d - 1 day
  • 1w - 1 week
  • 2w - 1 weeks
  • 2weeks - 2 weeks

Ideas / Todos / Not sure yet

  • add a refresh token flow?

Deno Dependencies

Minimal dependencies are used in this project.

Main Dependencies

Documentation Generation

License

This project is licensed under the MIT License. See the LICENSE file for details.