@owlmeans/auth 0.1.18-rc.3 → 0.1.18-rc.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/auth",
3
- "version": "0.1.18-rc.3",
3
+ "version": "0.1.18-rc.30",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@owlmeans/error": "^0.1.18-rc.3",
25
+ "@owlmeans/error": "^0.1.18-rc.30",
26
26
  "ajv-formats": "^3.0.1"
27
27
  },
28
28
  "peerDependencies": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@owlmeans/dep-config": "workspace:*",
33
- "@types/bun": "^1.3.14",
33
+ "@types/bun": "^1.4.0",
34
34
  "nodemon": "^3.1.14",
35
35
  "typescript": "^7.0.2"
36
36
  },
@@ -1,7 +1,7 @@
1
1
  import type { JSONSchemaType } from 'ajv'
2
2
  import type { AllowanceRequest, Auth, AuthCredentials, AuthPayload } from '../types.js'
3
3
  import {
4
- AuthRoleSchema, EntityValueSchema, GroupValueSchema, IdValueSchema, DateSchema,
4
+ AuthRoleSchema, EntitySlugValueSchema, GroupValueSchema, IdValueSchema, DateSchema,
5
5
  ScopeValueSchema, TypeNameSchema
6
6
  } from '../consts.js'
7
7
  import { AuthPayloadSchema } from '../auth/model.js'
@@ -16,7 +16,7 @@ export const PartialAuthPayloadSchema: JSONSchemaType<Omit<Partial<AuthPayload>,
16
16
  profileId: { ...IdValueSchema, nullable: true },
17
17
  expiresAt: { ...DateSchema, nullable: true },
18
18
  groups: { type: 'array', items: GroupValueSchema, nullable: true },
19
- entityId: { ...EntityValueSchema, nullable: true },
19
+ entitySlug: { ...EntitySlugValueSchema, nullable: true },
20
20
  scopes: { type: 'array', items: ScopeValueSchema, nullable: true },
21
21
  permissions: { type: 'array', nullable: true, items: PermissionSetSchema },
22
22
  attributes: { type: 'array', nullable: true, items: AttributeSetSchema },
@@ -58,6 +58,8 @@ export const AuthSchema: JSONSchemaType<Auth> = {
58
58
  token: { type: 'string', minLength: 32, maxLength: 1024 },
59
59
  isUser: { type: 'boolean' },
60
60
  createdAt: DateSchema,
61
+ sessionId: { type: 'string', minLength: 16, maxLength: 128, nullable: true },
62
+ authorizationVersion: { type: 'integer', minimum: 1, nullable: true },
61
63
  expiresAt: { ...DateSchema, nullable: true },
62
64
  ...AuthPayloadSchema.properties,
63
65
  },
package/src/auth/model.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { JSONSchemaType } from 'ajv'
2
2
  import type { AuthPayload, AuthToken, Authorization, ProfilePayload } from '../types.js'
3
3
  import {
4
- EntityValueSchema, EnumValueSchema, GroupValueSchema, IdValueSchema, DateSchema, ScopeValueSchema,
4
+ EntitySlugValueSchema, EnumValueSchema, GroupValueSchema, IdValueSchema, DateSchema, ScopeValueSchema,
5
5
  TypeNameSchema
6
6
  } from '../consts.js'
7
7
  import { AttributeSetSchema, PermissionSetSchema } from '../permission/model.js'
@@ -9,7 +9,7 @@ import { AttributeSetSchema, PermissionSetSchema } from '../permission/model.js'
9
9
  export const AuthorizationSchema: JSONSchemaType<Authorization> = {
10
10
  type: 'object',
11
11
  properties: {
12
- entityId: { ...EntityValueSchema, nullable: true },
12
+ entitySlug: { ...EntitySlugValueSchema, nullable: true },
13
13
  scopes: { type: 'array', items: ScopeValueSchema },
14
14
  permissions: { type: 'array', nullable: true, items: PermissionSetSchema },
15
15
  attributes: { type: 'array', nullable: true, items: AttributeSetSchema },
package/src/consts.ts CHANGED
@@ -98,7 +98,10 @@ export const ResourceValueSchema: JSONSchemaType<string> = { type: 'string', min
98
98
 
99
99
  export const AttributeValueSchema: JSONSchemaType<string> = { type: 'string', minLength: 8, maxLength: 128 }
100
100
 
101
- export const EntityValueSchema: JSONSchemaType<string> = { type: 'string', minLength: 3, maxLength: 256 }
101
+ export const EntitySlugValueSchema: JSONSchemaType<string> = { type: 'string', minLength: 3, maxLength: 256 }
102
+
103
+ /** @deprecated The organization value on the wire is a slug — use {@link EntitySlugValueSchema}. */
104
+ export const EntityValueSchema: JSONSchemaType<string> = EntitySlugValueSchema
102
105
 
103
106
  export const GroupValueSchema: JSONSchemaType<string> = { type: 'string', minLength: 1, maxLength: 128 }
104
107
 
@@ -115,11 +118,20 @@ export const AuthRoleSchema: JSONSchemaType<AuthRole> = { type: 'string', enum:
115
118
  export const DISPATCHER = 'dispatcher'
116
119
  export const DISPATCHER_AUTHEN = `${DISPATCHER}:authentication`
117
120
 
121
+ /**
122
+ * The login window opened one level up by an application that cannot complete the flow where it is.
123
+ *
124
+ * A separate entrypoint from {@link DISPATCHER} because it is never a `redirect_uri` — the provider
125
+ * always returns to the dispatcher, whatever page opened the window — and because a logout has to
126
+ * run somewhere that does not start the authorization machine.
127
+ */
128
+ export const DISPATCHER_SURROGATE = `${DISPATCHER}:surrogate`
129
+
118
130
  export const AUTHEN_RELY = `${AUTHEN}-rely`
119
131
 
120
132
  export const AUTH_HEADER = 'authorization'
121
133
  export const AUTH_QUERY = 'token'
122
- export const ENTITY_QUERY = 'entity'
134
+ export const ENTITY_QUERY = 'entitySlug'
123
135
  export const PROFILE_QUERY = 'profile'
124
136
 
125
137
  export const MOD_RECAPTCHA = '_external:re-captcha'
@@ -1,7 +1,7 @@
1
1
 
2
2
  import type { JSONSchemaType } from 'ajv'
3
3
  import type { Profile } from '../types.js'
4
- import { EntityValueSchema, IdValueSchema } from '../consts.js'
4
+ import { EntitySlugValueSchema, IdValueSchema } from '../consts.js'
5
5
  import { PermissionSetSchema, AttributeSetSchema } from '../permission/model.js'
6
6
 
7
7
  export const ProfileSchema: JSONSchemaType<Profile> = {
@@ -12,7 +12,7 @@ export const ProfileSchema: JSONSchemaType<Profile> = {
12
12
  credential: { type: 'string', nullable: true },
13
13
  secret: { type: 'string', nullable: true },
14
14
  groups: { type: 'array', items: { type: 'string' }, nullable: true },
15
- entityId: {...EntityValueSchema, nullable: true},
15
+ entitySlug: {...EntitySlugValueSchema, nullable: true},
16
16
  scopes: { type: 'array', items: { type: 'string' } },
17
17
  permissions: { type: 'array', items: PermissionSetSchema, nullable: true },
18
18
  attributes: { type: 'array', items: AttributeSetSchema, nullable: true },
package/src/errors.ts CHANGED
@@ -27,6 +27,18 @@ export class AuthManagerError extends AuthError {
27
27
  }
28
28
  }
29
29
 
30
+ /** An authentication authority could not be consulted, so access must fail closed. */
31
+ export class AuthUnavailable extends AuthError {
32
+ public static override typeName: string = `${AuthError.typeName}Unavailable`
33
+ public static httpStatus = 503
34
+ public static allowServerErrorStatus = true
35
+
36
+ constructor(message: string = 'unavailable') {
37
+ super(`unavailable:${message}`)
38
+ this.type = AuthUnavailable.typeName
39
+ }
40
+ }
41
+
30
42
  export class AuthManagerUnsupported extends AuthManagerError {
31
43
  public static override typeName: string = `${AuthManagerError.typeName}Unsupported`
32
44
 
@@ -120,6 +132,7 @@ export class ProfileConsistencyError extends ProfileError {
120
132
  ResilientError.registerErrorClass(AuthError)
121
133
  ResilientError.registerErrorClass(AuthUnknown)
122
134
  ResilientError.registerErrorClass(AuthManagerError)
135
+ ResilientError.registerErrorClass(AuthUnavailable)
123
136
  ResilientError.registerErrorClass(AuthManagerUnsupported)
124
137
  ResilientError.registerErrorClass(AuthenFailed)
125
138
  ResilientError.registerErrorClass(AuthenExists)
package/src/helper.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Auth, AuthCredentials, AuthToken } from './types.js'
1
+ import type { Auth, AuthCredentials, AuthToken, Authorization } from './types.js'
2
2
  import { Ajv } from 'ajv'
3
3
  import formatsPlugin from 'ajv-formats'
4
4
  import { AuthCredentialsSchema, AuthSchema } from './allowance/model.js'
@@ -30,3 +30,15 @@ export const isAuthCredentials = (auth: unknown): auth is AuthCredentials =>
30
30
  export const isAuthToken = (auth: unknown): auth is AuthToken =>
31
31
  typeof auth === 'object' && auth != null
32
32
  && ("token" in auth) && typeof auth.token === 'string'
33
+
34
+ /**
35
+ * The organization slug carried by an auth payload, tolerating tokens minted before the field
36
+ * was named.
37
+ *
38
+ * Tokens outlive deployments: one signed with the previous release still arrives with the value
39
+ * under `entityId`, and it stays valid until it expires. Everything that reads the organization
40
+ * off a payload goes through here so that window needs no second code path — and so the day the
41
+ * fallback can be deleted is a single-line change rather than an audit.
42
+ */
43
+ export const entitySlugOf = (payload?: Partial<Authorization> | null): string | undefined =>
44
+ payload?.entitySlug ?? (payload as { entityId?: string } | null | undefined)?.entityId
package/src/types.ts CHANGED
@@ -15,7 +15,7 @@ export interface AuthCredentials extends AuthPayload {
15
15
  ProfilePayload:
16
16
  groups?: string[]
17
17
  Authorization:
18
- entityId?: string
18
+ entitySlug?: string
19
19
  scopes: string[]
20
20
  permissions?: PermissionSet[]
21
21
  attributes?: AttributeSet[]
@@ -47,7 +47,7 @@ export interface AuthPayload extends ProfilePayload {
47
47
  ProfilePayload:
48
48
  groups?: string[]
49
49
  Authorization:
50
- entityId?: string
50
+ entitySlug?: string
51
51
  scopes: string[]
52
52
  permissions?: PermissionSet[]
53
53
  attributes?: AttributeSet[]
@@ -65,7 +65,7 @@ export interface ProfilePayload extends Authorization {
65
65
  groups?: string[]
66
66
  /**
67
67
  Authorization:
68
- entityId?: string
68
+ entitySlug?: string
69
69
  scopes: string[]
70
70
  permissions?: PermissionSet[]
71
71
  attributes?: AttributeSet[]
@@ -75,7 +75,17 @@ export interface ProfilePayload extends Authorization {
75
75
  }
76
76
 
77
77
  export interface Authorization {
78
- entityId?: string
78
+ /**
79
+ * The organization entity's slug — renameable, and the ONLY entity value that travels on the
80
+ * wire: in tokens, in URLs and in request bodies.
81
+ *
82
+ * It is deliberately NOT a database key. An implementation that stores things per organization
83
+ * keeps its own stable `entityId` on its records and resolves this slug to it at the boundary,
84
+ * so a rename costs one registry write instead of a migration of every collection, object name
85
+ * and third-party record that ever referenced the organization. Basic auth knows nothing about
86
+ * that id — see `@owlmeans/auth-common`'s entity resolver for the contract that does.
87
+ */
88
+ entitySlug?: string
79
89
  scopes: string[]
80
90
  permissions?: PermissionSet[]
81
91
  attributes?: AttributeSet[]
@@ -98,7 +108,7 @@ export interface Profile extends ProfilePayload {
98
108
  ProfilePayload:
99
109
  groups?: string[]
100
110
  Authorization:
101
- entityId?: string
111
+ entitySlug?: string
102
112
  scopes: string[]
103
113
  permissions?: PermissionSet[]
104
114
  attributes?: AttributeSet[]
@@ -111,6 +121,10 @@ export interface Auth extends AuthPayload {
111
121
  token: string
112
122
  isUser: boolean
113
123
  createdAt: Date
124
+ /** Opaque session registry key; it is not an organization identifier. */
125
+ sessionId?: string
126
+ /** Monotonic authorization revision supplied by the session registry. */
127
+ authorizationVersion?: number
114
128
  /**
115
129
  AuthPayload:
116
130
  type: string
@@ -122,7 +136,7 @@ export interface Auth extends AuthPayload {
122
136
  ProfilePayload:
123
137
  groups?: string[]
124
138
  Authorization:
125
- entityId?: string
139
+ entitySlug?: string
126
140
  scopes: string[]
127
141
  permissions?: PermissionSet[]
128
142
  attributes?: AttributeSet[]
@@ -160,7 +174,7 @@ export interface AllowanceRequest extends Partial<AuthPayload> {
160
174
  ProfilePayload:
161
175
  groups?: string[]
162
176
  Authorization:
163
- entityId?: string
177
+ entitySlug?: string
164
178
  scopes?: string[]
165
179
  permissions?: PermissionSet[]
166
180
  attributes?: AttributeSet[]
package/build/.gitkeep DELETED
File without changes