@crombolo/entra 0.36.2 → 0.37.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/package.json +3 -2
- package/src/index.ts +83 -68
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/entra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Edit a Microsoft Entra sign-in from the Crombolo backoffice: tenant, app credentials and group mappings, over the provider the site declares in code.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"id": "entra",
|
|
41
41
|
"name": "Microsoft Entra",
|
|
42
42
|
"server": "entraSettings",
|
|
43
|
+
"schemaVersion": 2,
|
|
43
44
|
"extensions": [
|
|
44
45
|
{
|
|
45
46
|
"type": "menuItem",
|
|
@@ -67,6 +68,6 @@
|
|
|
67
68
|
]
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
|
-
"@crombolo/crombolo": ">=0.
|
|
71
|
+
"@crombolo/crombolo": ">=0.37.0"
|
|
71
72
|
}
|
|
72
73
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
* Reading is for anyone with the Settings section. Changing is for
|
|
9
9
|
* administrators only, because a group mapping can make someone an administrator.
|
|
10
10
|
*/
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
BundleSection,
|
|
14
|
-
ProviderOverrideInput,
|
|
15
|
-
|
|
11
|
+
import {
|
|
12
|
+
type BundleRouteContext,
|
|
13
|
+
type BundleSection,
|
|
14
|
+
type ProviderOverrideInput,
|
|
15
|
+
type RouteContext,
|
|
16
|
+
route,
|
|
17
|
+
type ServerBundle,
|
|
16
18
|
} from '@crombolo/crombolo/bundle'
|
|
17
19
|
import manifest from '../package.json' with { type: 'json' }
|
|
18
20
|
|
|
@@ -71,13 +73,13 @@ const parseBody = async (request: Request): Promise<Record<string, unknown>> =>
|
|
|
71
73
|
return body && typeof body === 'object' ? (body as Record<string, unknown>) : {}
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
type Context =
|
|
76
|
+
type Context = RouteContext & BundleRouteContext<Capability>
|
|
75
77
|
|
|
76
78
|
/** The provider a route names, when it is an Entra one the config declares. */
|
|
77
79
|
async function entraProvider(context: Context) {
|
|
78
80
|
const { audience, id } = context.params
|
|
79
81
|
if (!audience || !AUDIENCES.has(audience)) return undefined
|
|
80
|
-
const all = await context.
|
|
82
|
+
const all = await context.bundle.identityProviders.list()
|
|
81
83
|
return all.find((p) => p.kind === 'entra' && p.audience === audience && p.id === id)
|
|
82
84
|
}
|
|
83
85
|
|
|
@@ -90,72 +92,85 @@ export function entraSettings(options: EntraSettingsOptions = {}): ServerBundle<
|
|
|
90
92
|
id: ENTRA_BUNDLE_ID,
|
|
91
93
|
section: options.section ?? 'settings',
|
|
92
94
|
capabilities: CAPABILITIES,
|
|
95
|
+
// Back-office routes (story 211), behind the user and the section.
|
|
93
96
|
routes: [
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
route<unknown, unknown, BundleRouteContext<Capability>>(
|
|
98
|
+
'providers',
|
|
99
|
+
{
|
|
100
|
+
async GET(_request, { bundle, principal }) {
|
|
101
|
+
const providers = (await bundle.identityProviders.list()).filter(
|
|
102
|
+
(p) => p.kind === 'entra',
|
|
103
|
+
)
|
|
104
|
+
return json({ canEdit: principal?.isAdmin === true, providers })
|
|
105
|
+
},
|
|
100
106
|
},
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
{ audience: 'backoffice' },
|
|
108
|
+
),
|
|
109
|
+
route<unknown, unknown, BundleRouteContext<Capability>>(
|
|
110
|
+
'groups/:audience',
|
|
111
|
+
{
|
|
112
|
+
async GET(_request, { bundle, params }) {
|
|
113
|
+
if (!params.audience || !AUDIENCES.has(params.audience))
|
|
114
|
+
return json({ ok: false, message: 'Groups are for members or users.' }, 404)
|
|
115
|
+
return json({
|
|
116
|
+
groups: await bundle.identityProviders.groups(params.audience as 'member' | 'user'),
|
|
117
|
+
})
|
|
118
|
+
},
|
|
111
119
|
},
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
audience
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
120
|
+
{ audience: 'backoffice' },
|
|
121
|
+
),
|
|
122
|
+
route<unknown, unknown, BundleRouteContext<Capability>>(
|
|
123
|
+
'providers/:audience/:id',
|
|
124
|
+
{
|
|
125
|
+
async PUT(request, context) {
|
|
126
|
+
if (!context.principal?.isAdmin) return adminOnly()
|
|
127
|
+
const provider = await entraProvider(context as Context)
|
|
128
|
+
if (!provider)
|
|
129
|
+
return json({ ok: false, message: 'There is no such Entra sign-in.' }, 404)
|
|
130
|
+
const outcome = await context.bundle.identityProviders.update(
|
|
131
|
+
provider.audience,
|
|
132
|
+
provider.id,
|
|
133
|
+
readOverrides(await parseBody(request)),
|
|
134
|
+
)
|
|
135
|
+
if (!outcome.ok) return json({ ok: false, message: outcome.error }, 400)
|
|
136
|
+
context.bundle.log.info('{user} changed the {audience} Entra sign-in {id}', {
|
|
137
|
+
user: context.principal.email,
|
|
138
|
+
audience: provider.audience,
|
|
139
|
+
id: provider.id,
|
|
140
|
+
})
|
|
141
|
+
return json({ ok: true, provider: await entraProvider(context as Context) })
|
|
142
|
+
},
|
|
143
|
+
async DELETE(_request, context) {
|
|
144
|
+
if (!context.principal?.isAdmin) return adminOnly()
|
|
145
|
+
const provider = await entraProvider(context as Context)
|
|
146
|
+
if (!provider)
|
|
147
|
+
return json({ ok: false, message: 'There is no such Entra sign-in.' }, 404)
|
|
148
|
+
await context.bundle.identityProviders.reset(provider.audience, provider.id)
|
|
149
|
+
context.bundle.log.info(
|
|
150
|
+
'{user} put the {audience} Entra sign-in {id} back to the code',
|
|
151
|
+
{
|
|
152
|
+
user: context.principal.email,
|
|
153
|
+
audience: provider.audience,
|
|
154
|
+
id: provider.id,
|
|
155
|
+
},
|
|
156
|
+
)
|
|
157
|
+
return json({ ok: true, provider: await entraProvider(context as Context) })
|
|
158
|
+
},
|
|
132
159
|
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
audience: provider.audience,
|
|
145
|
-
id: provider.id,
|
|
146
|
-
})
|
|
147
|
-
return json({ ok: true, provider: await entraProvider(context) })
|
|
160
|
+
{ audience: 'backoffice' },
|
|
161
|
+
),
|
|
162
|
+
route<unknown, unknown, BundleRouteContext<Capability>>(
|
|
163
|
+
'providers/:audience/:id/test',
|
|
164
|
+
{
|
|
165
|
+
async POST(_request, context) {
|
|
166
|
+
const provider = await entraProvider(context as Context)
|
|
167
|
+
if (!provider)
|
|
168
|
+
return json({ ok: false, message: 'There is no such Entra sign-in.' }, 404)
|
|
169
|
+
return json(await context.bundle.identityProviders.test(provider.audience, provider.id))
|
|
170
|
+
},
|
|
148
171
|
},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
method: 'POST',
|
|
152
|
-
path: 'providers/:audience/:id/test',
|
|
153
|
-
async handler(context) {
|
|
154
|
-
const provider = await entraProvider(context)
|
|
155
|
-
if (!provider) return json({ ok: false, message: 'There is no such Entra sign-in.' }, 404)
|
|
156
|
-
return json(await context.host.identityProviders.test(provider.audience, provider.id))
|
|
157
|
-
},
|
|
158
|
-
},
|
|
172
|
+
{ audience: 'backoffice' },
|
|
173
|
+
),
|
|
159
174
|
],
|
|
160
175
|
}
|
|
161
176
|
}
|