A single user authentication service that is simple and fun - like a picnic.
Auth made easy. Inspired by Moron CMS.
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.
- Installation
- Usage
- Routes
- Environment Variables
- Ideas / Todos / Not sure yet
- Deno Dependencies
- License
-
Clone the repository.
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name
-
Install Deno if you haven't already.
-
Run the server.
deno run --allow-net --allow-read --allow-env server.ts
The server exposes three main routes for authentication:
/auth
- Handles user authentication./auth/bearer
- Validates bearer tokens.
Authenticates the user and returns a bearer token.
- Request Body: JSON object containing
username
andpassword
. - Response: JSON object containing the bearer token.
Validates the provided bearer token.
- Headers:
Authentication
header with the bearer token. - Response: JSON object containing user information if the token is valid.
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)
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"
1m
- 1 minute1h
- 1 hour1d
- 1 day1w
- 1 week2w
- 1 weeks2weeks
- 2 weeks
- add a refresh token flow?
Minimal dependencies are used in this project.
This project is licensed under the MIT License. See the LICENSE file for details.