@absolutejs/auth 0.37.0 → 0.40.0-beta.0

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.
@@ -1,6 +1,7 @@
1
1
  import type { RouteString } from '../types';
2
2
  import { type SigningKey } from './keys';
3
3
  import type { OnClientRegistration } from './registration';
4
+ import type { VciConfig } from './vci';
4
5
  import type { AuthorizationCodeStore, BackchannelAuthStore, ClientAssertionJtiStore, ClientRegistrationTokenStore, DeviceAuthorizationStore, InitialAccessTokenStore, LogoutDeliveryStore, OAuthClient, OAuthClientStore, OidcRefreshTokenStore, PushedAuthorizationRequestStore } from './types';
5
6
  export declare const DEFAULT_OIDC_ROUTE: RouteString;
6
7
  export type OidcProviderConfig<UserType> = {
@@ -66,6 +67,7 @@ export type OidcProviderConfig<UserType> = {
66
67
  refreshTokenStore: OidcRefreshTokenStore;
67
68
  refreshTokenTtlMs?: number;
68
69
  signingKey: SigningKey;
70
+ vciConfig?: VciConfig;
69
71
  };
70
72
  export type TokenExchangeResult = {
71
73
  error: 'invalid_grant' | 'invalid_scope';
@@ -0,0 +1,3 @@
1
+ import type { CredentialNonceStore, CredentialOfferStore } from './vci';
2
+ export declare const createInMemoryCredentialNonceStore: () => CredentialNonceStore;
3
+ export declare const createInMemoryCredentialOfferStore: () => CredentialOfferStore;
@@ -76,6 +76,7 @@ export declare const oidcProviderRoutes: <UserType>(config: OidcProviderConfig<U
76
76
  client_assertion?: string | undefined;
77
77
  client_assertion_type?: string | undefined;
78
78
  code_verifier?: string | undefined;
79
+ 'pre-authorized_code'?: string | undefined;
79
80
  subject_token?: string | undefined;
80
81
  subject_token_type?: string | undefined;
81
82
  };
@@ -0,0 +1,159 @@
1
+ import type { RouteString } from '../types';
2
+ import { type SigningKey } from './keys';
3
+ export declare const PRE_AUTHORIZED_CODE_GRANT = "urn:ietf:params:oauth:grant-type:pre-authorized_code";
4
+ export type CredentialConfiguration = {
5
+ format: 'vc+sd-jwt';
6
+ id: string;
7
+ display?: Array<{
8
+ locale?: string;
9
+ name: string;
10
+ }>;
11
+ order?: string[];
12
+ claims?: Record<string, {
13
+ display?: Array<{
14
+ locale?: string;
15
+ name: string;
16
+ }>;
17
+ }>;
18
+ vct: string;
19
+ };
20
+ export type CredentialOffer = {
21
+ clientId: string;
22
+ configurationId: string;
23
+ createdAt: number;
24
+ expiresAt: number;
25
+ preAuthorizedCodeHash: string;
26
+ redeemed: boolean;
27
+ userId: string;
28
+ };
29
+ export type CredentialOfferStore = {
30
+ consumeOffer: (preAuthorizedCodeHash: string) => Promise<CredentialOffer | undefined>;
31
+ saveOffer: (offer: CredentialOffer) => Promise<void>;
32
+ };
33
+ export type CredentialNonceRecord = {
34
+ expiresAt: number;
35
+ nonceHash: string;
36
+ };
37
+ export type CredentialNonceStore = {
38
+ consumeNonce: (nonceHash: string) => Promise<CredentialNonceRecord | undefined>;
39
+ saveNonce: (record: CredentialNonceRecord) => Promise<void>;
40
+ };
41
+ export type VciConfig = {
42
+ accessTokenTtlMs?: number;
43
+ credentialConfigurations: CredentialConfiguration[];
44
+ credentialNonceStore?: CredentialNonceStore;
45
+ credentialOfferStore: CredentialOfferStore;
46
+ nonceTtlMs?: number;
47
+ offerTtlMs?: number;
48
+ resolveCredentialClaims: (context: {
49
+ configurationId: string;
50
+ userId: string;
51
+ }) => Promise<Record<string, unknown>> | Record<string, unknown>;
52
+ resolveProtectedClaims?: (context: {
53
+ configurationId: string;
54
+ userId: string;
55
+ }) => Promise<Record<string, unknown>> | Record<string, unknown>;
56
+ signingKey?: SigningKey;
57
+ vciRoute?: RouteString;
58
+ };
59
+ export declare const DEFAULT_VCI_ROUTE: RouteString;
60
+ export declare const createCredentialOffer: ({ clientId, configurationId, now, store, ttlMs, userId }: {
61
+ clientId: string;
62
+ configurationId: string;
63
+ now?: number;
64
+ store: CredentialOfferStore;
65
+ ttlMs?: number;
66
+ userId: string;
67
+ }) => Promise<{
68
+ offer: CredentialOffer;
69
+ preAuthorizedCode: string;
70
+ }>;
71
+ export type PreAuthExchangeResult = {
72
+ error: 'expired_token' | 'invalid_grant';
73
+ ok: false;
74
+ } | {
75
+ access_token: string;
76
+ c_nonce?: string;
77
+ c_nonce_expires_in?: number;
78
+ expires_in: number;
79
+ ok: true;
80
+ token_type: 'Bearer';
81
+ };
82
+ export declare const exchangePreAuthorizedCode: ({ config, issuer, now, preAuthorizedCode, signingKey }: {
83
+ config: VciConfig;
84
+ issuer: string;
85
+ now?: number;
86
+ preAuthorizedCode: string;
87
+ signingKey: SigningKey;
88
+ }) => Promise<{
89
+ error: "expired_token" | "invalid_grant";
90
+ ok: false;
91
+ } | {
92
+ access_token: string;
93
+ c_nonce?: string;
94
+ c_nonce_expires_in?: number;
95
+ expires_in: number;
96
+ ok: true;
97
+ token_type: "Bearer";
98
+ }>;
99
+ export type CredentialIssueInput = {
100
+ accessToken: string;
101
+ proofJwt?: string;
102
+ requestedFormat?: 'vc+sd-jwt';
103
+ };
104
+ export type CredentialIssueResult = {
105
+ credential: string;
106
+ format: 'vc+sd-jwt';
107
+ ok: true;
108
+ } | {
109
+ error: 'invalid_credential_request' | 'invalid_proof' | 'invalid_token' | 'unsupported_credential_format';
110
+ ok: false;
111
+ };
112
+ export declare const buildIssuerMetadata: ({ config, issuer, vciRoute }: {
113
+ config: VciConfig;
114
+ issuer: string;
115
+ vciRoute: RouteString;
116
+ }) => {
117
+ credential_configurations_supported: {
118
+ [k: string]: {
119
+ claims: Record<string, {
120
+ display?: Array<{
121
+ locale?: string;
122
+ name: string;
123
+ }>;
124
+ }> | undefined;
125
+ credential_signing_alg_values_supported: string[];
126
+ cryptographic_binding_methods_supported: string[];
127
+ display: {
128
+ locale?: string;
129
+ name: string;
130
+ }[] | undefined;
131
+ format: "vc+sd-jwt";
132
+ order: string[] | undefined;
133
+ proof_types_supported: {
134
+ jwt: {
135
+ proof_signing_alg_values_supported: string[];
136
+ };
137
+ };
138
+ vct: string;
139
+ };
140
+ };
141
+ credential_endpoint: string;
142
+ credential_issuer: string;
143
+ nonce_endpoint: string | undefined;
144
+ token_endpoint: string;
145
+ };
146
+ export declare const issueCredential: ({ config, input, issuer, now, signingKey }: {
147
+ config: VciConfig;
148
+ input: CredentialIssueInput;
149
+ issuer: string;
150
+ now?: number;
151
+ signingKey: SigningKey;
152
+ }) => Promise<{
153
+ credential: string;
154
+ format: "vc+sd-jwt";
155
+ ok: true;
156
+ } | {
157
+ error: "invalid_credential_request" | "invalid_proof" | "invalid_token" | "unsupported_credential_format";
158
+ ok: false;
159
+ }>;
@@ -0,0 +1,92 @@
1
+ import { Elysia } from 'elysia';
2
+ import type { SigningKey } from './keys';
3
+ import { type VciConfig } from './vci';
4
+ export declare const vciRoutes: ({ issuerUrl, signingKey, vciConfig }: {
5
+ issuerUrl: string;
6
+ signingKey: SigningKey;
7
+ vciConfig: VciConfig;
8
+ }) => Elysia<"", {
9
+ decorator: {};
10
+ store: {};
11
+ derive: {};
12
+ resolve: {};
13
+ }, {
14
+ typebox: {};
15
+ error: {};
16
+ }, {
17
+ schema: {};
18
+ standaloneSchema: {};
19
+ macro: {};
20
+ macroFn: {};
21
+ parser: {};
22
+ response: {};
23
+ }, {
24
+ ".well-known": {
25
+ "openid-credential-issuer": {
26
+ get: {
27
+ body: unknown;
28
+ params: {};
29
+ query: unknown;
30
+ headers: unknown;
31
+ response: {
32
+ 200: Response;
33
+ };
34
+ };
35
+ };
36
+ };
37
+ } & {
38
+ [x: string]: {
39
+ credential: {
40
+ post: {
41
+ body: {
42
+ format?: "vc+sd-jwt" | undefined;
43
+ proof?: {
44
+ jwt: string;
45
+ proof_type: "jwt";
46
+ } | undefined;
47
+ };
48
+ params: {};
49
+ query: unknown;
50
+ headers: unknown;
51
+ response: {
52
+ 200: Response;
53
+ 422: {
54
+ type: "validation";
55
+ on: string;
56
+ summary?: string;
57
+ message?: string;
58
+ found?: unknown;
59
+ property?: string;
60
+ expected?: string;
61
+ };
62
+ };
63
+ };
64
+ };
65
+ };
66
+ } & {
67
+ [x: string]: {
68
+ nonce: {
69
+ post: {
70
+ body: unknown;
71
+ params: {};
72
+ query: unknown;
73
+ headers: unknown;
74
+ response: {
75
+ 200: Response;
76
+ };
77
+ };
78
+ };
79
+ };
80
+ }, {
81
+ derive: {};
82
+ resolve: {};
83
+ schema: {};
84
+ standaloneSchema: {};
85
+ response: {};
86
+ }, {
87
+ derive: {};
88
+ resolve: {};
89
+ schema: {};
90
+ standaloneSchema: {};
91
+ response: {};
92
+ }>;
@@ -1,8 +1,10 @@
1
1
  import type { OrganizationId } from '../tenancy';
2
2
  import type { RouteString } from '../types';
3
+ import type { ScimAttributeMap } from './extensions';
3
4
  import type { ScimFilter, ScimGroup, ScimGroupInput, ScimTokenStore, ScimUser, ScimUserInput } from './types';
4
5
  export declare const DEFAULT_SCIM_ROUTE = "/scim/v2";
5
6
  export type ScimConfig = {
7
+ customAttributes?: ScimAttributeMap;
6
8
  getScimGroup?: (context: {
7
9
  id: string;
8
10
  organizationId: OrganizationId;
@@ -0,0 +1,30 @@
1
+ import type { ScimGroupMember } from './types';
2
+ export type ScimAttributeDefinition = {
3
+ caseExact?: boolean;
4
+ description?: string;
5
+ multiValued?: boolean;
6
+ mutability?: 'immutable' | 'readOnly' | 'readWrite' | 'writeOnly';
7
+ name: string;
8
+ required?: boolean;
9
+ returned?: 'always' | 'default' | 'never' | 'request';
10
+ subAttributes?: ScimAttributeDefinition[];
11
+ type: 'boolean' | 'complex' | 'dateTime' | 'decimal' | 'integer' | 'reference' | 'string';
12
+ uniqueness?: 'global' | 'none' | 'server';
13
+ };
14
+ export type ScimSchemaDefinition = {
15
+ attributes: ScimAttributeDefinition[];
16
+ description?: string;
17
+ id: string;
18
+ name: string;
19
+ };
20
+ export type ScimAttributeMap = {
21
+ fromScim: (body: Record<string, unknown>) => Record<string, unknown>;
22
+ schemas?: ScimSchemaDefinition[];
23
+ toScim: (custom: Record<string, unknown>) => Record<string, unknown>;
24
+ };
25
+ export declare const defineScimAttributeMap: (map: ScimAttributeMap) => ScimAttributeMap;
26
+ export type ScimGroupMembershipDelta = {
27
+ added: ScimGroupMember[];
28
+ removed: ScimGroupMember[];
29
+ };
30
+ export declare const diffScimGroupMembers: (current: ScimGroupMember[], next: ScimGroupMember[]) => ScimGroupMembershipDelta;
@@ -1,6 +1,6 @@
1
1
  import { Elysia } from 'elysia';
2
2
  import { type ScimConfig } from './config';
3
- export declare const scimRoutes: ({ getScimGroup, getScimUser, listScimGroups, listScimUsers, onScimGroupCreate, onScimGroupDelete, onScimGroupReplace, onScimUserCreate, onScimUserDeactivate, onScimUserReplace, scimRoute, scimTokenStore }: ScimConfig) => Elysia<"", {
3
+ export declare const scimRoutes: ({ customAttributes, getScimGroup, getScimUser, listScimGroups, listScimUsers, onScimGroupCreate, onScimGroupDelete, onScimGroupReplace, onScimUserCreate, onScimUserDeactivate, onScimUserReplace, scimRoute, scimTokenStore }: ScimConfig) => Elysia<"", {
4
4
  decorator: {};
5
5
  store: {};
6
6
  derive: {};
@@ -281,6 +281,76 @@ export declare const scimRoutes: ({ getScimGroup, getScimUser, listScimGroups, l
281
281
  };
282
282
  };
283
283
  };
284
+ } & {
285
+ [x: string]: {
286
+ get: {
287
+ body: unknown;
288
+ params: {};
289
+ query: unknown;
290
+ headers: unknown;
291
+ response: {
292
+ 200: Response;
293
+ };
294
+ };
295
+ };
296
+ } & {
297
+ [x: string]: {
298
+ get: {
299
+ body: unknown;
300
+ params: {
301
+ id: string;
302
+ };
303
+ query: unknown;
304
+ headers: unknown;
305
+ response: {
306
+ 200: Response;
307
+ 422: {
308
+ type: "validation";
309
+ on: string;
310
+ summary?: string;
311
+ message?: string;
312
+ found?: unknown;
313
+ property?: string;
314
+ expected?: string;
315
+ };
316
+ };
317
+ };
318
+ };
319
+ } & {
320
+ [x: string]: {
321
+ get: {
322
+ body: unknown;
323
+ params: {};
324
+ query: unknown;
325
+ headers: unknown;
326
+ response: {
327
+ 200: Response;
328
+ };
329
+ };
330
+ };
331
+ } & {
332
+ [x: string]: {
333
+ get: {
334
+ body: unknown;
335
+ params: {
336
+ id: string;
337
+ };
338
+ query: unknown;
339
+ headers: unknown;
340
+ response: {
341
+ 200: Response;
342
+ 422: {
343
+ type: "validation";
344
+ on: string;
345
+ summary?: string;
346
+ message?: string;
347
+ found?: unknown;
348
+ property?: string;
349
+ expected?: string;
350
+ };
351
+ };
352
+ };
353
+ };
284
354
  }, {
285
355
  derive: {};
286
356
  resolve: {};
@@ -1,6 +1,9 @@
1
+ import type { ScimAttributeMap, ScimSchemaDefinition } from './extensions';
1
2
  import type { ScimFilter, ScimGroup, ScimGroupInput, ScimUser, ScimUserInput } from './types';
2
- export declare const toUserResource: (user: ScimUser, location: string) => Record<string, unknown>;
3
- export declare const parseUserInput: (body: unknown) => ScimUserInput | undefined;
3
+ declare const SCHEMA_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:Schema";
4
+ declare const RESOURCE_TYPE_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:ResourceType";
5
+ export declare const toUserResource: (user: ScimUser, location: string, map?: ScimAttributeMap) => Record<string, unknown>;
6
+ export declare const parseUserInput: (body: unknown, map?: ScimAttributeMap) => ScimUserInput | undefined;
4
7
  export declare const applyPatch: (user: ScimUser, body: unknown) => ScimUserInput;
5
8
  export declare const listResponse: (resources: Record<string, unknown>[]) => {
6
9
  itemsPerPage: number;
@@ -13,6 +16,13 @@ export declare const parseFilter: (filter: string | undefined) => ScimFilter | u
13
16
  export declare const scimError: (httpStatus: number, detail: string, scimType?: string) => Response;
14
17
  export declare const scimJson: (resource: unknown, httpStatus: number) => Response;
15
18
  export declare const serviceProviderConfig: (location: string) => {
19
+ authenticationSchemes: {
20
+ description: string;
21
+ name: string;
22
+ primary: boolean;
23
+ specUri: string;
24
+ type: string;
25
+ }[];
16
26
  bulk: {
17
27
  maxOperations: number;
18
28
  maxPayloadSize: number;
@@ -40,6 +50,34 @@ export declare const serviceProviderConfig: (location: string) => {
40
50
  supported: boolean;
41
51
  };
42
52
  };
53
+ export declare const schemaList: (location: string, extras?: ScimSchemaDefinition[]) => {
54
+ itemsPerPage: number;
55
+ Resources: Record<string, unknown>[];
56
+ schemas: string[];
57
+ startIndex: number;
58
+ totalResults: number;
59
+ };
60
+ export declare const schemaOne: (location: string, id: string, extras?: ScimSchemaDefinition[]) => Record<string, unknown> | undefined;
61
+ export declare const resourceTypeList: (location: string, usersEndpoint: string, groupsEndpoint: string, extras?: ScimSchemaDefinition[]) => {
62
+ itemsPerPage: number;
63
+ Resources: Record<string, unknown>[];
64
+ schemas: string[];
65
+ startIndex: number;
66
+ totalResults: number;
67
+ };
68
+ export declare const resourceTypeOne: (location: string, id: string, usersEndpoint: string, groupsEndpoint: string, extras?: ScimSchemaDefinition[]) => {
69
+ description: string;
70
+ endpoint: string;
71
+ id: string;
72
+ meta: {
73
+ location: string;
74
+ resourceType: string;
75
+ };
76
+ name: string;
77
+ schema: string;
78
+ schemas: string[];
79
+ } | undefined;
80
+ export { RESOURCE_TYPE_SCHEMA, SCHEMA_SCHEMA };
43
81
  export declare const applyGroupPatch: (group: ScimGroup, body: unknown) => ScimGroupInput;
44
82
  export declare const parseGroupInput: (body: unknown) => ScimGroupInput | undefined;
45
83
  export declare const toGroupResource: (group: ScimGroup, location: string) => Record<string, unknown>;
@@ -14,6 +14,7 @@ export type ScimTokenStore = {
14
14
  };
15
15
  export type ScimUser = {
16
16
  active: boolean;
17
+ custom?: Record<string, unknown>;
17
18
  displayName?: string;
18
19
  email?: string;
19
20
  externalId?: string;
@@ -24,6 +25,7 @@ export type ScimUser = {
24
25
  };
25
26
  export type ScimUserInput = {
26
27
  active: boolean;
28
+ custom?: Record<string, unknown>;
27
29
  displayName?: string;
28
30
  email?: string;
29
31
  externalId?: string;
@@ -0,0 +1,37 @@
1
+ import { type SigningKey } from '../oidc/keys';
2
+ declare const toBase64Url: (bytes: ArrayBuffer | Uint8Array) => string;
3
+ declare const fromBase64Url: (value: string) => Uint8Array<ArrayBuffer>;
4
+ export type SdDisclosure = {
5
+ claimName: string;
6
+ claimValue: unknown;
7
+ encoded: string;
8
+ salt: string;
9
+ };
10
+ export type SdJwtVcIssueInput = {
11
+ base: Record<string, unknown>;
12
+ holderJwk?: JsonWebKey;
13
+ selective: Record<string, unknown>;
14
+ signingKey: SigningKey;
15
+ };
16
+ export declare const issueSdJwtVc: (input: SdJwtVcIssueInput) => Promise<string>;
17
+ export type ParsedSdJwtVc = {
18
+ disclosures: string[];
19
+ jwt: string;
20
+ keyBindingJwt: string | undefined;
21
+ };
22
+ export declare const parseSdJwtVc: (token: string) => ParsedSdJwtVc;
23
+ export declare const presentSdJwtVc: (parsed: ParsedSdJwtVc, selectedClaims: string[], keyBindingJwt?: string) => string;
24
+ export type VerifiedSdJwtVc = {
25
+ cnf: {
26
+ jwk: JsonWebKey;
27
+ } | undefined;
28
+ disclosedClaims: Record<string, unknown>;
29
+ keyBindingJwt: string | undefined;
30
+ protectedClaims: Record<string, unknown>;
31
+ };
32
+ export type SdJwtVcVerifyInput = {
33
+ issuerPublicJwk: JsonWebKey;
34
+ token: string;
35
+ };
36
+ export declare const verifySdJwtVc: (input: SdJwtVcVerifyInput) => Promise<VerifiedSdJwtVc | undefined>;
37
+ export { fromBase64Url, toBase64Url };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.37.0",
2
+ "version": "0.40.0-beta.0",
3
3
  "name": "@absolutejs/auth",
4
4
  "description": "An authorization library for absolutejs",
5
5
  "repository": {