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

@autotelic/oauth-gateway-worker

v0.1.1

Published

A template for kick starting a Cloudflare Workers project

Downloads

6

Readme

API Oauth

A cloudflare worker to provide authentication for an API (currently setup for Github oauth).

TODO: make oauth and route configurable so this is a generic worker template for the generate command.

Setup

npm i @autotelic/oauth-gateway-worker

### Cloudflare environments and deployment

wrangler.toml.example is setup to show that there is a "dev" version of the worker deployed to the worker subdomain, and a "production" version.

Both environments require these secrets:

  • GITHUB_APP_CLIENT_ID - the client id of a github app
  • GITHUB_APP_CLIENT_SECRET - the client secret of the same github app
  • B64URL_TOKEN_ENCRYPTION_KEY - an AES-GCM-256 key base64url encoded for symmetrically encrypting/decrypting the token we return
  • kv-namespaces[].id - ID of the production AUTH_STORE namespace
  • kv-namespaces[].preview_id - ID of the dev AUTH_STORE namespace

In addition OAUTH_REDIRECT_URI is defined in wrangler.toml

Until we have a GH action, deployment is using the wrangler cli:

$ wrangler publish

or

$ wrangler publish --env production

See the wrangler docs for more.

Running locally in development

$ wrangler dev

will setup a local server to run the worker from your codebase, by default on http://localhost:8787

If you would like to forward the requests to a locally running instance of the API, first run an ngrok tunnel pointing to your local instance of the API:

$ ngrok http 3000

(this assumes your API instance is running locally on port 3000)

Then grab the https ngrok url you are given, and update the UPSTREAM_HOST in the wrangler.toml vars.

Restart wrangler dev to pick up the change. Your local worker should now proxy via the ngrok tunnel to the local API.

(It seems that cloudflare throws an error when you proxy to localhost, unfortunately)

On Heroku

If you are running the downstream API on Heroku, you will need to:

  • configure cloudflare and Heroku as documented here https://support.cloudflare.com/hc/en-us/articles/205893698-Configure-CloudFlare-and-Heroku-over-HTTPS
  • enable Dyno Metadata and ensure the API redirects to the cloudflare hosted domain

Usage

  • go to /login to be redirected to the authorization page
  • this will redirect to /callback and display a generated and encrypted token
  • use the token in an Authorization: Bearer <token> header for http requests to any other path of the API