IF Commons GitHub

apiKey

concept

A random secret that a program presents, kept as a keyed hash and shown once, never wider in authority than its owner

Model identityMachine. Written in commons/data/models/identity-machine/mod.ts:56. Identified by credential.

Governance: attributes

allowedCidrstextmany

The networks it may be used from

Becomes the column allowed_cidrs of api_key.

Written at commons/data/models/identity-machine/mod.ts:62

lastUsedAtinstantoptional

When it was last used

Becomes the column last_used_at of api_key.

Written at commons/data/models/identity-machine/mod.ts:63

prefixtextrequired

The part that is not secret, by which the key is found, unique

Becomes the column prefix of api_key.

Written at commons/data/models/identity-machine/mod.ts:59

scopestextmany

The permissions the key may use: the owner's, narrowed to these

Becomes the column scopes of api_key.

Written at commons/data/models/identity-machine/mod.ts:61

secretHashtextrequired

The keyed hash of the secret

Becomes the column secret_hash of api_key.

Written at commons/data/models/identity-machine/mod.ts:60

Governance: relationships

credentialone

The credential it is To credential. Written at commons/data/models/identity-machine/mod.ts:56

rotatedFromoptional

The key it replaced To apiKey. Written at commons/data/models/identity-machine/mod.ts:56

Logical: the table

Projects to the table api_key with the primary key credential_id.

ColumnTypeNullRoleFrom
credential_idtextfalsereferenceapiKey.credential
last_used_attimestamptrueattributeapiKey.lastUsedAt
prefixtextfalseattributeapiKey.prefix
rotated_from_api_key_credential_idtexttruereferenceapiKey.rotatedFrom
secret_hashtextfalseattributeapiKey.secretHash

Physical: SQL

CREATE TABLE IF NOT EXISTS "api_key" (
    "credential_id" VARCHAR NOT NULL PRIMARY KEY,
    "prefix" VARCHAR NOT NULL,
    "secret_hash" VARCHAR NOT NULL,
    "last_used_at" TIMESTAMPTZ,
    "rotated_from_api_key_credential_id" VARCHAR,
    CONSTRAINT "api_key_credential_id_fk" FOREIGN KEY ("credential_id") REFERENCES "credential" ("credential_id"),
    CONSTRAINT "api_key_rotated_from_api_key_credential_id_fk" FOREIGN KEY ("rotated_from_api_key_credential_id") REFERENCES "api_key" ("credential_id"),
    CONSTRAINT "api_key_prefix_uq" UNIQUE ("prefix")
);

Physical: the typed table

Read and written from TypeScript with the types the model gives: import { apiKey } from "@intellectual-frontiers/data/sql/typed/models". Generated in commons/data/sql/typed/models/identity-machine.auto.ts: do not edit.

import { from } from "@intellectual-frontiers/data/sql/typed";
import { apiKey } from "@intellectual-frontiers/data/sql/typed/models";

const rows = await from(apiKey).select((s) => ({ credentialId: s.apiKey.credentialId, prefix: s.apiKey.prefix })).run(runner);

Titles, headings, exports, tables, columns and requirements. Esc closes.