@schemavaults/auth-common 0.33.2 → 0.36.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.
- package/dist/api-scopes/api-server-scope.d.ts +66 -0
- package/dist/api-scopes/api-server-scope.js +97 -0
- package/dist/api-scopes/api-server-scope.js.map +1 -0
- package/dist/api-scopes/consent.d.ts +87 -0
- package/dist/api-scopes/consent.js +75 -0
- package/dist/api-scopes/consent.js.map +1 -0
- package/dist/api-scopes/index.d.ts +8 -0
- package/dist/api-scopes/index.js +5 -0
- package/dist/api-scopes/index.js.map +1 -0
- package/dist/api-scopes/scope-grants.d.ts +37 -0
- package/dist/api-scopes/scope-grants.js +49 -0
- package/dist/api-scopes/scope-grants.js.map +1 -0
- package/dist/api-scopes/scope-sync.d.ts +127 -0
- package/dist/api-scopes/scope-sync.js +149 -0
- package/dist/api-scopes/scope-sync.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/oidc/index.d.ts +2 -2
- package/dist/oidc/index.js +1 -1
- package/dist/oidc/index.js.map +1 -1
- package/dist/oidc/scope.d.ts +48 -0
- package/dist/oidc/scope.js +86 -0
- package/dist/oidc/scope.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API scopes: the OAuth 2.0 scope values (RFC 6749 §3.3) an API server
|
|
3
|
+
* (resource server) defines for itself, e.g. `notes:read` or
|
|
4
|
+
* `https://api.example.com/auth/drive`, each with a human readable
|
|
5
|
+
* description for consent screens. A client asks for them on an
|
|
6
|
+
* authorization request that names the API server as its RFC 8707
|
|
7
|
+
* `resource`; the auth server grants the requested scopes the API server
|
|
8
|
+
* defines and stamps them on the access tokens it mints for that API
|
|
9
|
+
* server, whose route guards enforce them (`requiredScopes`).
|
|
10
|
+
*
|
|
11
|
+
* The OIDC scope names (`OIDC_RESERVED_SCOPES`) can never be API scopes,
|
|
12
|
+
* so a granted scope string splits unambiguously into its OIDC and API
|
|
13
|
+
* parts (`partitionGrantedScopes`).
|
|
14
|
+
*/
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
export declare const MAX_API_SCOPE_VALUE_LENGTH: 128;
|
|
17
|
+
export declare const MAX_API_SCOPE_DESCRIPTION_LENGTH: 256;
|
|
18
|
+
/** Upper bound on the scopes one API server may define. */
|
|
19
|
+
export declare const MAX_API_SCOPES_PER_API_SERVER: 100;
|
|
20
|
+
/**
|
|
21
|
+
* One RFC 6749 §3.3 scope-token: printable ASCII except SP, `"` and `\`.
|
|
22
|
+
*/
|
|
23
|
+
export declare const API_SCOPE_VALUE_REGEX: RegExp;
|
|
24
|
+
/**
|
|
25
|
+
* A scope value an API server may define: a single RFC 6749 scope-token
|
|
26
|
+
* that is not one of the OIDC scope names.
|
|
27
|
+
*/
|
|
28
|
+
export declare const apiScopeValueSchema: z.ZodString;
|
|
29
|
+
export type ApiScopeValue = z.infer<typeof apiScopeValueSchema>;
|
|
30
|
+
/** What a consent screen tells the user the scope allows. */
|
|
31
|
+
export declare const apiScopeDescriptionSchema: z.ZodString;
|
|
32
|
+
/**
|
|
33
|
+
* An RFC 8707 `resource` value carried through an authorization flow (the
|
|
34
|
+
* login / register / session code requests): an API server id or the URL
|
|
35
|
+
* of one of its registered domains. Only bounded here; the auth server
|
|
36
|
+
* resolves it, and ignores a value it cannot honour.
|
|
37
|
+
*/
|
|
38
|
+
export declare const resourceIndicatorSchema: z.ZodString;
|
|
39
|
+
/** A scope defined by an API server. */
|
|
40
|
+
export declare const apiServerScopeSchema: z.ZodObject<{
|
|
41
|
+
api_server_scope_id: z.ZodGUID;
|
|
42
|
+
api_server_id: z.ZodString;
|
|
43
|
+
scope: z.ZodString;
|
|
44
|
+
description: z.ZodString;
|
|
45
|
+
allow_dynamic_clients: z.ZodBoolean;
|
|
46
|
+
created_at: z.ZodNumber;
|
|
47
|
+
created_by: z.ZodNullable<z.ZodGUID>;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
export type ApiServerScope = z.infer<typeof apiServerScopeSchema>;
|
|
50
|
+
/** Body of a request defining a new scope on an API server. */
|
|
51
|
+
export declare const createApiServerScopeRequestSchema: z.ZodObject<{
|
|
52
|
+
scope: z.ZodString;
|
|
53
|
+
description: z.ZodString;
|
|
54
|
+
allow_dynamic_clients: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
}, z.core.$strict>;
|
|
56
|
+
export type CreateApiServerScopeRequest = z.infer<typeof createApiServerScopeRequestSchema>;
|
|
57
|
+
/**
|
|
58
|
+
* Body of a request changing a scope's description and/or whether dynamic
|
|
59
|
+
* clients may be granted it. The scope value itself is immutable: tokens
|
|
60
|
+
* already carry it, so a rename is a new scope plus a deletion.
|
|
61
|
+
*/
|
|
62
|
+
export declare const updateApiServerScopeRequestSchema: z.ZodObject<{
|
|
63
|
+
description: z.ZodOptional<z.ZodString>;
|
|
64
|
+
allow_dynamic_clients: z.ZodOptional<z.ZodBoolean>;
|
|
65
|
+
}, z.core.$strict>;
|
|
66
|
+
export type UpdateApiServerScopeRequest = z.infer<typeof updateApiServerScopeRequestSchema>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API scopes: the OAuth 2.0 scope values (RFC 6749 §3.3) an API server
|
|
3
|
+
* (resource server) defines for itself, e.g. `notes:read` or
|
|
4
|
+
* `https://api.example.com/auth/drive`, each with a human readable
|
|
5
|
+
* description for consent screens. A client asks for them on an
|
|
6
|
+
* authorization request that names the API server as its RFC 8707
|
|
7
|
+
* `resource`; the auth server grants the requested scopes the API server
|
|
8
|
+
* defines and stamps them on the access tokens it mints for that API
|
|
9
|
+
* server, whose route guards enforce them (`requiredScopes`).
|
|
10
|
+
*
|
|
11
|
+
* The OIDC scope names (`OIDC_RESERVED_SCOPES`) can never be API scopes,
|
|
12
|
+
* so a granted scope string splits unambiguously into its OIDC and API
|
|
13
|
+
* parts (`partitionGrantedScopes`).
|
|
14
|
+
*/
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import { apiServerIdSchema } from "@schemavaults/app-definitions";
|
|
17
|
+
import { isOidcReservedScope } from "../oidc/scope";
|
|
18
|
+
export const MAX_API_SCOPE_VALUE_LENGTH = 128;
|
|
19
|
+
export const MAX_API_SCOPE_DESCRIPTION_LENGTH = 256;
|
|
20
|
+
/** Upper bound on the scopes one API server may define. */
|
|
21
|
+
export const MAX_API_SCOPES_PER_API_SERVER = 100;
|
|
22
|
+
/**
|
|
23
|
+
* One RFC 6749 §3.3 scope-token: printable ASCII except SP, `"` and `\`.
|
|
24
|
+
*/
|
|
25
|
+
export const API_SCOPE_VALUE_REGEX = /^[\x21\x23-\x5B\x5D-\x7E]+$/;
|
|
26
|
+
/**
|
|
27
|
+
* A scope value an API server may define: a single RFC 6749 scope-token
|
|
28
|
+
* that is not one of the OIDC scope names.
|
|
29
|
+
*/
|
|
30
|
+
export const apiScopeValueSchema = z
|
|
31
|
+
.string()
|
|
32
|
+
.min(1)
|
|
33
|
+
.max(MAX_API_SCOPE_VALUE_LENGTH)
|
|
34
|
+
.regex(API_SCOPE_VALUE_REGEX, {
|
|
35
|
+
message: "A scope must be a single RFC 6749 scope-token: printable ASCII without spaces, '\"' or '\\'",
|
|
36
|
+
})
|
|
37
|
+
.refine((scope) => !isOidcReservedScope(scope), {
|
|
38
|
+
message: "OpenID Connect scope names (openid, profile, email, address, phone, offline_access) cannot be defined as API scopes",
|
|
39
|
+
});
|
|
40
|
+
/** What a consent screen tells the user the scope allows. */
|
|
41
|
+
export const apiScopeDescriptionSchema = z
|
|
42
|
+
.string()
|
|
43
|
+
.trim()
|
|
44
|
+
.min(1)
|
|
45
|
+
.max(MAX_API_SCOPE_DESCRIPTION_LENGTH);
|
|
46
|
+
/**
|
|
47
|
+
* An RFC 8707 `resource` value carried through an authorization flow (the
|
|
48
|
+
* login / register / session code requests): an API server id or the URL
|
|
49
|
+
* of one of its registered domains. Only bounded here; the auth server
|
|
50
|
+
* resolves it, and ignores a value it cannot honour.
|
|
51
|
+
*/
|
|
52
|
+
export const resourceIndicatorSchema = z.string().min(1).max(2048);
|
|
53
|
+
/** A scope defined by an API server. */
|
|
54
|
+
export const apiServerScopeSchema = z
|
|
55
|
+
.object({
|
|
56
|
+
api_server_scope_id: z.guid(),
|
|
57
|
+
api_server_id: apiServerIdSchema,
|
|
58
|
+
// Format only (no reserved-name check), so a stored definition always
|
|
59
|
+
// parses on the way out.
|
|
60
|
+
scope: z
|
|
61
|
+
.string()
|
|
62
|
+
.min(1)
|
|
63
|
+
.max(MAX_API_SCOPE_VALUE_LENGTH)
|
|
64
|
+
.regex(API_SCOPE_VALUE_REGEX),
|
|
65
|
+
description: z.string().max(MAX_API_SCOPE_DESCRIPTION_LENGTH),
|
|
66
|
+
// Whether clients registered through RFC 7591 dynamic client
|
|
67
|
+
// registration (which have no app-to-API connection to carry an
|
|
68
|
+
// allowance) may be granted the scope. Only meaningful while the API
|
|
69
|
+
// server allows dynamic clients at all.
|
|
70
|
+
allow_dynamic_clients: z.boolean(),
|
|
71
|
+
created_at: z.number().nonnegative(),
|
|
72
|
+
created_by: z.guid().nullable(),
|
|
73
|
+
})
|
|
74
|
+
.strict();
|
|
75
|
+
/** Body of a request defining a new scope on an API server. */
|
|
76
|
+
export const createApiServerScopeRequestSchema = z
|
|
77
|
+
.object({
|
|
78
|
+
scope: apiScopeValueSchema,
|
|
79
|
+
description: apiScopeDescriptionSchema,
|
|
80
|
+
/** Defaults to true. */
|
|
81
|
+
allow_dynamic_clients: z.boolean().optional(),
|
|
82
|
+
})
|
|
83
|
+
.strict();
|
|
84
|
+
/**
|
|
85
|
+
* Body of a request changing a scope's description and/or whether dynamic
|
|
86
|
+
* clients may be granted it. The scope value itself is immutable: tokens
|
|
87
|
+
* already carry it, so a rename is a new scope plus a deletion.
|
|
88
|
+
*/
|
|
89
|
+
export const updateApiServerScopeRequestSchema = z
|
|
90
|
+
.object({
|
|
91
|
+
description: apiScopeDescriptionSchema.optional(),
|
|
92
|
+
allow_dynamic_clients: z.boolean().optional(),
|
|
93
|
+
})
|
|
94
|
+
.strict()
|
|
95
|
+
.refine((update) => update.description !== undefined ||
|
|
96
|
+
update.allow_dynamic_clients !== undefined, "At least one of 'description' and 'allow_dynamic_clients' must be provided");
|
|
97
|
+
//# sourceMappingURL=api-server-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-server-scope.js","sourceRoot":"","sources":["../../src/api-scopes/api-server-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAY,CAAC;AACvD,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAY,CAAC;AAC7D,2DAA2D;AAC3D,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAY,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAW,6BAA6B,CAAC;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,0BAA0B,CAAC;KAC/B,KAAK,CAAC,qBAAqB,EAAE;IAC5B,OAAO,EACL,6FAA6F;CAChG,CAAC;KACD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE;IAC9C,OAAO,EACL,qHAAqH;CACxH,CAAC,CAAC;AAIL,6DAA6D;AAC7D,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC;KACvC,MAAM,EAAE;KACR,IAAI,EAAE;KACN,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,g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AAC,QAAQ,EAAE;CAC9C,CAAC;KACD,MAAM,EAAE;KACR,MAAM,CACL,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,WAAW,KAAK,SAAS;IAChC,MAAM,CAAC,qBAAqB,KAAK,SAAS,EAC5C,4EAA4E,CAC7E,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-scope user consent: what a user has agreed to let a client
|
|
3
|
+
* application do with an API server, recorded per scope so the consent
|
|
4
|
+
* screen only asks again for what is new (incremental authorization) and
|
|
5
|
+
* the user can withdraw a single scope later.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
/** A scope as a consent screen presents it. */
|
|
9
|
+
export declare const consentScopeSchema: z.ZodObject<{
|
|
10
|
+
api_server_scope_id: z.ZodGUID;
|
|
11
|
+
scope: z.ZodString;
|
|
12
|
+
description: z.ZodString;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
export type ConsentScope = z.infer<typeof consentScopeSchema>;
|
|
15
|
+
/**
|
|
16
|
+
* What the signed-in user would be agreeing to for one authorization
|
|
17
|
+
* request (`GET /api/apps/{app_id}/check-authorization?scope=…&resource=…`).
|
|
18
|
+
*/
|
|
19
|
+
export declare const appConsentStatusSchema: z.ZodObject<{
|
|
20
|
+
success: z.ZodLiteral<true>;
|
|
21
|
+
authorized: z.ZodBoolean;
|
|
22
|
+
consent_required: z.ZodBoolean;
|
|
23
|
+
requested_oidc_scopes: z.ZodArray<z.ZodString>;
|
|
24
|
+
api_server: z.ZodNullable<z.ZodObject<{
|
|
25
|
+
api_server_id: z.ZodString;
|
|
26
|
+
api_server_name: z.ZodString;
|
|
27
|
+
}, z.core.$strict>>;
|
|
28
|
+
granted_api_scopes: z.ZodArray<z.ZodObject<{
|
|
29
|
+
api_server_scope_id: z.ZodGUID;
|
|
30
|
+
scope: z.ZodString;
|
|
31
|
+
description: z.ZodString;
|
|
32
|
+
}, z.core.$strict>>;
|
|
33
|
+
pending_api_scopes: z.ZodArray<z.ZodObject<{
|
|
34
|
+
api_server_scope_id: z.ZodGUID;
|
|
35
|
+
scope: z.ZodString;
|
|
36
|
+
description: z.ZodString;
|
|
37
|
+
}, z.core.$strict>>;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
export type AppConsentStatus = z.infer<typeof appConsentStatusSchema>;
|
|
40
|
+
/** The API scopes a user approved on the consent screen (a subset of the pending ones). */
|
|
41
|
+
export declare const approvedApiScopesSchema: z.ZodArray<z.ZodString>;
|
|
42
|
+
/** One API scope a user granted a connected app. */
|
|
43
|
+
export declare const connectedAppScopeSchema: z.ZodObject<{
|
|
44
|
+
api_server_id: z.ZodString;
|
|
45
|
+
api_server_name: z.ZodString;
|
|
46
|
+
api_server_scope_id: z.ZodGUID;
|
|
47
|
+
scope: z.ZodString;
|
|
48
|
+
description: z.ZodString;
|
|
49
|
+
granted_at: z.ZodNumber;
|
|
50
|
+
}, z.core.$strict>;
|
|
51
|
+
export type ConnectedAppScope = z.infer<typeof connectedAppScopeSchema>;
|
|
52
|
+
/** A third-party application the user authorized, with what it can access. */
|
|
53
|
+
export declare const connectedAppSchema: z.ZodObject<{
|
|
54
|
+
app_id: z.ZodString;
|
|
55
|
+
app_name: z.ZodString;
|
|
56
|
+
app_description: z.ZodString;
|
|
57
|
+
authorized_at: z.ZodNumber;
|
|
58
|
+
last_used_at: z.ZodNullable<z.ZodNumber>;
|
|
59
|
+
api_scopes: z.ZodArray<z.ZodObject<{
|
|
60
|
+
api_server_id: z.ZodString;
|
|
61
|
+
api_server_name: z.ZodString;
|
|
62
|
+
api_server_scope_id: z.ZodGUID;
|
|
63
|
+
scope: z.ZodString;
|
|
64
|
+
description: z.ZodString;
|
|
65
|
+
granted_at: z.ZodNumber;
|
|
66
|
+
}, z.core.$strict>>;
|
|
67
|
+
}, z.core.$strict>;
|
|
68
|
+
export type ConnectedApp = z.infer<typeof connectedAppSchema>;
|
|
69
|
+
export declare const listConnectedAppsResponseSchema: z.ZodObject<{
|
|
70
|
+
success: z.ZodLiteral<true>;
|
|
71
|
+
list: z.ZodArray<z.ZodObject<{
|
|
72
|
+
app_id: z.ZodString;
|
|
73
|
+
app_name: z.ZodString;
|
|
74
|
+
app_description: z.ZodString;
|
|
75
|
+
authorized_at: z.ZodNumber;
|
|
76
|
+
last_used_at: z.ZodNullable<z.ZodNumber>;
|
|
77
|
+
api_scopes: z.ZodArray<z.ZodObject<{
|
|
78
|
+
api_server_id: z.ZodString;
|
|
79
|
+
api_server_name: z.ZodString;
|
|
80
|
+
api_server_scope_id: z.ZodGUID;
|
|
81
|
+
scope: z.ZodString;
|
|
82
|
+
description: z.ZodString;
|
|
83
|
+
granted_at: z.ZodNumber;
|
|
84
|
+
}, z.core.$strict>>;
|
|
85
|
+
}, z.core.$strict>>;
|
|
86
|
+
}, z.core.$strict>;
|
|
87
|
+
export type ListConnectedAppsResponse = z.infer<typeof listConnectedAppsResponseSchema>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-scope user consent: what a user has agreed to let a client
|
|
3
|
+
* application do with an API server, recorded per scope so the consent
|
|
4
|
+
* screen only asks again for what is new (incremental authorization) and
|
|
5
|
+
* the user can withdraw a single scope later.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { apiServerIdSchema, appIdSchema } from "@schemavaults/app-definitions";
|
|
9
|
+
import { MAX_API_SCOPES_PER_API_SERVER, apiScopeValueSchema } from "./api-server-scope";
|
|
10
|
+
/** A scope as a consent screen presents it. */
|
|
11
|
+
export const consentScopeSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
api_server_scope_id: z.guid(),
|
|
14
|
+
scope: z.string(),
|
|
15
|
+
description: z.string(),
|
|
16
|
+
})
|
|
17
|
+
.strict();
|
|
18
|
+
/**
|
|
19
|
+
* What the signed-in user would be agreeing to for one authorization
|
|
20
|
+
* request (`GET /api/apps/{app_id}/check-authorization?scope=…&resource=…`).
|
|
21
|
+
*/
|
|
22
|
+
export const appConsentStatusSchema = z
|
|
23
|
+
.object({
|
|
24
|
+
success: z.literal(true),
|
|
25
|
+
/** Whether the user authorized the app at all (any earlier sign-in). */
|
|
26
|
+
authorized: z.boolean(),
|
|
27
|
+
/**
|
|
28
|
+
* Whether the consent screen must be shown: the app is not authorized
|
|
29
|
+
* yet, or the request asks for API scopes the user has not granted.
|
|
30
|
+
*/
|
|
31
|
+
consent_required: z.boolean(),
|
|
32
|
+
/** The OpenID Connect scopes the request asks for (`openid`, `email`, `profile`). */
|
|
33
|
+
requested_oidc_scopes: z.array(z.string()),
|
|
34
|
+
/** The API server whose scopes the request asks for; null when none. */
|
|
35
|
+
api_server: z
|
|
36
|
+
.object({ api_server_id: apiServerIdSchema, api_server_name: z.string() })
|
|
37
|
+
.strict()
|
|
38
|
+
.nullable(),
|
|
39
|
+
/** The requested API scopes the user already granted the app. */
|
|
40
|
+
granted_api_scopes: z.array(consentScopeSchema),
|
|
41
|
+
/** The requested API scopes awaiting the user's decision. */
|
|
42
|
+
pending_api_scopes: z.array(consentScopeSchema),
|
|
43
|
+
})
|
|
44
|
+
.strict();
|
|
45
|
+
/** The API scopes a user approved on the consent screen (a subset of the pending ones). */
|
|
46
|
+
export const approvedApiScopesSchema = z
|
|
47
|
+
.array(apiScopeValueSchema)
|
|
48
|
+
.max(MAX_API_SCOPES_PER_API_SERVER);
|
|
49
|
+
/** One API scope a user granted a connected app. */
|
|
50
|
+
export const connectedAppScopeSchema = z
|
|
51
|
+
.object({
|
|
52
|
+
api_server_id: apiServerIdSchema,
|
|
53
|
+
api_server_name: z.string(),
|
|
54
|
+
api_server_scope_id: z.guid(),
|
|
55
|
+
scope: z.string(),
|
|
56
|
+
description: z.string(),
|
|
57
|
+
granted_at: z.number().nonnegative(),
|
|
58
|
+
})
|
|
59
|
+
.strict();
|
|
60
|
+
/** A third-party application the user authorized, with what it can access. */
|
|
61
|
+
export const connectedAppSchema = z
|
|
62
|
+
.object({
|
|
63
|
+
app_id: appIdSchema,
|
|
64
|
+
app_name: z.string(),
|
|
65
|
+
app_description: z.string(),
|
|
66
|
+
authorized_at: z.number().nonnegative(),
|
|
67
|
+
/** When the app was last issued a token for the user; null if never (or not tracked). */
|
|
68
|
+
last_used_at: z.number().nonnegative().nullable(),
|
|
69
|
+
api_scopes: z.array(connectedAppScopeSchema),
|
|
70
|
+
})
|
|
71
|
+
.strict();
|
|
72
|
+
export const listConnectedAppsResponseSchema = z
|
|
73
|
+
.object({ success: z.literal(true), list: z.array(connectedAppSchema) })
|
|
74
|
+
.strict();
|
|
75
|
+
//# sourceMappingURL=consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.js","sourceRoot":"","sources":["../../src/api-scopes/consent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAExF,+CAA+C;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAChC,MAAM,CAAC;IACN,mBAAmB,EAAE,CAAC,CAAC,IAAI,EAAE;IAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;CACxB,CAAC;KACD,MAAM,EAAE,CAAC;AAIZ;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC;KACpC,MAAM,CAAC;IACN,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IACxB,wEAAwE;IACxE,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE;IACvB;;;OAGG;IACH,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE;IAC7B,qFAAqF;IACrF,qBAAqB,EAAE,CAAC,CAAC,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,QAAQ,EAAE;IACjD,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,uBAAuB,CAAC;CAC7C,CAAC;KACD,MAAM,EAAE,CAAC;AAIZ,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC;KAC7C,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC;KACvE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { MAX_API_SCOPE_VALUE_LENGTH, MAX_API_SCOPE_DESCRIPTION_LENGTH, MAX_API_SCOPES_PER_API_SERVER, API_SCOPE_VALUE_REGEX, apiScopeValueSchema, apiScopeDescriptionSchema, resourceIndicatorSchema, apiServerScopeSchema, createApiServerScopeRequestSchema, updateApiServerScopeRequestSchema, } from "./api-server-scope";
|
|
2
|
+
export type { ApiScopeValue, ApiServerScope, CreateApiServerScopeRequest, UpdateApiServerScopeRequest, } from "./api-server-scope";
|
|
3
|
+
export { API_SCOPE_GRANTEES, apiScopeGranteeSchema, appApiScopePolicySchema, updateAppApiScopePolicyRequestSchema, } from "./scope-grants";
|
|
4
|
+
export type { ApiScopeGrantee, AppApiScopePolicy, UpdateAppApiScopePolicyRequest, } from "./scope-grants";
|
|
5
|
+
export { consentScopeSchema, appConsentStatusSchema, approvedApiScopesSchema, connectedAppScopeSchema, connectedAppSchema, listConnectedAppsResponseSchema, } from "./consent";
|
|
6
|
+
export type { ConsentScope, AppConsentStatus, ConnectedAppScope, ConnectedApp, ListConnectedAppsResponse, } from "./consent";
|
|
7
|
+
export { API_SERVER_SCOPES_JSON_SCHEMA_PATH, apiScopeManifestEntrySchema, syncApiServerScopesRequestSchema, apiScopeManifestEntries, syncedApiScopeSchema, updatedApiScopeSchema, apiServerScopeSyncResultSchema, syncApiServerScopesResponseSchema, hasApiScopeSyncDrift, } from "./scope-sync";
|
|
8
|
+
export type { ApiScopeManifestEntry, ApiScopeManifestEntryInput, SyncApiServerScopesRequest, SyncApiServerScopesRequestInput, SyncedApiScope, UpdatedApiScope, ApiServerScopeSyncResult, SyncApiServerScopesResponse, } from "./scope-sync";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MAX_API_SCOPE_VALUE_LENGTH, MAX_API_SCOPE_DESCRIPTION_LENGTH, MAX_API_SCOPES_PER_API_SERVER, API_SCOPE_VALUE_REGEX, apiScopeValueSchema, apiScopeDescriptionSchema, resourceIndicatorSchema, apiServerScopeSchema, createApiServerScopeRequestSchema, updateApiServerScopeRequestSchema, } from "./api-server-scope";
|
|
2
|
+
export { API_SCOPE_GRANTEES, apiScopeGranteeSchema, appApiScopePolicySchema, updateAppApiScopePolicyRequestSchema, } from "./scope-grants";
|
|
3
|
+
export { consentScopeSchema, appConsentStatusSchema, approvedApiScopesSchema, connectedAppScopeSchema, connectedAppSchema, listConnectedAppsResponseSchema, } from "./consent";
|
|
4
|
+
export { API_SERVER_SCOPES_JSON_SCHEMA_PATH, apiScopeManifestEntrySchema, syncApiServerScopesRequestSchema, apiScopeManifestEntries, syncedApiScopeSchema, updatedApiScopeSchema, apiServerScopeSyncResultSchema, syncApiServerScopesResponseSchema, hasApiScopeSyncDrift, } from "./scope-sync";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api-scopes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,6BAA6B,EAC7B,qBAAqB,EACrB,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,iCAAiC,EACjC,iCAAiC,GAClC,MAAM,oBAAoB,CAAC;AAQ5B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,oCAAoC,GACrC,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,+BAA+B,GAChC,MAAM,WAAW,CAAC;AASnB,OAAO,EACL,kCAAkC,EAClC,2BAA2B,EAC3B,gCAAgC,EAChC,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,iCAAiC,EACjC,oBAAoB,GACrB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-app scope allowances ("client grants"): which of an API server's
|
|
3
|
+
* scopes a connected client application may be granted.
|
|
4
|
+
*
|
|
5
|
+
* - `user` allowance: the scopes users may delegate to the app on an
|
|
6
|
+
* authorization request. By default unrestricted (every scope the API
|
|
7
|
+
* server defines; each user still consents per scope); an API server
|
|
8
|
+
* owner may restrict it to a list.
|
|
9
|
+
* - `service_account` allowance: the scopes the app's own service account
|
|
10
|
+
* gets on the client_credentials grant, where no user consents. Empty by
|
|
11
|
+
* default: machine-to-machine tokens carry an API scope only when the API
|
|
12
|
+
* server owner listed it for that app.
|
|
13
|
+
*
|
|
14
|
+
* Dynamically registered clients have no connection; they may be granted
|
|
15
|
+
* the scopes flagged `allow_dynamic_clients` on the API server.
|
|
16
|
+
*/
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
export declare const API_SCOPE_GRANTEES: readonly ["user", "service_account"];
|
|
19
|
+
export type ApiScopeGrantee = (typeof API_SCOPE_GRANTEES)[number];
|
|
20
|
+
export declare const apiScopeGranteeSchema: z.ZodEnum<{
|
|
21
|
+
service_account: "service_account";
|
|
22
|
+
user: "user";
|
|
23
|
+
}>;
|
|
24
|
+
/** The scope allowances of one app-to-API connection. */
|
|
25
|
+
export declare const appApiScopePolicySchema: z.ZodObject<{
|
|
26
|
+
restrict_user_scopes: z.ZodBoolean;
|
|
27
|
+
user_scopes: z.ZodArray<z.ZodString>;
|
|
28
|
+
service_account_scopes: z.ZodArray<z.ZodString>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
export type AppApiScopePolicy = z.infer<typeof appApiScopePolicySchema>;
|
|
31
|
+
/** Body replacing the scope allowances of an app-to-API connection. */
|
|
32
|
+
export declare const updateAppApiScopePolicyRequestSchema: z.ZodObject<{
|
|
33
|
+
restrict_user_scopes: z.ZodBoolean;
|
|
34
|
+
user_scopes: z.ZodArray<z.ZodString>;
|
|
35
|
+
service_account_scopes: z.ZodArray<z.ZodString>;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
export type UpdateAppApiScopePolicyRequest = z.infer<typeof updateAppApiScopePolicyRequestSchema>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-app scope allowances ("client grants"): which of an API server's
|
|
3
|
+
* scopes a connected client application may be granted.
|
|
4
|
+
*
|
|
5
|
+
* - `user` allowance: the scopes users may delegate to the app on an
|
|
6
|
+
* authorization request. By default unrestricted (every scope the API
|
|
7
|
+
* server defines; each user still consents per scope); an API server
|
|
8
|
+
* owner may restrict it to a list.
|
|
9
|
+
* - `service_account` allowance: the scopes the app's own service account
|
|
10
|
+
* gets on the client_credentials grant, where no user consents. Empty by
|
|
11
|
+
* default: machine-to-machine tokens carry an API scope only when the API
|
|
12
|
+
* server owner listed it for that app.
|
|
13
|
+
*
|
|
14
|
+
* Dynamically registered clients have no connection; they may be granted
|
|
15
|
+
* the scopes flagged `allow_dynamic_clients` on the API server.
|
|
16
|
+
*/
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import { MAX_API_SCOPES_PER_API_SERVER, apiScopeValueSchema } from "./api-server-scope";
|
|
19
|
+
export const API_SCOPE_GRANTEES = ["user", "service_account"];
|
|
20
|
+
export const apiScopeGranteeSchema = z.enum(API_SCOPE_GRANTEES);
|
|
21
|
+
const scopeValueListSchema = z
|
|
22
|
+
.array(apiScopeValueSchema)
|
|
23
|
+
.max(MAX_API_SCOPES_PER_API_SERVER)
|
|
24
|
+
.refine((values) => new Set(values).size === values.length, {
|
|
25
|
+
message: "Scope values must be unique",
|
|
26
|
+
});
|
|
27
|
+
/** The scope allowances of one app-to-API connection. */
|
|
28
|
+
export const appApiScopePolicySchema = z
|
|
29
|
+
.object({
|
|
30
|
+
/**
|
|
31
|
+
* False (the default): users may grant the app every scope the API
|
|
32
|
+
* server defines. True: only `user_scopes`.
|
|
33
|
+
*/
|
|
34
|
+
restrict_user_scopes: z.boolean(),
|
|
35
|
+
/** The scopes users may grant when `restrict_user_scopes` is on. */
|
|
36
|
+
user_scopes: z.array(z.string()),
|
|
37
|
+
/** The scopes the app's service account gets (client_credentials). */
|
|
38
|
+
service_account_scopes: z.array(z.string()),
|
|
39
|
+
})
|
|
40
|
+
.strict();
|
|
41
|
+
/** Body replacing the scope allowances of an app-to-API connection. */
|
|
42
|
+
export const updateAppApiScopePolicyRequestSchema = z
|
|
43
|
+
.object({
|
|
44
|
+
restrict_user_scopes: z.boolean(),
|
|
45
|
+
user_scopes: scopeValueListSchema,
|
|
46
|
+
service_account_scopes: scopeValueListSchema,
|
|
47
|
+
})
|
|
48
|
+
.strict();
|
|
49
|
+
//# sourceMappingURL=scope-grants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-grants.js","sourceRoot":"","sources":["../../src/api-scopes/scope-grants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAExF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAU,CAAC;AAEvE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AAEhE,MAAM,oBAAoB,GAAG,CAAC;KAC3B,KAAK,CAAC,mBAAmB,CAAC;KAC1B,GAAG,CAAC,6BAA6B,CAAC;KAClC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,MAAM,EAAE;IAC1D,OAAO,EAAE,6BAA6B;CACvC,CAAC,CAAC;AAEL,yDAAyD;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC;KACrC,MAAM,CAAC;IACN;;;OAGG;IACH,oBAAoB,EAAE,CAAC,CAAC,OAAO,EAAE;IACjC,oEAAoE;IACpE,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAChC,sEAAsE;IACtE,sBAAsB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAC5C,CAAC;KACD,MAAM,EAAE,CAAC;AAIZ,uEAAuE;AACvE,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC;KAClD,MAAM,CAAC;IACN,oBAAoB,EAAE,CAAC,CAAC,OAAO,EAAE;IACjC,WAAW,EAAE,oBAAoB;IACjC,sBAAsB,EAAE,oBAAoB;CAC7C,CAAC;KACD,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope sync: a resource server declares its whole list of API scopes in
|
|
3
|
+
* code (a "scope manifest") and sends it to
|
|
4
|
+
* `PUT /api/resource-server/apis/{api_server_id}/scopes`, authenticated
|
|
5
|
+
* with its JWKS access key. The auth server creates the scopes that are
|
|
6
|
+
* missing and updates the ones whose description (or, when the entry
|
|
7
|
+
* gives it, `allow_dynamic_clients`) changed. It never deletes a scope:
|
|
8
|
+
* deleting one drops users' consents and the per-app allowances set for
|
|
9
|
+
* it, so scopes missing from the list are only reported
|
|
10
|
+
* (`not_in_manifest`) and stay a decision for a person in the console.
|
|
11
|
+
*
|
|
12
|
+
* The request schema is also the source of the manifest JSON Schema the
|
|
13
|
+
* auth server serves at {@link API_SERVER_SCOPES_JSON_SCHEMA_PATH}, so
|
|
14
|
+
* editors, the SDK and the endpoint check the same rules.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
/**
|
|
18
|
+
* Path (on every auth server deployment) of the JSON Schema of scope
|
|
19
|
+
* manifests; a manifest names `<auth server URL><path>` in its `$schema`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const API_SERVER_SCOPES_JSON_SCHEMA_PATH: "/json-schema/api-server-scopes.json";
|
|
22
|
+
/** One scope of a manifest. */
|
|
23
|
+
export declare const apiScopeManifestEntrySchema: z.ZodObject<{
|
|
24
|
+
scope: z.ZodString;
|
|
25
|
+
description: z.ZodString;
|
|
26
|
+
allow_dynamic_clients: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
export type ApiScopeManifestEntry = z.infer<typeof apiScopeManifestEntrySchema>;
|
|
29
|
+
/** An entry as written, before its description is trimmed. */
|
|
30
|
+
export type ApiScopeManifestEntryInput = z.input<typeof apiScopeManifestEntrySchema>;
|
|
31
|
+
/**
|
|
32
|
+
* Body of `PUT /api/resource-server/apis/{api_server_id}/scopes`, and the
|
|
33
|
+
* shape of a scope manifest file: the API server's whole scope list, at
|
|
34
|
+
* most {@link MAX_API_SCOPES_PER_API_SERVER} entries with no scope value
|
|
35
|
+
* repeated, plus an optional `$schema` the endpoint ignores (so a manifest
|
|
36
|
+
* file is sent as it is).
|
|
37
|
+
*/
|
|
38
|
+
export declare const syncApiServerScopesRequestSchema: z.ZodObject<{
|
|
39
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
40
|
+
scopes: z.ZodArray<z.ZodObject<{
|
|
41
|
+
scope: z.ZodString;
|
|
42
|
+
description: z.ZodString;
|
|
43
|
+
allow_dynamic_clients: z.ZodOptional<z.ZodBoolean>;
|
|
44
|
+
}, z.core.$strict>>;
|
|
45
|
+
}, z.core.$strict>;
|
|
46
|
+
export type SyncApiServerScopesRequest = z.infer<typeof syncApiServerScopesRequestSchema>;
|
|
47
|
+
export type SyncApiServerScopesRequestInput = z.input<typeof syncApiServerScopesRequestSchema>;
|
|
48
|
+
/**
|
|
49
|
+
* The entries of a manifest given either as a list or as the shorthand
|
|
50
|
+
* `{ [scope]: description }` (which keeps every scope's current
|
|
51
|
+
* `allow_dynamic_clients`). Not validated: parse the result with
|
|
52
|
+
* {@link syncApiServerScopesRequestSchema}.
|
|
53
|
+
*/
|
|
54
|
+
export declare function apiScopeManifestEntries(scopes: readonly ApiScopeManifestEntryInput[] | Readonly<Record<string, string>>): ApiScopeManifestEntryInput[];
|
|
55
|
+
/** A scope as the sync left it (created, or updated). */
|
|
56
|
+
export declare const syncedApiScopeSchema: z.ZodObject<{
|
|
57
|
+
scope: z.ZodString;
|
|
58
|
+
description: z.ZodString;
|
|
59
|
+
allow_dynamic_clients: z.ZodBoolean;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
export type SyncedApiScope = z.infer<typeof syncedApiScopeSchema>;
|
|
62
|
+
/** An updated scope, with the previous values of the fields that changed. */
|
|
63
|
+
export declare const updatedApiScopeSchema: z.ZodObject<{
|
|
64
|
+
scope: z.ZodString;
|
|
65
|
+
description: z.ZodString;
|
|
66
|
+
allow_dynamic_clients: z.ZodBoolean;
|
|
67
|
+
previous: z.ZodObject<{
|
|
68
|
+
description: z.ZodOptional<z.ZodString>;
|
|
69
|
+
allow_dynamic_clients: z.ZodOptional<z.ZodBoolean>;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
export type UpdatedApiScope = z.infer<typeof updatedApiScopeSchema>;
|
|
73
|
+
/** What a sync did (or, for a dry run, would do). */
|
|
74
|
+
export declare const apiServerScopeSyncResultSchema: z.ZodObject<{
|
|
75
|
+
api_server_id: z.ZodString;
|
|
76
|
+
dry_run: z.ZodBoolean;
|
|
77
|
+
created: z.ZodArray<z.ZodObject<{
|
|
78
|
+
scope: z.ZodString;
|
|
79
|
+
description: z.ZodString;
|
|
80
|
+
allow_dynamic_clients: z.ZodBoolean;
|
|
81
|
+
}, z.core.$strip>>;
|
|
82
|
+
updated: z.ZodArray<z.ZodObject<{
|
|
83
|
+
scope: z.ZodString;
|
|
84
|
+
description: z.ZodString;
|
|
85
|
+
allow_dynamic_clients: z.ZodBoolean;
|
|
86
|
+
previous: z.ZodObject<{
|
|
87
|
+
description: z.ZodOptional<z.ZodString>;
|
|
88
|
+
allow_dynamic_clients: z.ZodOptional<z.ZodBoolean>;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
}, z.core.$strip>>;
|
|
91
|
+
unchanged: z.ZodArray<z.ZodString>;
|
|
92
|
+
not_in_manifest: z.ZodArray<z.ZodObject<{
|
|
93
|
+
scope: z.ZodString;
|
|
94
|
+
description: z.ZodString;
|
|
95
|
+
}, z.core.$strip>>;
|
|
96
|
+
}, z.core.$strip>;
|
|
97
|
+
export type ApiServerScopeSyncResult = z.infer<typeof apiServerScopeSyncResultSchema>;
|
|
98
|
+
/** Success body of `PUT /api/resource-server/apis/{api_server_id}/scopes`. */
|
|
99
|
+
export declare const syncApiServerScopesResponseSchema: z.ZodObject<{
|
|
100
|
+
success: z.ZodLiteral<true>;
|
|
101
|
+
data: z.ZodObject<{
|
|
102
|
+
api_server_id: z.ZodString;
|
|
103
|
+
dry_run: z.ZodBoolean;
|
|
104
|
+
created: z.ZodArray<z.ZodObject<{
|
|
105
|
+
scope: z.ZodString;
|
|
106
|
+
description: z.ZodString;
|
|
107
|
+
allow_dynamic_clients: z.ZodBoolean;
|
|
108
|
+
}, z.core.$strip>>;
|
|
109
|
+
updated: z.ZodArray<z.ZodObject<{
|
|
110
|
+
scope: z.ZodString;
|
|
111
|
+
description: z.ZodString;
|
|
112
|
+
allow_dynamic_clients: z.ZodBoolean;
|
|
113
|
+
previous: z.ZodObject<{
|
|
114
|
+
description: z.ZodOptional<z.ZodString>;
|
|
115
|
+
allow_dynamic_clients: z.ZodOptional<z.ZodBoolean>;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
}, z.core.$strip>>;
|
|
118
|
+
unchanged: z.ZodArray<z.ZodString>;
|
|
119
|
+
not_in_manifest: z.ZodArray<z.ZodObject<{
|
|
120
|
+
scope: z.ZodString;
|
|
121
|
+
description: z.ZodString;
|
|
122
|
+
}, z.core.$strip>>;
|
|
123
|
+
}, z.core.$strip>;
|
|
124
|
+
}, z.core.$strip>;
|
|
125
|
+
export type SyncApiServerScopesResponse = z.infer<typeof syncApiServerScopesResponseSchema>;
|
|
126
|
+
/** Whether a sync created or updated anything (drift, for `--check`). */
|
|
127
|
+
export declare function hasApiScopeSyncDrift(result: ApiServerScopeSyncResult): boolean;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope sync: a resource server declares its whole list of API scopes in
|
|
3
|
+
* code (a "scope manifest") and sends it to
|
|
4
|
+
* `PUT /api/resource-server/apis/{api_server_id}/scopes`, authenticated
|
|
5
|
+
* with its JWKS access key. The auth server creates the scopes that are
|
|
6
|
+
* missing and updates the ones whose description (or, when the entry
|
|
7
|
+
* gives it, `allow_dynamic_clients`) changed. It never deletes a scope:
|
|
8
|
+
* deleting one drops users' consents and the per-app allowances set for
|
|
9
|
+
* it, so scopes missing from the list are only reported
|
|
10
|
+
* (`not_in_manifest`) and stay a decision for a person in the console.
|
|
11
|
+
*
|
|
12
|
+
* The request schema is also the source of the manifest JSON Schema the
|
|
13
|
+
* auth server serves at {@link API_SERVER_SCOPES_JSON_SCHEMA_PATH}, so
|
|
14
|
+
* editors, the SDK and the endpoint check the same rules.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import { apiServerIdSchema } from "@schemavaults/app-definitions";
|
|
18
|
+
import { API_SCOPE_VALUE_REGEX, MAX_API_SCOPES_PER_API_SERVER, MAX_API_SCOPE_DESCRIPTION_LENGTH, MAX_API_SCOPE_VALUE_LENGTH, apiScopeDescriptionSchema, apiScopeValueSchema, } from "./api-server-scope";
|
|
19
|
+
/**
|
|
20
|
+
* Path (on every auth server deployment) of the JSON Schema of scope
|
|
21
|
+
* manifests; a manifest names `<auth server URL><path>` in its `$schema`.
|
|
22
|
+
*/
|
|
23
|
+
export const API_SERVER_SCOPES_JSON_SCHEMA_PATH = "/json-schema/api-server-scopes.json";
|
|
24
|
+
/** One scope of a manifest. */
|
|
25
|
+
export const apiScopeManifestEntrySchema = z
|
|
26
|
+
.object({
|
|
27
|
+
scope: apiScopeValueSchema.meta({
|
|
28
|
+
title: "Scope",
|
|
29
|
+
description: "The OAuth 2.0 scope value: one RFC 6749 scope-token (printable ASCII without spaces, '\"' or '\\'), at most 128 characters, and never an OpenID Connect scope name. It cannot be renamed once defined.",
|
|
30
|
+
examples: ["notes:read", "notes:write"],
|
|
31
|
+
}),
|
|
32
|
+
description: apiScopeDescriptionSchema.meta({
|
|
33
|
+
title: "Description",
|
|
34
|
+
description: "What the scope allows, shown to users on the consent screen (1 to 256 characters after trimming). A changed description updates the scope on the next sync.",
|
|
35
|
+
examples: ["Read your notes."],
|
|
36
|
+
}),
|
|
37
|
+
allow_dynamic_clients: z
|
|
38
|
+
.boolean()
|
|
39
|
+
.optional()
|
|
40
|
+
.meta({
|
|
41
|
+
title: "Allow dynamically registered clients",
|
|
42
|
+
description: "Whether dynamically registered clients may be granted this scope. Omit it to keep the current value; a new scope defaults to true.",
|
|
43
|
+
examples: [true],
|
|
44
|
+
}),
|
|
45
|
+
})
|
|
46
|
+
.strict()
|
|
47
|
+
.meta({ title: "API scope" });
|
|
48
|
+
/**
|
|
49
|
+
* Body of `PUT /api/resource-server/apis/{api_server_id}/scopes`, and the
|
|
50
|
+
* shape of a scope manifest file: the API server's whole scope list, at
|
|
51
|
+
* most {@link MAX_API_SCOPES_PER_API_SERVER} entries with no scope value
|
|
52
|
+
* repeated, plus an optional `$schema` the endpoint ignores (so a manifest
|
|
53
|
+
* file is sent as it is).
|
|
54
|
+
*/
|
|
55
|
+
export const syncApiServerScopesRequestSchema = z
|
|
56
|
+
.object({
|
|
57
|
+
$schema: z
|
|
58
|
+
.string()
|
|
59
|
+
.optional()
|
|
60
|
+
.meta({
|
|
61
|
+
description: "URL of this JSON Schema, for editor auto-complete and checks. Ignored by the auth server.",
|
|
62
|
+
}),
|
|
63
|
+
scopes: z
|
|
64
|
+
.array(apiScopeManifestEntrySchema)
|
|
65
|
+
.max(MAX_API_SCOPES_PER_API_SERVER)
|
|
66
|
+
.superRefine((entries, ctx) => {
|
|
67
|
+
const seen = new Set();
|
|
68
|
+
entries.forEach((entry, index) => {
|
|
69
|
+
if (seen.has(entry.scope)) {
|
|
70
|
+
ctx.addIssue({
|
|
71
|
+
code: "custom",
|
|
72
|
+
path: [index, "scope"],
|
|
73
|
+
message: `The scope '${entry.scope}' is listed more than once`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
seen.add(entry.scope);
|
|
77
|
+
});
|
|
78
|
+
})
|
|
79
|
+
.meta({
|
|
80
|
+
title: "Scopes",
|
|
81
|
+
description: `Every scope the API server defines (at most ${MAX_API_SCOPES_PER_API_SERVER}, each value listed once). Missing scopes are created and changed ones updated; scopes the auth server knows but the list leaves out are reported and never deleted.`,
|
|
82
|
+
}),
|
|
83
|
+
})
|
|
84
|
+
.strict()
|
|
85
|
+
.meta({
|
|
86
|
+
title: "API server scope manifest",
|
|
87
|
+
description: "The API scopes a resource server defines, synced to the auth server with `auth-server-sdk sync-scopes` or `syncApiServerScopes()` from `@schemavaults/auth-server-sdk/api-scopes` (PUT /api/resource-server/apis/{api_server_id}/scopes).",
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* The entries of a manifest given either as a list or as the shorthand
|
|
91
|
+
* `{ [scope]: description }` (which keeps every scope's current
|
|
92
|
+
* `allow_dynamic_clients`). Not validated: parse the result with
|
|
93
|
+
* {@link syncApiServerScopesRequestSchema}.
|
|
94
|
+
*/
|
|
95
|
+
export function apiScopeManifestEntries(scopes) {
|
|
96
|
+
if (Array.isArray(scopes)) {
|
|
97
|
+
return [...scopes];
|
|
98
|
+
}
|
|
99
|
+
return Object.entries(scopes).map(([scope, description]) => ({ scope, description }));
|
|
100
|
+
}
|
|
101
|
+
// Format only (no reserved-name check), like apiServerScopeSchema, so the
|
|
102
|
+
// stored definitions always parse on the way out.
|
|
103
|
+
const syncedScopeValueSchema = z
|
|
104
|
+
.string()
|
|
105
|
+
.min(1)
|
|
106
|
+
.max(MAX_API_SCOPE_VALUE_LENGTH)
|
|
107
|
+
.regex(API_SCOPE_VALUE_REGEX);
|
|
108
|
+
const syncedScopeDescriptionSchema = z
|
|
109
|
+
.string()
|
|
110
|
+
.max(MAX_API_SCOPE_DESCRIPTION_LENGTH);
|
|
111
|
+
/** A scope as the sync left it (created, or updated). */
|
|
112
|
+
export const syncedApiScopeSchema = z.object({
|
|
113
|
+
scope: syncedScopeValueSchema,
|
|
114
|
+
description: syncedScopeDescriptionSchema,
|
|
115
|
+
allow_dynamic_clients: z.boolean(),
|
|
116
|
+
});
|
|
117
|
+
/** An updated scope, with the previous values of the fields that changed. */
|
|
118
|
+
export const updatedApiScopeSchema = syncedApiScopeSchema.extend({
|
|
119
|
+
previous: z.object({
|
|
120
|
+
description: syncedScopeDescriptionSchema.optional(),
|
|
121
|
+
allow_dynamic_clients: z.boolean().optional(),
|
|
122
|
+
}),
|
|
123
|
+
});
|
|
124
|
+
/** What a sync did (or, for a dry run, would do). */
|
|
125
|
+
export const apiServerScopeSyncResultSchema = z.object({
|
|
126
|
+
api_server_id: apiServerIdSchema,
|
|
127
|
+
dry_run: z.boolean(),
|
|
128
|
+
/** Scopes that were missing, in manifest order. */
|
|
129
|
+
created: z.array(syncedApiScopeSchema),
|
|
130
|
+
/** Scopes whose description or `allow_dynamic_clients` changed, in manifest order. */
|
|
131
|
+
updated: z.array(updatedApiScopeSchema),
|
|
132
|
+
/** Values of the listed scopes that already matched, in manifest order. */
|
|
133
|
+
unchanged: z.array(syncedScopeValueSchema),
|
|
134
|
+
/** Scopes the API server defines that the manifest leaves out (kept), oldest first. */
|
|
135
|
+
not_in_manifest: z.array(z.object({
|
|
136
|
+
scope: syncedScopeValueSchema,
|
|
137
|
+
description: syncedScopeDescriptionSchema,
|
|
138
|
+
})),
|
|
139
|
+
});
|
|
140
|
+
/** Success body of `PUT /api/resource-server/apis/{api_server_id}/scopes`. */
|
|
141
|
+
export const syncApiServerScopesResponseSchema = z.object({
|
|
142
|
+
success: z.literal(true),
|
|
143
|
+
data: apiServerScopeSyncResultSchema,
|
|
144
|
+
});
|
|
145
|
+
/** Whether a sync created or updated anything (drift, for `--check`). */
|
|
146
|
+
export function hasApiScopeSyncDrift(result) {
|
|
147
|
+
return result.created.length > 0 || result.updated.length > 0;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=scope-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-sync.js","sourceRoot":"","sources":["../../src/api-scopes/scope-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,gCAAgC,EAChC,0BAA0B,EAC1B,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAE5B;;;GAGG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAC7C,qCAA8C,CAAC;AAEjD,+BAA+B;AAC/B,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC;KACzC,MAAM,CAAC;IACN,KAAK,EAAE,mBAAmB,CAAC,IAAI,CAAC;QAC9B,KAAK,EAAE,OAAO;QACd,WAAW,EACT,wMAAwM;QAC1M,QAAQ,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC;KACxC,CAAC;IACF,WAAW,EAAE,yBAAyB,CAAC,IAAI,CAAC;QAC1C,KAAK,EAAE,aA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AAC;AAIH,qDAAqD;AACrD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC,MAAM,CAAC;IACrD,aAAa,EAAE,iBAAiB;IAChC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,mDAAmD;IACnD,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC;IACtC,sFAAsF;IACtF,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC;IACvC,2EAA2E;IAC3E,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC;IAC1C,uFAAuF;IACvF,eAAe,EAAE,CAAC,CAAC,KAAK,CACtB,CAAC,CAAC,MAAM,CAAC;QACP,KAAK,EAAE,sBAAsB;QAC7B,WAAW,EAAE,4BAA4B;KAC1C,CAAC,CACH;CACF,CAAC,CAAC;AAIH,8EAA8E;AAC9E,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,CAAC,MAAM,CAAC;IACxD,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IACxB,IAAI,EAAE,8BAA8B;CACrC,CAAC,CAAC;AAIH,yEAAyE;AACzE,MAAM,UAAU,oBAAoB,CAAC,MAAgC;IACnE,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export * from "./pkce";
|
|
|
13
13
|
export type * from "./pkce";
|
|
14
14
|
export * from "./oidc";
|
|
15
15
|
export type * from "./oidc";
|
|
16
|
+
export * from "./api-scopes";
|
|
17
|
+
export type * from "./api-scopes";
|
|
16
18
|
export { sha256_base64url } from "./sha256_digest";
|
|
17
19
|
export { authenticateResultSchema, authenticatedAuthenticateResultSchema, mfaRequiredAuthenticateResultSchema, authenticateFailureResultSchema, challengeExpiredAuthenticateResultSchema, emailVerificationRequiredAuthenticateResultSchema, availableMfaFactorSchema, collapseWebauthnFactors, type AuthenticateResult, type AuthenticatedAuthenticateResult, type MfaRequiredAuthenticateResult, type AuthenticateFailureResult, type ChallengeExpiredAuthenticateResult, type EmailVerificationRequiredAuthenticateResult, type AvailableMfaFactor, } from "./authenticate_result";
|
|
18
20
|
export * from "./mfa";
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./token-data";
|
|
|
7
7
|
export * from "./middleware";
|
|
8
8
|
export * from "./pkce";
|
|
9
9
|
export * from "./oidc";
|
|
10
|
+
export * from "./api-scopes";
|
|
10
11
|
export { sha256_base64url } from "./sha256_digest";
|
|
11
12
|
export { authenticateResultSchema, authenticatedAuthenticateResultSchema, mfaRequiredAuthenticateResultSchema, authenticateFailureResultSchema, challengeExpiredAuthenticateResultSchema, emailVerificationRequiredAuthenticateResultSchema, availableMfaFactorSchema, collapseWebauthnFactors, } from "./authenticate_result";
|
|
12
13
|
export * from "./mfa";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,cAAc,GACf,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,mCAAmC,EACnC,qCAAqC,GACtC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EAIvB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,GAK1B,MAAM,aAAa,CAAC;AAErB,cAAc,eAAe,CAAC;AAG9B,mBAAmB;AACnB,cAAc,cAAc,CAAC;AAM7B,cAAc,cAAc,CAAC;AAG7B,cAAc,QAAQ,CAAC;AAGvB,cAAc,QAAQ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EAAE,MAAM,4CAA4C,CAAC;AAEtG,OAAO,EAAE,kCAAkC,EAAE,MAAM,0CAA0C,CAAC;AAE9F,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EACL,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAE/C,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC"}
|
package/dist/oidc/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
|
|
2
|
-
export type { OidcSupportedScope, OidcScope, ParsedOidcScopes, } from "./scope";
|
|
1
|
+
export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, grantRequestedScopes, partitionGrantedScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
|
|
2
|
+
export type { OidcSupportedScope, OidcScope, ParsedOidcScopes, GrantedScopes, } from "./scope";
|
|
3
3
|
export { oidcNonceSchema, OIDC_NONCE_VSCHAR_REGEX, parseOidcNonce, OidcNonceValidationError, } from "./nonce";
|
|
4
4
|
export type { OidcNonce } from "./nonce";
|
|
5
5
|
export { OIDC_SUB_CLAIM_DELIMITER, formatOidcSubClaim, parseOidcSubClaim, } from "./sub-claim";
|
package/dist/oidc/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
|
|
1
|
+
export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, grantRequestedScopes, partitionGrantedScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
|
|
2
2
|
export { oidcNonceSchema, OIDC_NONCE_VSCHAR_REGEX, parseOidcNonce, OidcNonceValidationError, } from "./nonce";
|
|
3
3
|
export { OIDC_SUB_CLAIM_DELIMITER, formatOidcSubClaim, parseOidcSubClaim, } from "./sub-claim";
|
|
4
4
|
export { buildOidcProfileClaims } from "./profile-claims";
|
package/dist/oidc/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AAQjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,sCAAsC,EAAE,MAAM,oBAAoB,CAAC;AAG5E,OAAO,EACL,yBAAyB,EACzB,uCAAuC,EACvC,iCAAiC,EACjC,kCAAkC,EAClC,wCAAwC,EACxC,yCAAyC,EACzC,iCAAiC,GAClC,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAMhE,OAAO,EACL,kCAAkC,EAClC,gCAAgC,EAChC,0CAA0C,EAC1C,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,EACrC,gCAAgC,EAChC,sCAAsC,GACvC,MAAM,+BAA+B,CAAC"}
|
package/dist/oidc/scope.d.ts
CHANGED
|
@@ -17,10 +17,25 @@
|
|
|
17
17
|
* granted set is echoed back in the token response, so RPs that
|
|
18
18
|
* hardcode e.g. "openid profile email address" still interoperate, and
|
|
19
19
|
* a request naming only unknown scopes degrades to a plain OAuth grant).
|
|
20
|
+
*
|
|
21
|
+
* API scopes: an API server (resource server) may define its own scope
|
|
22
|
+
* values (e.g. `notes:read`, see `api-scopes/`). They are granted only
|
|
23
|
+
* when the authorization request names that API server as its RFC 8707
|
|
24
|
+
* `resource` (`grantRequestedScopes`); without a resource they are
|
|
25
|
+
* unknown scopes and dropped exactly as before.
|
|
20
26
|
*/
|
|
21
27
|
import { z } from "zod";
|
|
22
28
|
export declare const OIDC_OPENID_SCOPE: "openid";
|
|
23
29
|
export declare const OIDC_SUPPORTED_SCOPES: readonly ["openid", "email", "profile"];
|
|
30
|
+
/**
|
|
31
|
+
* The scope values OpenID Connect Core §5.4 / §11 standardize. No API
|
|
32
|
+
* server may define one of them as an API scope (even those this server
|
|
33
|
+
* does not support yet), so a granted scope string always splits
|
|
34
|
+
* unambiguously into its OIDC part and its API part
|
|
35
|
+
* (`partitionGrantedScopes`).
|
|
36
|
+
*/
|
|
37
|
+
export declare const OIDC_RESERVED_SCOPES: readonly ["openid", "profile", "email", "address", "phone", "offline_access"];
|
|
38
|
+
export declare function isOidcReservedScope(scope: string): boolean;
|
|
24
39
|
/**
|
|
25
40
|
* Scope requested by default when a flow does not name one explicitly:
|
|
26
41
|
* the SDK's `authenticateWithRedirect`/`sendAuthenticateRequest`
|
|
@@ -71,6 +86,39 @@ export interface ParsedOidcScopes {
|
|
|
71
86
|
* malformed value from an absent one check `oidcScopeSchema` first.
|
|
72
87
|
*/
|
|
73
88
|
export declare function parseAndGrantScopes(raw: unknown): ParsedOidcScopes;
|
|
89
|
+
export interface GrantedScopes {
|
|
90
|
+
/**
|
|
91
|
+
* Every granted scope (OIDC and API scopes), deduplicated, in request
|
|
92
|
+
* order.
|
|
93
|
+
*/
|
|
94
|
+
granted: string[];
|
|
95
|
+
/** The OIDC scopes among `granted` (see `parseAndGrantScopes`). */
|
|
96
|
+
oidc: OidcSupportedScope[];
|
|
97
|
+
/** The API scopes among `granted`. */
|
|
98
|
+
api: string[];
|
|
99
|
+
/** Whether `granted` includes `openid`. */
|
|
100
|
+
hasOpenid: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Like `parseAndGrantScopes`, but also grants the requested scopes that
|
|
104
|
+
* `api_scopes` lists: the scope values defined by the API server the
|
|
105
|
+
* grant's RFC 8707 `resource` resolved to. Every other scope is still
|
|
106
|
+
* dropped (RFC 6749 §3.3), and so is any OIDC reserved name in
|
|
107
|
+
* `api_scopes`. With no `api_scopes` the result grants exactly what
|
|
108
|
+
* `parseAndGrantScopes` grants.
|
|
109
|
+
*/
|
|
110
|
+
export declare function grantRequestedScopes(raw: unknown, api_scopes?: Iterable<string>): GrantedScopes;
|
|
111
|
+
/**
|
|
112
|
+
* Splits a granted scope string (an authorization code row, a token's
|
|
113
|
+
* `scope` claim) into its OIDC scopes and its API scopes. Only granted
|
|
114
|
+
* sets are stored, and API scopes can never take an OIDC reserved name,
|
|
115
|
+
* so every token that is not a supported OIDC scope is an API scope.
|
|
116
|
+
* Null / empty is the empty grant (a plain OAuth 2.1 grant).
|
|
117
|
+
*/
|
|
118
|
+
export declare function partitionGrantedScopes(scope: string | null | undefined): {
|
|
119
|
+
oidc: OidcSupportedScope[];
|
|
120
|
+
api: string[];
|
|
121
|
+
};
|
|
74
122
|
/**
|
|
75
123
|
* Serializes granted scopes back to the space-delimited wire format for
|
|
76
124
|
* the token response `scope` field and the AUTHORIZATION_CODES row.
|
package/dist/oidc/scope.js
CHANGED
|
@@ -17,10 +17,34 @@
|
|
|
17
17
|
* granted set is echoed back in the token response, so RPs that
|
|
18
18
|
* hardcode e.g. "openid profile email address" still interoperate, and
|
|
19
19
|
* a request naming only unknown scopes degrades to a plain OAuth grant).
|
|
20
|
+
*
|
|
21
|
+
* API scopes: an API server (resource server) may define its own scope
|
|
22
|
+
* values (e.g. `notes:read`, see `api-scopes/`). They are granted only
|
|
23
|
+
* when the authorization request names that API server as its RFC 8707
|
|
24
|
+
* `resource` (`grantRequestedScopes`); without a resource they are
|
|
25
|
+
* unknown scopes and dropped exactly as before.
|
|
20
26
|
*/
|
|
21
27
|
import { z } from "zod";
|
|
22
28
|
export const OIDC_OPENID_SCOPE = "openid";
|
|
23
29
|
export const OIDC_SUPPORTED_SCOPES = ["openid", "email", "profile"];
|
|
30
|
+
/**
|
|
31
|
+
* The scope values OpenID Connect Core §5.4 / §11 standardize. No API
|
|
32
|
+
* server may define one of them as an API scope (even those this server
|
|
33
|
+
* does not support yet), so a granted scope string always splits
|
|
34
|
+
* unambiguously into its OIDC part and its API part
|
|
35
|
+
* (`partitionGrantedScopes`).
|
|
36
|
+
*/
|
|
37
|
+
export const OIDC_RESERVED_SCOPES = [
|
|
38
|
+
"openid",
|
|
39
|
+
"profile",
|
|
40
|
+
"email",
|
|
41
|
+
"address",
|
|
42
|
+
"phone",
|
|
43
|
+
"offline_access",
|
|
44
|
+
];
|
|
45
|
+
export function isOidcReservedScope(scope) {
|
|
46
|
+
return OIDC_RESERVED_SCOPES.includes(scope);
|
|
47
|
+
}
|
|
24
48
|
/**
|
|
25
49
|
* Scope requested by default when a flow does not name one explicitly:
|
|
26
50
|
* the SDK's `authenticateWithRedirect`/`sendAuthenticateRequest`
|
|
@@ -85,6 +109,68 @@ export function parseAndGrantScopes(raw) {
|
|
|
85
109
|
}
|
|
86
110
|
return { granted, hasOpenid: granted.includes(OIDC_OPENID_SCOPE) };
|
|
87
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Like `parseAndGrantScopes`, but also grants the requested scopes that
|
|
114
|
+
* `api_scopes` lists: the scope values defined by the API server the
|
|
115
|
+
* grant's RFC 8707 `resource` resolved to. Every other scope is still
|
|
116
|
+
* dropped (RFC 6749 §3.3), and so is any OIDC reserved name in
|
|
117
|
+
* `api_scopes`. With no `api_scopes` the result grants exactly what
|
|
118
|
+
* `parseAndGrantScopes` grants.
|
|
119
|
+
*/
|
|
120
|
+
export function grantRequestedScopes(raw, api_scopes = []) {
|
|
121
|
+
const { granted: oidc, hasOpenid } = parseAndGrantScopes(raw);
|
|
122
|
+
const grantable_api_scopes = new Set();
|
|
123
|
+
for (const scope of api_scopes) {
|
|
124
|
+
if (typeof scope === "string" && !isOidcReservedScope(scope)) {
|
|
125
|
+
grantable_api_scopes.add(scope);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (grantable_api_scopes.size === 0 ||
|
|
129
|
+
typeof raw !== "string" ||
|
|
130
|
+
!oidcScopeSchema.safeParse(raw).success) {
|
|
131
|
+
return { granted: [...oidc], oidc, api: [], hasOpenid };
|
|
132
|
+
}
|
|
133
|
+
const granted = [];
|
|
134
|
+
const api = [];
|
|
135
|
+
for (const token of raw.split(" ")) {
|
|
136
|
+
if (!token || granted.includes(token))
|
|
137
|
+
continue;
|
|
138
|
+
if (oidc.includes(token)) {
|
|
139
|
+
granted.push(token);
|
|
140
|
+
}
|
|
141
|
+
else if (grantable_api_scopes.has(token)) {
|
|
142
|
+
granted.push(token);
|
|
143
|
+
api.push(token);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return { granted, oidc, api, hasOpenid };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Splits a granted scope string (an authorization code row, a token's
|
|
150
|
+
* `scope` claim) into its OIDC scopes and its API scopes. Only granted
|
|
151
|
+
* sets are stored, and API scopes can never take an OIDC reserved name,
|
|
152
|
+
* so every token that is not a supported OIDC scope is an API scope.
|
|
153
|
+
* Null / empty is the empty grant (a plain OAuth 2.1 grant).
|
|
154
|
+
*/
|
|
155
|
+
export function partitionGrantedScopes(scope) {
|
|
156
|
+
const oidc = [];
|
|
157
|
+
const api = [];
|
|
158
|
+
if (typeof scope !== "string") {
|
|
159
|
+
return { oidc, api };
|
|
160
|
+
}
|
|
161
|
+
for (const token of scope.split(" ")) {
|
|
162
|
+
if (!token)
|
|
163
|
+
continue;
|
|
164
|
+
if (isSupportedOidcScope(token)) {
|
|
165
|
+
if (!oidc.includes(token))
|
|
166
|
+
oidc.push(token);
|
|
167
|
+
}
|
|
168
|
+
else if (!isOidcReservedScope(token) && !api.includes(token)) {
|
|
169
|
+
api.push(token);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { oidc, api };
|
|
173
|
+
}
|
|
88
174
|
/**
|
|
89
175
|
* Serializes granted scopes back to the space-delimited wire format for
|
|
90
176
|
* the token response `scope` field and the AUTHORIZATION_CODES row.
|
package/dist/oidc/scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/oidc/scope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/oidc/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAiB,CAAC;AAEnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,OAAO;IACP,gBAAgB;CACR,CAAC;AAEX,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAQ,oBAA0C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,sBAA+B,CAAC;AAElE,MAAM,qBAAqB,GAAG,GAAY,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,4DAA4D,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,qBAAqB,CAAC;KAC1B,KAAK,CAAC,gBAAgB,EAAE;IACvB,OAAO,EACL,sEAAsE;CACzE,CAAC,CAAC;AAoBL,SAAS,oBAAoB,CAAC,KAAa;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,SAAS,CAAC,4CAA4C,C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