npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@axel669/acheron

v0.1.4

Published

An auth system built for use with cloudflare workers and pages functions that does all of the annoying logic and validation for various authentication methods.

Downloads

29

Readme

Acheron

An auth system built for use with cloudflare workers and pages functions that does all of the annoying logic and validation for various authentication methods.

Change Log

Installation

pnpm add @axel669/acheron

Installing the Worker

In order to use the auth functions provided in the library, there needs to be a cloudflare worker deployed to the same account that will be bound to the calling code. The library ships with a copy of the worker (minus installed packages), but the worker can also be pulled from the repo and deployed.

The worker can also be run locally to test things without deploying to CF. The worker has a single env var (log_level) that can be set if more information about the worker is required. Values are: "debug", "info", "warn" "error", "none". If not set, it will default to "error". If set to "debug" the worker will log auth config and token details without masking, only use this option running locally if you are seeing errors.

Steps:

  • Install the worker dependencies
    • The library includes an npm bin script to install deps called ach-setup

    The worker has a package.json file that is ready to go for this

  • Check the wrangler configuration
    • The library includes an npm bin script to run the worker. On windows machines use ach-win-run, and for other systems use ach-run

    The worker wrangler.toml has a config that is ready to be deployed, but any of the settings can be changed if needed, just be sure to note what changes are made when binding to it

  • Deploy the worker using wrangler
    • The library includes an npm bin script to deploy the worker. On windows machines use ach-win-deploy, and for other systems use ach-deploy

Usage

The acheron worker is not made to be called directly, instead use one of the library functions for the corresponding auth type, as the auth functions have additional logic to handle being inside an application. The auth functions should be used as middleware (run before route code) to ensure that auth is handled before route code needs to use its results. To see specifics on how to use the auth functions, check out the examples folder in the repo.

In order for acheron to route properly, your app will need to have a route for the login methods to respond to (/login/<auth type>), as well as a logout route (/logout).

Env Variables

These env vars need to be configured in the worker/pages func that is calling the auth. That allows multiple applications to reuse the library worker, since it doesn't need to be configured for every application.

NOTE: All variables that deal with origins must include the protocol + domain (ex: https://company.okta.com, http://localhost:45067).

Required for All Auth

  • jwt_secret

    The secret that will be used to sign and verify the JWTs used by the library for auth

Optional for All Auth

  • app_origin

    If set, the library will use this origin for building the redirect URLs that are required for the auth processes. If not set, the library will use the origin the application is deployed on. The main use of this is for testing workers locally that have cf routes set, as wrangler will use that origin internally for local dev, even though the code is running on the localhost domain.

  • login_dest

    If set, the library will redirect to this pathname on the app origin when a user successfully logs in (logging in and directing to a dashboard for example). If not set, the library will redirect to the top level of the app origin.

Github Variables

  • github_client_id
  • github_client_secret

Twitch Variables

  • twitch_client_id
  • twitch_client_secret

Auth0 Variables

  • auth0_client_id
  • auth0_client_secret
  • auth0_origin

Okta Variables

  • okta_client_id
  • okta_client_secret
  • okta_origin

Examples

See the examples folder of the repo for usage in a few scenarios.

The pages and worker examples show basic middlware usage, the hono-worker example shows how the auth result can be used to customize where login is enforced in an app.