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

ubsub-oidc-proxy

v0.1.8

Published

Proxy to frontend OIDC client for ubsub and others

Downloads

10

Readme

Ubsub OIDC Proxy

Build Status npm npm Snyk Vulnerabilities for npm package

The Ubsub OIDC proxy is a simple utility that can be used as a http server (for static files), a reverse-proxy (http endpoint), or as a middleware. Given the correct configuration it will manage the OIDC authentication for ubsub, and store the result in a way the frontend can access and validate against it.

Installing

npm install ubsub-oidc-proxy

Usage

See configuration below for full details. As an easy-start, I recommend creating .oidcproxyrc file at the base of your project, and setting it as so:

[oidc]
client_id=xxx
client_secret=xxx
redirect_base=http://example.com/auth
scope=user topic.*

Standalone

As an easy way to test, you can run it standalone and it will serve a dummy-page. This will make sure OIDC is set up correctly.

npm install -g ubsub-oidc-proxy
ubsub-oidc-proxy --oidc.client_id=xxx --oidc.client_secret=xxx

or, if you're an npx fan...

npx ubsub-oidc-proxy --oidc.client_id=xxx --oidc.client_secret=xxx

As a file server

If, for instance, you want to serve a folder of static files (eg dist/), you could install globally, or as module, and run:

ubsub-odic-proxy --backend.static dist/

By default, this will mount the auth router on /auth. If that conflicts with your application, you can change that with --backend.path

As a proxy

Alternatively, if your backend is being served on a port, you can access it via the built in proxy.

ubsub-oidc-proxy --backend.proxy.target http://localhost:8080

As a middleware

If you chose to use it as a middleware to your express app, you can use it by passing the set of oidc parameters you can find in config.js.

#!/usr/bin/env node
const express = require('express');
const oidcRouter = require('ubsub-oidc-proxy');

const app = express();

// Authentication endpoint
app.use('/auth', oidcRouter(oidc));

app.listen(8080, () => {
  console.log('Listening on http://0.0.0.0:8080');
});

Configuration

Configuration with ubsub uses rc, so config can be provided via environment, .oidcproxyrc (ini or json), or minimist-like arguments.

See config.js for a full set of options.

At minimum, you need to set the following:

  • client_id Client ID obtained from ubsub.io
  • client_secret Client secret obtained from ubsub.io
  • redirect_base Where OIDC flow should redirect back to upon finishing
  • scope (Optional) You probably want to request more scopes than just user

Using in client

By default, once you have been authenticated the proxy will store the JSON blob in the cookie oidcState (config.oidc.storeName).

This object looks like:

{
  "access_token": "long-access-token",
  "id_token": "encoded.jwt.string",
  "expires_in": "2069-08-15T01:09:36.105Z",
  "token_type": "Bearer",
  "jwt": {
    "iat": 1565831376,
    "aud": "test",
    "iss": "app.ubsub.io",
    "sub": "token-id"
  }
}

In javascript, you can make calls either back through the api proxy (if configured), or directly to the router if your application is allowed to make CORS requests.

API Proxy

By default, the oidc-proxy will expose the /api endpoint, which will automatically parse the state cookie, and forward requests to the router scoped to your current user and token.

You can use this endpoint on the frontend to avoid the need to worry about CORS, but be wary of the size of payload that may need to traverse your proxy and consider calling the router directly instead.

Advanced usage

Mounting path for high-performance static sites

There may be a case where you don't want the proxy to actually serve your content, but rather act simply at the auth endpoint and let something else serve the content (eg nginx). To do this, any popular reverse-proxy will allow path-based proxying, and you simply need to proxy backend.path.

For example:

server {
  server_name example.com;
  location / {
    root /var/www;
  }
  location /auth {
    proxy_pass localhost:3050;
  }
}

License

Copyright (c) 2019 Christopher LaPointe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.