@owlmeans/server-auth 0.1.18-rc.53 → 0.1.18-rc.55
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/README.md +7 -7
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-auth/SKILL.md +3 -3
- package/agent-meta/skills/supervisor-auth/SKILL.md +5 -5
- package/build/actions/types.local.d.ts +2 -1
- package/build/actions/types.local.d.ts.map +1 -1
- package/build/manager/actions/authenticate.d.ts +8 -0
- package/build/manager/actions/authenticate.d.ts.map +1 -0
- package/build/manager/actions/authenticate.js +5 -0
- package/build/manager/actions/authenticate.js.map +1 -0
- package/build/manager/actions/index.d.ts +3 -1
- package/build/manager/actions/index.d.ts.map +1 -1
- package/build/manager/actions/index.js +3 -1
- package/build/manager/actions/index.js.map +1 -1
- package/build/manager/actions/init.d.ts +8 -0
- package/build/manager/actions/init.d.ts.map +1 -0
- package/build/manager/actions/init.js +5 -0
- package/build/manager/actions/init.js.map +1 -0
- package/build/manager/actions/rely.d.ts +8 -0
- package/build/manager/actions/rely.d.ts.map +1 -0
- package/build/manager/actions/rely.js +7 -0
- package/build/manager/actions/rely.js.map +1 -0
- package/build/manager/entrypoints.d.ts +7 -1
- package/build/manager/entrypoints.d.ts.map +1 -1
- package/build/manager/model.js +6 -6
- package/build/manager/model.js.map +1 -1
- package/build/manager/plugins/basic-ed25519.d.ts +1 -1
- package/build/manager/plugins/basic-ed25519.d.ts.map +1 -1
- package/build/manager/plugins/basic-ed25519.js +5 -5
- package/build/manager/plugins/basic-ed25519.js.map +1 -1
- package/build/manager/plugins/basic-rely.d.ts +1 -1
- package/build/manager/plugins/basic-rely.d.ts.map +1 -1
- package/build/manager/plugins/basic-rely.js +1 -1
- package/build/manager/plugins/basic-rely.js.map +1 -1
- package/build/manager/plugins/consts.d.ts +8 -0
- package/build/manager/plugins/consts.d.ts.map +1 -0
- package/build/manager/plugins/consts.js +9 -0
- package/build/manager/plugins/consts.js.map +1 -0
- package/build/manager/plugins/export.d.ts +1 -1
- package/build/manager/plugins/export.d.ts.map +1 -1
- package/build/manager/plugins/export.js +1 -1
- package/build/manager/plugins/export.js.map +1 -1
- package/build/manager/plugins/index.d.ts +3 -4
- package/build/manager/plugins/index.d.ts.map +1 -1
- package/build/manager/plugins/index.js +6 -6
- package/build/manager/plugins/index.js.map +1 -1
- package/build/manager/plugins/re-captcha.d.ts +1 -1
- package/build/manager/plugins/re-captcha.d.ts.map +1 -1
- package/build/manager/plugins/re-captcha.js +3 -3
- package/build/manager/plugins/re-captcha.js.map +1 -1
- package/build/manager/plugins/supervisor.js +2 -2
- package/build/manager/plugins/supervisor.js.map +1 -1
- package/build/manager/plugins/types.d.ts +17 -2
- package/build/manager/plugins/types.d.ts.map +1 -1
- package/build/manager/plugins/utils.d.ts +5 -4
- package/build/manager/plugins/utils.d.ts.map +1 -1
- package/build/manager/plugins/utils.js +20 -15
- package/build/manager/plugins/utils.js.map +1 -1
- package/build/manager/rely/flow.d.ts.map +1 -1
- package/build/manager/rely/flow.js +5 -5
- package/build/manager/rely/flow.js.map +1 -1
- package/build/manager/supervisor.d.ts.map +1 -1
- package/build/manager/supervisor.js.map +1 -1
- package/build/model/rely/peer.d.ts.map +1 -1
- package/build/model/rely/peer.js +7 -7
- package/build/model/rely/peer.js.map +1 -1
- package/build/service.d.ts.map +1 -1
- package/build/service.js +12 -12
- package/build/service.js.map +1 -1
- package/package.json +28 -28
- package/src/actions/types.local.ts +1 -1
- package/src/manager/README.md +1 -1
- package/src/manager/actions/authenticate.ts +12 -0
- package/src/manager/actions/index.ts +3 -1
- package/src/manager/actions/init.ts +12 -0
- package/src/manager/actions/rely.ts +12 -0
- package/src/manager/model.ts +6 -6
- package/src/manager/plugins/basic-ed25519.ts +5 -5
- package/src/manager/plugins/basic-rely.ts +1 -1
- package/src/manager/plugins/export.ts +1 -1
- package/src/manager/plugins/index.ts +10 -12
- package/src/manager/plugins/re-captcha.ts +3 -3
- package/src/manager/plugins/supervisor.ts +2 -2
- package/src/manager/plugins/types.ts +19 -2
- package/src/manager/plugins/utils.ts +24 -14
- package/src/manager/rely/flow.ts +5 -5
- package/src/manager/supervisor.ts +2 -1
- package/src/model/rely/peer.ts +8 -8
- package/src/service.ts +13 -13
- package/tests/replay-policy.spec.ts +1 -1
- package/tests/supervisor.spec.ts +2 -2
- package/src/manager/actions/manager.ts +0 -25
- /package/src/manager/plugins/{replay-policy.ts → consts.ts} +0 -0
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { AuthenticationType } from '@owlmeans/auth'
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { basicRely } from './basic-rely.js'
|
|
2
|
+
import type { AuthPluginFactory } from './types.js'
|
|
3
|
+
import { makeBasicEd25519Plugin } from './basic-ed25519.js'
|
|
4
|
+
import { makeReCaptchaPlugin } from './re-captcha.js'
|
|
5
|
+
import { makeBasicRelyPlugin } from './basic-rely.js'
|
|
7
6
|
|
|
8
|
-
export const plugins: Record<string,
|
|
7
|
+
export const plugins: Record<string, AuthPluginFactory> = {}
|
|
9
8
|
|
|
10
|
-
plugins[AuthenticationType.BasicEd25519] =
|
|
11
|
-
plugins[AuthenticationType.ReCaptcha] =
|
|
12
|
-
plugins[AuthenticationType.RelyHandshake] =
|
|
9
|
+
plugins[AuthenticationType.BasicEd25519] = makeBasicEd25519Plugin as AuthPluginFactory
|
|
10
|
+
plugins[AuthenticationType.ReCaptcha] = makeReCaptchaPlugin as AuthPluginFactory
|
|
11
|
+
plugins[AuthenticationType.RelyHandshake] = makeBasicRelyPlugin as AuthPluginFactory
|
|
13
12
|
|
|
14
13
|
/** Register an external AuthPlugin factory under a custom type string. */
|
|
15
14
|
export const registerPlugin = (
|
|
16
15
|
type: string,
|
|
17
|
-
factory:
|
|
16
|
+
factory: AuthPluginFactory
|
|
18
17
|
): void => {
|
|
19
|
-
plugins[type] = factory
|
|
18
|
+
plugins[type] = factory
|
|
20
19
|
}
|
|
21
|
-
|
|
@@ -8,14 +8,14 @@ import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
|
|
|
8
8
|
import { EntrypointOutcome } from '@owlmeans/entrypoint'
|
|
9
9
|
import { base64 } from '@scure/base'
|
|
10
10
|
import { randomBytes } from '@noble/hashes/utils.js'
|
|
11
|
-
import {
|
|
11
|
+
import { authPluginHelper } from './utils.js'
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const makeReCaptchaPlugin = <C extends AppConfig, T extends AppContext<C>>(context: T): AuthPlugin => {
|
|
14
14
|
const plugin: AuthPlugin = {
|
|
15
15
|
type: AuthenticationType.ReCaptcha,
|
|
16
16
|
|
|
17
17
|
init: async request => {
|
|
18
|
-
assertType(request.type, plugin)
|
|
18
|
+
authPluginHelper.assertType(request.type, plugin)
|
|
19
19
|
|
|
20
20
|
const challenge = base64.encode(randomBytes(32))
|
|
21
21
|
|
|
@@ -2,7 +2,7 @@ import { AuthenticationType, AuthenFailed, AuthRole, ALL_SCOPES, buildSupervisor
|
|
|
2
2
|
import type { AuthPlugin } from './types.js'
|
|
3
3
|
import { base64 } from '@scure/base'
|
|
4
4
|
import { randomBytes } from '@noble/hashes/utils.js'
|
|
5
|
-
import {
|
|
5
|
+
import { keyHelper } from '@owlmeans/basic-keys'
|
|
6
6
|
import { TRUSTED } from '@owlmeans/config'
|
|
7
7
|
import type { TrustedRecord } from '@owlmeans/auth-common'
|
|
8
8
|
import type { AppConfig, AppContext, SupervisorPluginOptions } from '../types.js'
|
|
@@ -51,7 +51,7 @@ export const makeSupervisorPlugin = (
|
|
|
51
51
|
if (record?.credential == null) {
|
|
52
52
|
continue
|
|
53
53
|
}
|
|
54
|
-
if (await fromPubKey(record.credential).verify(payload, parsed.signature)) {
|
|
54
|
+
if (await keyHelper.fromPubKey(record.credential).verify(payload, parsed.signature)) {
|
|
55
55
|
matched = alias
|
|
56
56
|
break
|
|
57
57
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { AllowanceResponse } from '@owlmeans/auth'
|
|
2
|
-
import type { AuthModel } from '../types.js'
|
|
2
|
+
import type { AppConfig, AppContext, AuthModel } from '../types.js'
|
|
3
3
|
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
4
4
|
import type { RedisResource } from '@owlmeans/redis-resource'
|
|
5
5
|
import type { ResourceRecord } from '@owlmeans/resource'
|
|
6
|
-
import type { AuthChallengeReplayPolicy } from './
|
|
6
|
+
import type { AuthChallengeReplayPolicy } from './consts.js'
|
|
7
7
|
|
|
8
8
|
export interface AuthPlugin extends Omit<AuthModel, "rely"> {
|
|
9
9
|
type: string
|
|
@@ -31,3 +31,20 @@ export interface RelyRecord extends ResourceRecord, AllowanceResponse {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface AuthRedisResource extends RedisResource<RelyRecord> {}
|
|
34
|
+
|
|
35
|
+
/** Builds the plugin of one authentication type over the context it serves. */
|
|
36
|
+
export interface AuthPluginFactory {
|
|
37
|
+
<C extends AppConfig, T extends AppContext<C>>(context: T): AuthPlugin
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Resolution of the registered plugins, and the check every plugin runs on what it is handed. */
|
|
41
|
+
export interface AuthPluginHelper {
|
|
42
|
+
/** @throws {TypeMissmatchError} when a request names another plugin's type */
|
|
43
|
+
assertType: (type: string, plugin: AuthPlugin) => void
|
|
44
|
+
/**
|
|
45
|
+
* The registered plugin of a type, built over the context.
|
|
46
|
+
*
|
|
47
|
+
* @throws {AuthUnknown}
|
|
48
|
+
*/
|
|
49
|
+
getPlugin: (type: string, context: AppContext<AppConfig>) => Promise<AuthPlugin>
|
|
50
|
+
}
|
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import { AuthUnknown, TypeMissmatchError } from '@owlmeans/auth'
|
|
2
|
-
import type { AuthPlugin } from './types.js'
|
|
2
|
+
import type { AuthPlugin, AuthPluginHelper } from './types.js'
|
|
3
3
|
import type { AppContext, AppConfig } from '../types.js'
|
|
4
4
|
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const createAuthPluginHelper = (): AuthPluginHelper => {
|
|
6
|
+
const assertType = (type: string, plugin: AuthPlugin): void => {
|
|
7
|
+
if (type !== plugin.type) {
|
|
8
|
+
throw new TypeMissmatchError(plugin.type)
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
|
-
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw new AuthUnknown(type)
|
|
12
|
+
const getPlugin = async (type: string, context: AppContext<AppConfig>): Promise<AuthPlugin> => {
|
|
13
|
+
const { plugins } = await import('./index.js')
|
|
14
|
+
const plugin = plugins[type]
|
|
15
|
+
if (plugin == null) {
|
|
16
|
+
throw new AuthUnknown(type)
|
|
17
|
+
}
|
|
18
|
+
return plugins[type](context)
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
return { assertType, getPlugin }
|
|
21
22
|
}
|
|
23
|
+
|
|
24
|
+
export const authPluginHelper = createAuthPluginHelper()
|
|
25
|
+
|
|
26
|
+
/** @deprecated compat:factory-refactor — use `authPluginHelper.assertType(…)` */
|
|
27
|
+
export const assertType = (type: string, plugin: AuthPlugin): void => authPluginHelper.assertType(type, plugin)
|
|
28
|
+
|
|
29
|
+
/** @deprecated compat:factory-refactor — use `authPluginHelper.getPlugin(…)` */
|
|
30
|
+
export const getPlugin = async (type: string, context: AppContext<AppConfig>): Promise<AuthPlugin> =>
|
|
31
|
+
await authPluginHelper.getPlugin(type, context)
|
package/src/manager/rely/flow.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AllowanceRequest, Auth, AuthCredentials, RelyToken } from '@owlmeans/auth'
|
|
2
2
|
import { AUTH_SCOPE, AuthenticationStage, AuthenticationType, AuthPluginError, AuthRole, RELY_3RD } from '@owlmeans/auth'
|
|
3
3
|
import type { AuthenticateMethod, Connection, EventMessage, Message } from '@owlmeans/socket'
|
|
4
|
-
import { isEventMessage, isMessage } from '@owlmeans/socket'
|
|
5
4
|
import type { AppContext, RelyAllowanceRequest, RelyLinker, RelyCarrier } from '../types.js'
|
|
6
5
|
import { makeAuthModel } from '../model.js'
|
|
7
6
|
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope'
|
|
@@ -10,6 +9,7 @@ import { RELY_TUNNEL } from '../consts.js'
|
|
|
10
9
|
import type { RedisResource } from '@owlmeans/redis-resource'
|
|
11
10
|
import { RELY_ACTION_TIMEOUT } from '@owlmeans/auth-common'
|
|
12
11
|
import { logger } from '@owlmeans/log'
|
|
12
|
+
import { socketMessageHelper } from '@owlmeans/socket'
|
|
13
13
|
|
|
14
14
|
// 1. There is a difference between privileged (provider)
|
|
15
15
|
// and non-privileged (consumer) request
|
|
@@ -32,9 +32,9 @@ export const createRelyFlow = (context: AppContext, conn: Connection, auth?: Aut
|
|
|
32
32
|
const linker: RelyLinker = async (rely, source, notify) => {
|
|
33
33
|
const tunnel = context.resource<RedisResource<Message<any>>>(RELY_TUNNEL)
|
|
34
34
|
const closeReceiver = await tunnel.subscribe(async message => {
|
|
35
|
-
if (isMessage(message, true)) {
|
|
35
|
+
if (socketMessageHelper.isMessage(message, true)) {
|
|
36
36
|
await conn.send(message)
|
|
37
|
-
} else if (isEventMessage(message, true)) {
|
|
37
|
+
} else if (socketMessageHelper.isEventMessage(message, true)) {
|
|
38
38
|
if ((message as EventMessage<unknown>).event === 'close') {
|
|
39
39
|
await conn.close()
|
|
40
40
|
closeSender()
|
|
@@ -48,13 +48,13 @@ export const createRelyFlow = (context: AppContext, conn: Connection, auth?: Aut
|
|
|
48
48
|
conn._receiveError = async msg => { log.debug('Forward error', { nonce: source.nonce, id: msg.id }) }
|
|
49
49
|
conn.defaultCallTimeout = RELY_ACTION_TIMEOUT * 1000
|
|
50
50
|
const closeSender = conn.listen(async message => {
|
|
51
|
-
if (isMessage(message, true)) {
|
|
51
|
+
if (socketMessageHelper.isMessage(message, true)) {
|
|
52
52
|
const forward = { ...message }
|
|
53
53
|
if (forward.rawData != null) {
|
|
54
54
|
delete forward.rawData
|
|
55
55
|
}
|
|
56
56
|
await tunnel.publish(forward, rely.nonce)
|
|
57
|
-
} else if (isEventMessage(message, true)) {
|
|
57
|
+
} else if (socketMessageHelper.isEventMessage(message, true)) {
|
|
58
58
|
if (message.event === 'close') {
|
|
59
59
|
const forward = { ...message as Message<unknown> }
|
|
60
60
|
if (forward.rawData != null) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AuthenticationType } from '@owlmeans/auth'
|
|
2
2
|
import { DEFAULT_GUARD } from '@owlmeans/auth-common'
|
|
3
3
|
import type { AppConfig, AppContext, SupervisorAuthOptions, SupervisorPluginOptions } from './types.js'
|
|
4
|
+
import type { AuthPluginFactory } from './plugins/types.js'
|
|
4
5
|
import { registerPlugin } from './plugins/index.js'
|
|
5
6
|
import { makeSupervisorPlugin } from './plugins/supervisor.js'
|
|
6
7
|
import { DEFAULT_SUPERVISORS } from './consts.local.js'
|
|
@@ -50,7 +51,7 @@ export const appendSupervisorAuth = <C extends AppConfig, T extends AppContext<C
|
|
|
50
51
|
|
|
51
52
|
registerPlugin(
|
|
52
53
|
AuthenticationType.Supervisor,
|
|
53
|
-
(ctx => makeSupervisorPlugin(ctx as unknown as AppContext<AppConfig>, resolved)) as
|
|
54
|
+
(ctx => makeSupervisorPlugin(ctx as unknown as AppContext<AppConfig>, resolved)) as AuthPluginFactory
|
|
54
55
|
)
|
|
55
56
|
|
|
56
57
|
if (opts?.acceptInternalTokens !== false) {
|
package/src/model/rely/peer.ts
CHANGED
|
@@ -7,6 +7,14 @@ import { base58 } from '@scure/base'
|
|
|
7
7
|
import type { RelyOptions } from './types.js'
|
|
8
8
|
import { RELY_CALL_TIMEOUT } from '@owlmeans/auth-common'
|
|
9
9
|
|
|
10
|
+
const toNumber = (bytes: Uint8Array): string => {
|
|
11
|
+
let pinInt = 0n
|
|
12
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
13
|
+
pinInt = (pinInt << 8n) | BigInt(bytes[i]);
|
|
14
|
+
}
|
|
15
|
+
return pinInt.toString()
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
export const makeRelyModel = (opts?: RelyOptions): EnvelopeModel<RelyToken> => {
|
|
11
19
|
const envelope = makeEnvelopeModel<RelyToken>(RELY_3RD)
|
|
12
20
|
|
|
@@ -33,11 +41,3 @@ export const makeRelyModel = (opts?: RelyOptions): EnvelopeModel<RelyToken> => {
|
|
|
33
41
|
|
|
34
42
|
return envelope
|
|
35
43
|
}
|
|
36
|
-
|
|
37
|
-
const toNumber = (bytes: Uint8Array): string => {
|
|
38
|
-
let pinInt = 0n
|
|
39
|
-
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
40
|
-
pinInt = (pinInt << 8n) | BigInt(bytes[i]);
|
|
41
|
-
}
|
|
42
|
-
return pinInt.toString()
|
|
43
|
-
}
|
package/src/service.ts
CHANGED
|
@@ -12,25 +12,25 @@ import { trust, extractAuthToken } from '@owlmeans/auth-common/utils'
|
|
|
12
12
|
import { ENTITY_RESOLVER, type EntityResolverService, TOKEN_UPDATE } from '@owlmeans/auth-common'
|
|
13
13
|
import { AUTH_IDENTITY_PROFILE, type IdentityProfile, type IdentityProfileResource } from '@owlmeans/server-auth-identity'
|
|
14
14
|
import { appendMemoryAuthSessionManager, AUTH_SESSION_MANAGER, AUTH_SESSION_TTL, type AuthSessionManager } from '@owlmeans/server-auth-session'
|
|
15
|
-
import {
|
|
15
|
+
import { idHelper } from '@owlmeans/basic-ids'
|
|
16
16
|
import { logger } from '@owlmeans/log'
|
|
17
17
|
import type { Config, Context } from './types.local.js'
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
const log = logger('server-auth')
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* A refused token exchange — the manager's token presented to open a session. Logged with the
|
|
24
|
-
* reason and the account id only; returns the error for the caller to throw.
|
|
25
|
-
*/
|
|
26
|
-
const refuse = (reason: string, error: AuthenFailed, userId?: string): AuthenFailed => {
|
|
27
|
-
const accountId = userId == null ? undefined
|
|
28
|
-
: userId.includes('@') ? `*@${userId.slice(userId.lastIndexOf('@') + 1)}` : userId
|
|
29
|
-
log.warn('Session exchange refused', { reason, ...(accountId != null ? { accountId } : {}) }, { event: 'auth.refused' })
|
|
30
|
-
return error
|
|
31
|
-
}
|
|
32
|
-
|
|
33
22
|
export const makeAuthService = (alias: string = DEFAULT_ALIAS): AuthService => {
|
|
23
|
+
/**
|
|
24
|
+
* A refused token exchange — the manager's token presented to open a session. Logged with the
|
|
25
|
+
* reason and the account id only; returns the error for the caller to throw.
|
|
26
|
+
*/
|
|
27
|
+
const refuse = (reason: string, error: AuthenFailed, userId?: string): AuthenFailed => {
|
|
28
|
+
const accountId = userId == null ? undefined
|
|
29
|
+
: userId.includes('@') ? `*@${userId.slice(userId.lastIndexOf('@') + 1)}` : userId
|
|
30
|
+
log.warn('Session exchange refused', { reason, ...(accountId != null ? { accountId } : {}) }, { event: 'auth.refused' })
|
|
31
|
+
return error
|
|
32
|
+
}
|
|
33
|
+
|
|
34
34
|
const location = `server-auth:${alias}`
|
|
35
35
|
|
|
36
36
|
const cache = (context: Context): Resource<AuthSpent> =>
|
|
@@ -191,7 +191,7 @@ export const makeAuthService = (alias: string = DEFAULT_ALIAS): AuthService => {
|
|
|
191
191
|
isUser: true,
|
|
192
192
|
createdAt: new Date(issuedAt),
|
|
193
193
|
expiresAt,
|
|
194
|
-
sessionId: uuid(),
|
|
194
|
+
sessionId: idHelper.uuid(),
|
|
195
195
|
authorizationVersion: 1
|
|
196
196
|
}
|
|
197
197
|
const manager = sessions(context)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
2
|
import { AuthenFailed, AuthRole } from '@owlmeans/auth'
|
|
3
3
|
import { makeAuthModel } from '../src/manager/model.js'
|
|
4
|
-
import { AuthChallengeReplayPolicy } from '../src/manager/plugins/
|
|
4
|
+
import { AuthChallengeReplayPolicy } from '../src/manager/plugins/consts.js'
|
|
5
5
|
import { registerPlugin } from '../src/manager/plugins/index.js'
|
|
6
6
|
import { makeTestContext } from './context.js'
|
|
7
7
|
|
package/tests/supervisor.spec.ts
CHANGED
|
@@ -4,16 +4,16 @@ import { AuthenticationType, AuthRole, buildSupervisorPayload } from '@owlmeans/
|
|
|
4
4
|
import type { AuthCredentials } from '@owlmeans/auth'
|
|
5
5
|
import type { TrustedRecord } from '@owlmeans/auth-common'
|
|
6
6
|
import type { Criteria } from '@owlmeans/resource'
|
|
7
|
-
import { firstMatch } from '@owlmeans/resource'
|
|
8
7
|
import { makeSupervisorPlugin } from '../src/manager/plugins/supervisor.js'
|
|
9
8
|
import type { AppConfig, AppContext } from '../src/manager/types.js'
|
|
9
|
+
import { recordQueryHelper } from '@owlmeans/resource'
|
|
10
10
|
|
|
11
11
|
const SUPERVISOR = 'master'
|
|
12
12
|
|
|
13
13
|
const makeStubContext = (records: TrustedRecord[]): AppContext<AppConfig> => ({
|
|
14
14
|
getConfigResource: () => ({
|
|
15
15
|
load: async (idOrWhere: string | Criteria<TrustedRecord>) =>
|
|
16
|
-
firstMatch(records, typeof idOrWhere === 'string' ? { id: idOrWhere } : idOrWhere)
|
|
16
|
+
recordQueryHelper.firstMatch(records, typeof idOrWhere === 'string' ? { id: idOrWhere } : idOrWhere)
|
|
17
17
|
})
|
|
18
18
|
} as unknown as AppContext<AppConfig>)
|
|
19
19
|
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { AllowanceRequest, AllowanceResponse, AuthCredentials, AuthToken } from '@owlmeans/auth'
|
|
2
|
-
import type { EntrypointProtocol } from '@owlmeans/entrypoint'
|
|
3
|
-
import { handlers } from '@owlmeans/server-api'
|
|
4
|
-
import { makeAuthModel } from '../model.js'
|
|
5
|
-
import type { AppContext, AppConfig } from '../types.js'
|
|
6
|
-
import { connection } from '@owlmeans/server-socket'
|
|
7
|
-
|
|
8
|
-
const api = handlers<AppContext<AppConfig>>()
|
|
9
|
-
|
|
10
|
-
export const authenticationInit = (protocol: EntrypointProtocol<{ body: AllowanceRequest }, AllowanceResponse>) =>
|
|
11
|
-
api.body(protocol, async (body, context) =>
|
|
12
|
-
await makeAuthModel(context).init(body)
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
export const authenticate = (protocol: EntrypointProtocol<{ body: AuthCredentials }, AuthToken>) =>
|
|
16
|
-
api.body(protocol, async (body, context) =>
|
|
17
|
-
await makeAuthModel(context).authenticate(body)
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
export const rely = (protocol: EntrypointProtocol<{ query: Partial<AuthToken> }, undefined>) => connection(protocol,
|
|
21
|
-
// @TODO Request will contain information is there requrest
|
|
22
|
-
// privileged or not (privileged request implies auth provider)
|
|
23
|
-
async (conn, context, request) =>
|
|
24
|
-
await makeAuthModel(context as AppContext<AppConfig>).rely(conn, request.auth)
|
|
25
|
-
)
|
|
File without changes
|