Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JacobLinCool/pea

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PEA

Pure Email Auth.

icon

Features

  • Authenticate users with email.
  • Restrict the email domain(s) / pattern(s) of the users.
  • Support multiple applications.
  • Asymmetric JWT signing.
  • Fully serverless.
  • A developer dashboard for managing applications.
  • A public showboard for each developer.

Using PEA, all of your users' email addresses are verified by nature.

You can use D1 Manager to manage the underlying D1 database.

Setup

Requirements:

  • A Cloudflare account (with a domain, so we can send emails)
  • A Cloudflare D1 database
  1. Execute the SQL in here in your D1 database to create the tables.
  2. Fork this repository.
  3. Create a new Cloudflare Pages project with the forked repository.
  4. Setup the environment variables and D1 binding (D1) in the Cloudflare Pages project.
  5. Trigger /api/sys/setup to check if the setup is successful.

Configuration

PEA uses environment variables for some configurations.

Name Description Example
PEA_APP_EMAIL The email address of the system use for sending email. [email protected]

Authentication Model

For Application Developers

After creating an application on PEA, you can use the provided login page or the API to authenticate users.

The provided login page is located at /app/<your-app> and you can use the cb query parameters to customize the callback URL, for example /app/your-app?cb=https://your.app/callback/url.

You can also use the API to authenticate users. The API is located at /api/app/<your-app>/login and you can use the callback field in the request body to customize the callback URL.

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "callback": "https://your.app/callback/url"}' \
    https://pea.csie.cool/api/app/your-app-id/login

Then, PEA will send an email to the user with the callback URL and a JWT token in the following format:

https://your.app/callback/url?token=<JWT_TOKEN>

Both methods require the callback URL matches the pattern in the application settings.

Verify the JWT Token

You can verify the JWT token using the public key provided by PEA.

Follows the JWT standard, the JWK sets can be found at jku field in the JWT token header.

{
  "jku": "https://pea.csie.cool/jwks.json"
}

Every JWT library should be able to verify the JWT token using the JWK sets.

If you are using SvelteKit, you can use the sveltekit-jwt package to verify the JWT token.

### For Users

1. Open the application you want to log in to.
2. Enter your email address and click the login button (or something similar).
3. Receive an email from PEA and click the link in the email.
4. Done! You are now logged in to the application.

About

Pure Email Auth.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published