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

@authx/authx

v3.1.0-alpha.56

Published

This is AuthX. It's named AuthX because it's an "exchange" of sorts, consolidating identities from several upstream authorities into a single identity for downstream clients. AuthX uses the OAuth2 framework in both directions, and adds a robust access con

Downloads

1,360

Readme

AuthX

This is AuthX. It's named AuthX because it's an "exchange" of sorts, consolidating identities from several upstream authorities into a single identity for downstream clients. AuthX uses the OAuth2 framework in both directions, and adds a robust access control system, based on the AuthX scope spec.


Concepts | Development | Scopes


Concepts

AuthX is designed for a scenario in which a RESOURCE needs to restrict access to all or part of its functionality. A CLIENT app, acting on behalf of a User can retreive an OAuth token from AuthX, which can be passed to the RESOURCE with any request.

╔══════════════════════════════════════════╗
║                  ┌───────────┐           ║
║                  │ AUTHORITY │           ║
║                  └─────┬─────┘           ║
║▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓│▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓║
║   ┌────────────┐ ┌─────┴─────┐           ║
║   │ Credential ├─┤ Authority │           ║
║   └───┬────────┘ └───────────┘           ║
║   ┌───┴──┐              Authentication   ║
║░░░│ User │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░║
║   └─┬──┬─┘              ┌──────┐         ║
║     │  └────────────────┤ Role │         ║
║    ┌┴──────┐ ┌────────┐ └──────┘         ║
║    │ Grant ├─┤ Client │                  ║
║    └───────┘ └───┬────┘  Authorization   ║
║▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓│▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓║
║              ┌───┴────┐ ┌──────────┐     ║
║              │ CLIENT ├─┤ RESOURCE │     ║
║              └────────┘ └──────────┘     ║
╚══════════════════════════════════════════╝

User

A user is the central component, and represents a source of agency, either human or machine.

Resource

A resource is anything which requires an AuthX token to perform an action.

Client

A client uses AuthX to act on behalf of a user.

Grant

A grant contains the set of scopes for which a client's can act on a user's behalf.

Authorization

An authorization contains the set of scopes that will be encoded in a token and passed to a resource by a client.

Role

A role bestows its scopes to every user it includes.

Authority

An authority is a mechanism for authentication, and provides the configuration for corresponding units of code called strategies. Several strategies are included by default:

  1. email - use an email address to verify a visitor's identity (most people call this "reset your password")
  2. password - verify your identity with a password (which is protected with bcrypt)
  3. openid - connect to an OpenID provider, such as Google

Credential

Credentials connect users to authorities. A user can have multiple credentials of the some authorities (multiple emails, for example), or be limited to one (such as a password).

Development

Scripts

These scripts can be run using npm run <script>; when relevant, the following environment variables can be set to modify their behavior:

  • PORT: HTTP port to listen
  • PGHOST: postgres host
  • PGPORT: postgres port
  • PGUSER: postgres user
  • PGPASSWORD: postgres password

format

Use prettier to format the code in this package.

lint

Check the contents of this package against prettier and eslint rules.

prepare

Build the files from /src to the /dist directory with optimizations.

prepare:development

Build the files from /src to the /dist directory, and re-build as changes are made to source files.

start

Start a web server that runs AuthX.

start:development

Start a web server that runs AuthX and reloads as its source files change. Use the PORT environment variable to specify a port.

test

Run all tests from the /dist directory.

test:development

Run all tests from the /dist directory, and re-run a test when it changes.

Files

/src

This holds the source code for AuthX.

/dist

The compiled and bundled code ends up here for distribution. This is ignored by git.

Scopes

AuthX uses its own authorization system to restrict access to its resources. A scope is divided into three parts:

  1. realm: this is configurable to the individual instance (for example, authx or identity or authx.dev)
  2. context: this contains the criteria required for an action to be valid
  3. action: the action being performed

Context

For an AuthX resource, the context is always in the following format:

v2.(type).(authority_id).(authorization_id).(client_id).(credential_id).(role_id).(user_id)

When checking for the ability to perform an action on an entity, the entity's ID and the IDs of related entities are present on the compared scope. When creating a new entity, only the IDs of related entities will be present, and the position of the entity' ID will be empty, even if an ID is specified for the entity in its creation request.

Given an entity type, relevant IDs will be present in the context:

| type | authority_id | authorization_id | client_id | credential_id | grant_id | role_id | user_id | | --------------- | :------------: | :----------------: | :---------: | :-------------: | :--------: | :-------: | :-------: | | authority | ✪ | | | | | | | | authorization | | ✪ | ● | | ○ | | ● | | client | | | ✪ | | | | | | credential | ● | | | ✪ | | | ● | | grant | | | ● | | ✪ | | ● | | role | | | | | | ✪ | | | user | | | | | | | ✪ |

  • ○ An ID may be present.
  • ● An ID will always be present for an action.
  • ✪ An ID will be present for existing entities, and will be empty for a new entity.

Action

For an AuthX resource, the action is always in the following format:

(basic).(details).(scopes).(secrets).(users)

In each position, an r designates the ability to perform reads, a w designates the ability to write, and (per normmal scope semantics) a * designates both.

To create a new entity, a value of * is required in each relevant position. For example, the following scope represents the ability to create a new client:

authx:v2.client.......:*..*.*.

| type | basic | details | scopes | secrets | users | | --------------- | :-----: | :-------: | :------: | :-------: | :-----: | | authority | ✪ | ● | | | | | authorization | ✪ | | ● | ● | | | client | ✪ | | | ● | | | credential | ✪ | ● | | | | | grant | ✪ | | ● | ● | | | role | ✪ | | ● | | ● | | user | ✪ | | ◯ | | |

  • ◯ An r will be checked for reads.
  • ● An r will be checked for reads and a w will be checked for writes.
  • ✪ All other applicable positions will check for a corresponding r or w in this position.

OAuth

Users must have the following scopes to use OAuth:

authx:v2.client...*....:r....
authx:v2.user.......{current_user_id}:r....
authx:v2.grant...{current_client_id}..{current_grant_id}..{current_user_id}:*..*.*.
authx:v2.authorization..*.{current_client_id}..{current_grant_id}..{current_user_id}:*..*.*.

The following scopes are implicit in an OAuth request:

authx:v2.user.......{current_user_id}:r....
authx:v2.grant...{current_client_id}..{current_grant_id}..{current_user_id}:r..*.*.
authx:v2.grant...{current_client_id}..{current_grant_id}..{current_user_id}:w...*.
authx:v2.authorization..*.{current_client_id}..{current_grant_id}..{current_user_id}:*..*.*.

Scope Explanations