@authx/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 con
Last updated 16 hours ago by mike-marcacci .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @authx/authx 
SYNC missed versions from official npm registry.

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> or yarn <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; 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

Current Tags

  • 2.0.6                                ...           latest (16 hours ago)

39 Versions

  • 2.0.6                                ...           16 hours ago
  • 2.0.5                                ...           4 days ago
  • 2.0.4                                ...           4 days ago
  • 2.0.3                                ...           4 days ago
  • 2.0.2                                ...           8 days ago
  • 2.0.1                                ...           8 days ago
  • 2.0.0                                ...           8 days ago
  • 2.0.0-beta.30                                ...           9 days ago
  • 2.0.0-beta.29                                ...           9 days ago
  • 2.0.0-beta.28                                ...           16 days ago
  • 2.0.0-beta.27                                ...           24 days ago
  • 2.0.0-beta.26                                ...           24 days ago
  • 2.0.0-beta.25                                ...           4 months ago
  • 2.0.0-beta.24                                ...           4 months ago
  • 2.0.0-beta.23                                ...           4 months ago
  • 2.0.0-beta.22                                ...           6 months ago
  • 2.0.0-beta.21                                ...           6 months ago
  • 2.0.0-beta.20                                ...           6 months ago
  • 2.0.0-beta.19                                ...           6 months ago
  • 2.0.0-beta.18                                ...           6 months ago
  • 2.0.0-beta.17                                ...           6 months ago
  • 2.0.0-beta.16                                ...           6 months ago
  • 2.0.0-beta.15                                ...           6 months ago
  • 2.0.0-beta.14                                ...           6 months ago
  • 2.0.0-beta.13                                ...           6 months ago
  • 2.0.0-beta.12                                ...           6 months ago
  • 2.0.0-beta.11                                ...           7 months ago
  • 2.0.0-beta.10                                ...           7 months ago
  • 2.0.0-beta.9                                ...           7 months ago
  • 2.0.0-beta.7                                ...           7 months ago
  • 2.0.0-beta.6                                ...           7 months ago
  • 2.0.0-beta.5                                ...           7 months ago
  • 2.0.0-beta.4                                ...           7 months ago
  • 2.0.0-beta.3                                ...           7 months ago
  • 2.0.0-beta.2                                ...           7 months ago
  • 2.0.0-beta.1                                ...           7 months ago
  • 2.0.0-alpha.12                                ...           7 months ago
  • 2.0.0-alpha.11                                ...           7 months ago
  • 2.0.0-alpha.10                                ...           7 months ago
Maintainers (1)
Downloads
Today 17
This Week 53
This Month 139
Last Day 0
Last Week 86
Last Month 121
Dependencies (24)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |