@owlmeans/client-iam 0.1.18-rc.57 → 0.1.18-rc.59
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/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/organization.d.ts +21 -0
- package/build/organization.d.ts.map +1 -0
- package/build/organization.js +24 -0
- package/build/organization.js.map +1 -0
- package/package.json +7 -7
- package/src/index.ts +3 -0
- package/src/organization.ts +29 -0
- package/tests/organization.spec.ts +85 -0
- package/tests/tsconfig.json +12 -0
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export type * from '@owlmeans/iam';
|
|
2
2
|
export { hasPermission } from '@owlmeans/iam';
|
|
3
|
+
export { ORGANIZATION_REFUSAL, ORGANIZATION_OWNER_REFUSAL } from '@owlmeans/oidc';
|
|
4
|
+
export type { OidcOrganizationItem } from '@owlmeans/oidc';
|
|
3
5
|
export * from './consts.js';
|
|
4
6
|
export * from './append.js';
|
|
5
7
|
export * from './consent.js';
|
|
6
8
|
export * from './login.js';
|
|
9
|
+
export * from './organization.js';
|
|
7
10
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,eAAe,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,eAAe,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AACjF,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAC1D,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { hasPermission } from '@owlmeans/iam';
|
|
2
|
+
export { ORGANIZATION_REFUSAL, ORGANIZATION_OWNER_REFUSAL } from '@owlmeans/oidc';
|
|
2
3
|
export * from './consts.js';
|
|
3
4
|
export * from './append.js';
|
|
4
5
|
export * from './consent.js';
|
|
5
6
|
export * from './login.js';
|
|
7
|
+
export * from './organization.js';
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAEjF,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BasicContext } from '@owlmeans/context';
|
|
2
|
+
import type { OidcOrganizationItem } from '@owlmeans/oidc';
|
|
3
|
+
/**
|
|
4
|
+
* The organizations of the signed-in subject, the one the session acts in marked `acting`.
|
|
5
|
+
*
|
|
6
|
+
* Answered by the application's own server from the session it holds — refreshed against the
|
|
7
|
+
* provider by the guard first — so a person just removed from an organization no longer sees it.
|
|
8
|
+
* A session of a client without the organizations scope has none. Needs the bindings of
|
|
9
|
+
* `iamEntrypoints()`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const listOrganizations: (ctx: BasicContext<any>) => Promise<OidcOrganizationItem[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Moves the session into another organization of its subject and adopts the re-signed token, so
|
|
14
|
+
* every request after it — and every screen reading `auth` — acts in that organization.
|
|
15
|
+
*
|
|
16
|
+
* There is no per-request organization selector: the session, not the request, decides where a
|
|
17
|
+
* request acts. An organization the subject is not in is refused (`ORGANIZATION_REFUSAL`) and the
|
|
18
|
+
* current token stays.
|
|
19
|
+
*/
|
|
20
|
+
export declare const switchOrganization: (ctx: BasicContext<any>, entitySlug: string) => Promise<void>;
|
|
21
|
+
//# sourceMappingURL=organization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organization.d.ts","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAG1D;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,QAAe,YAAY,CAAC,GAAG,CAAC,KAAG,OAAO,CAAC,oBAAoB,EAAE,CAC7B,CAAA;AAElE;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAAe,YAAY,CAAC,GAAG,CAAC,cAAc,MAAM,KAAG,OAAO,CAAC,IAAI,CAIjG,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { oidcProtocols } from '@owlmeans/oidc';
|
|
2
|
+
import { adoptToken } from '@owlmeans/client-auth/login';
|
|
3
|
+
/**
|
|
4
|
+
* The organizations of the signed-in subject, the one the session acts in marked `acting`.
|
|
5
|
+
*
|
|
6
|
+
* Answered by the application's own server from the session it holds — refreshed against the
|
|
7
|
+
* provider by the guard first — so a person just removed from an organization no longer sees it.
|
|
8
|
+
* A session of a client without the organizations scope has none. Needs the bindings of
|
|
9
|
+
* `iamEntrypoints()`.
|
|
10
|
+
*/
|
|
11
|
+
export const listOrganizations = async (ctx) => (await ctx.entrypoint(oidcProtocols.organizations).call()).items;
|
|
12
|
+
/**
|
|
13
|
+
* Moves the session into another organization of its subject and adopts the re-signed token, so
|
|
14
|
+
* every request after it — and every screen reading `auth` — acts in that organization.
|
|
15
|
+
*
|
|
16
|
+
* There is no per-request organization selector: the session, not the request, decides where a
|
|
17
|
+
* request acts. An organization the subject is not in is refused (`ORGANIZATION_REFUSAL`) and the
|
|
18
|
+
* current token stays.
|
|
19
|
+
*/
|
|
20
|
+
export const switchOrganization = async (ctx, entitySlug) => {
|
|
21
|
+
const { token } = await ctx.entrypoint(oidcProtocols.organization).call({ body: { entitySlug } });
|
|
22
|
+
await adoptToken(ctx, token);
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=organization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organization.js","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,GAAsB,EAAmC,EAAE,CACjG,CAAC,MAAM,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAA;AAElE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,GAAsB,EAAE,UAAkB,EAAiB,EAAE;IACpG,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,CAAA;IAEjG,MAAM,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAC9B,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/client-iam",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.59",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@owlmeans/client-auth": "^0.1.18-rc.
|
|
25
|
+
"@owlmeans/client-auth": "^0.1.18-rc.54",
|
|
26
26
|
"@owlmeans/consent": "^0.1.18-rc.9",
|
|
27
27
|
"@owlmeans/context": "^0.1.18-rc.32",
|
|
28
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
29
|
-
"@owlmeans/iam": "^0.1.18-rc.
|
|
30
|
-
"@owlmeans/oidc": "^0.1.18-rc.
|
|
31
|
-
"@owlmeans/web-client": "^0.1.18-rc.
|
|
32
|
-
"@owlmeans/web-oidc-rp": "^0.1.18-rc.
|
|
28
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.38",
|
|
29
|
+
"@owlmeans/iam": "^0.1.18-rc.46",
|
|
30
|
+
"@owlmeans/oidc": "^0.1.18-rc.51",
|
|
31
|
+
"@owlmeans/web-client": "^0.1.18-rc.57",
|
|
32
|
+
"@owlmeans/web-oidc-rp": "^0.1.18-rc.60"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@owlmeans/dep-config": "workspace:*",
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export type * from '@owlmeans/iam'
|
|
2
2
|
export { hasPermission } from '@owlmeans/iam'
|
|
3
|
+
export { ORGANIZATION_REFUSAL, ORGANIZATION_OWNER_REFUSAL } from '@owlmeans/oidc'
|
|
4
|
+
export type { OidcOrganizationItem } from '@owlmeans/oidc'
|
|
3
5
|
export * from './consts.js'
|
|
4
6
|
export * from './append.js'
|
|
5
7
|
export * from './consent.js'
|
|
6
8
|
export * from './login.js'
|
|
9
|
+
export * from './organization.js'
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BasicContext } from '@owlmeans/context'
|
|
2
|
+
import { oidcProtocols } from '@owlmeans/oidc'
|
|
3
|
+
import type { OidcOrganizationItem } from '@owlmeans/oidc'
|
|
4
|
+
import { adoptToken } from '@owlmeans/client-auth/login'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The organizations of the signed-in subject, the one the session acts in marked `acting`.
|
|
8
|
+
*
|
|
9
|
+
* Answered by the application's own server from the session it holds — refreshed against the
|
|
10
|
+
* provider by the guard first — so a person just removed from an organization no longer sees it.
|
|
11
|
+
* A session of a client without the organizations scope has none. Needs the bindings of
|
|
12
|
+
* `iamEntrypoints()`.
|
|
13
|
+
*/
|
|
14
|
+
export const listOrganizations = async (ctx: BasicContext<any>): Promise<OidcOrganizationItem[]> =>
|
|
15
|
+
(await ctx.entrypoint(oidcProtocols.organizations).call()).items
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Moves the session into another organization of its subject and adopts the re-signed token, so
|
|
19
|
+
* every request after it — and every screen reading `auth` — acts in that organization.
|
|
20
|
+
*
|
|
21
|
+
* There is no per-request organization selector: the session, not the request, decides where a
|
|
22
|
+
* request acts. An organization the subject is not in is refused (`ORGANIZATION_REFUSAL`) and the
|
|
23
|
+
* current token stays.
|
|
24
|
+
*/
|
|
25
|
+
export const switchOrganization = async (ctx: BasicContext<any>, entitySlug: string): Promise<void> => {
|
|
26
|
+
const { token } = await ctx.entrypoint(oidcProtocols.organization).call({ body: { entitySlug } })
|
|
27
|
+
|
|
28
|
+
await adoptToken(ctx, token)
|
|
29
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { AuthForbidden } from '@owlmeans/auth'
|
|
3
|
+
import { bind } from '@owlmeans/client-entrypoint'
|
|
4
|
+
import { makeClientContext } from '@owlmeans/client-context'
|
|
5
|
+
import type { ClientConfig } from '@owlmeans/client-context'
|
|
6
|
+
import { AppType, createService } from '@owlmeans/context'
|
|
7
|
+
import type { InitializedService } from '@owlmeans/context'
|
|
8
|
+
import { EntrypointOutcome, transportAlias } from '@owlmeans/entrypoint'
|
|
9
|
+
import type { AbstractRequest, AbstractResponse, EntrypointHandler, EntrypointTransport } from '@owlmeans/entrypoint'
|
|
10
|
+
import { ResilientError } from '@owlmeans/error'
|
|
11
|
+
import { DEFAULT_ALIAS as AUTH_SERVICE } from '@owlmeans/client-auth'
|
|
12
|
+
import { ORGANIZATION_REFUSAL, oidcProtocols } from '@owlmeans/oidc'
|
|
13
|
+
import type { OidcOrganizationItem } from '@owlmeans/oidc'
|
|
14
|
+
import { RouteProtocols } from '@owlmeans/route'
|
|
15
|
+
import { listOrganizations, switchOrganization } from '../src/organization.js'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The organization switch from the browser's side. The relying party's server is stood in for by
|
|
19
|
+
* the framework's own transport seam: a call reaches it with its alias and body, and a refusal
|
|
20
|
+
* crosses as the marshalled text the API client unmarshals. The auth service records what it is
|
|
21
|
+
* asked to adopt.
|
|
22
|
+
*/
|
|
23
|
+
const ITEMS: OidcOrganizationItem[] = [
|
|
24
|
+
{ entitySlug: 'acme', owner: true, home: true, acting: true },
|
|
25
|
+
{ entitySlug: 'beta', owner: false, title: 'Beta', acting: false },
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
const start = async () => {
|
|
29
|
+
const calls: AbstractRequest[] = []
|
|
30
|
+
const adopted: (string | undefined)[] = []
|
|
31
|
+
|
|
32
|
+
const context = makeClientContext({
|
|
33
|
+
ready: false, service: 'client-iam-tests', type: AppType.Frontend, layer: undefined, services: {}, webService: 'web',
|
|
34
|
+
} as unknown as ClientConfig)
|
|
35
|
+
|
|
36
|
+
context.registerService(createService<EntrypointTransport>(transportAlias(RouteProtocols.WEB), {
|
|
37
|
+
protocol: RouteProtocols.WEB,
|
|
38
|
+
handle: (async (req: AbstractRequest, res: AbstractResponse<unknown>) => {
|
|
39
|
+
calls.push(req)
|
|
40
|
+
if (req.alias === oidcProtocols.organizations.alias) {
|
|
41
|
+
res.resolve({ items: ITEMS }, EntrypointOutcome.Ok)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
const { entitySlug } = req.body as { entitySlug: string }
|
|
45
|
+
if (!ITEMS.some(item => item.entitySlug === entitySlug)) {
|
|
46
|
+
res.reject(ResilientError.ensure(ResilientError.marshal(new AuthForbidden(ORGANIZATION_REFUSAL)).message, true))
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
res.resolve({ token: `wrapped-token-for-${entitySlug}` }, EntrypointOutcome.Ok)
|
|
50
|
+
}) as EntrypointHandler,
|
|
51
|
+
}))
|
|
52
|
+
context.registerService(createService<InitializedService & { update: (token?: string) => Promise<void> }>(AUTH_SERVICE, {
|
|
53
|
+
update: async token => { adopted.push(token) },
|
|
54
|
+
}))
|
|
55
|
+
context.registerEntrypoint(bind(oidcProtocols.organizations))
|
|
56
|
+
context.registerEntrypoint(bind(oidcProtocols.organization))
|
|
57
|
+
await context.configure().init()
|
|
58
|
+
|
|
59
|
+
return { context, calls, adopted }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
describe('@owlmeans/client-iam — organizations', () => {
|
|
63
|
+
test('listOrganizations answers the items of the session', async () => {
|
|
64
|
+
const { context, calls } = await start()
|
|
65
|
+
|
|
66
|
+
expect(await listOrganizations(context)).toEqual(ITEMS)
|
|
67
|
+
expect(calls.map(call => call.alias)).toEqual([oidcProtocols.organizations.alias])
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('switchOrganization posts the slug and adopts the re-signed token', async () => {
|
|
71
|
+
const { context, calls, adopted } = await start()
|
|
72
|
+
|
|
73
|
+
await switchOrganization(context, 'beta')
|
|
74
|
+
expect(calls[0].alias).toBe(oidcProtocols.organization.alias)
|
|
75
|
+
expect(calls[0].body).toEqual({ entitySlug: 'beta' })
|
|
76
|
+
expect(adopted).toEqual(['wrapped-token-for-beta'])
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('a refused switch adopts nothing', async () => {
|
|
80
|
+
const { context, adopted } = await start()
|
|
81
|
+
|
|
82
|
+
await expect(switchOrganization(context, 'gamma')).rejects.toBeInstanceOf(AuthForbidden)
|
|
83
|
+
expect(adopted).toEqual([])
|
|
84
|
+
})
|
|
85
|
+
})
|