@owlmeans/server-auth 0.1.18-rc.8 → 0.1.18
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 +216 -38
- package/agent-meta/manifest.json +10 -3
- package/agent-meta/skills/server-auth/SKILL.md +161 -22
- package/agent-meta/skills/supervisor-auth/SKILL.md +128 -0
- package/build/actions/service.d.ts +6 -2
- package/build/actions/service.d.ts.map +1 -1
- package/build/actions/service.js +5 -4
- package/build/actions/service.js.map +1 -1
- package/build/actions/types.local.d.ts +6 -0
- package/build/actions/types.local.d.ts.map +1 -0
- package/build/actions/types.local.js +2 -0
- package/build/actions/types.local.js.map +1 -0
- package/build/entrypoints.d.ts +5 -0
- package/build/entrypoints.d.ts.map +1 -0
- package/build/entrypoints.js +9 -0
- package/build/entrypoints.js.map +1 -0
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.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/consts.local.d.ts +2 -0
- package/build/manager/consts.local.d.ts.map +1 -0
- package/build/manager/consts.local.js +2 -0
- package/build/manager/consts.local.js.map +1 -0
- package/build/manager/context.d.ts.map +1 -1
- package/build/manager/context.js +0 -1
- package/build/manager/context.js.map +1 -1
- package/build/manager/entrypoints.d.ts +9 -0
- package/build/manager/entrypoints.d.ts.map +1 -0
- package/build/manager/entrypoints.js +16 -0
- package/build/manager/entrypoints.js.map +1 -0
- package/build/manager/exports.d.ts +1 -2
- package/build/manager/exports.d.ts.map +1 -1
- package/build/manager/exports.js +1 -2
- package/build/manager/exports.js.map +1 -1
- package/build/manager/index.d.ts +1 -1
- package/build/manager/index.d.ts.map +1 -1
- package/build/manager/index.js +1 -1
- package/build/manager/index.js.map +1 -1
- package/build/manager/main.d.ts.map +1 -1
- package/build/manager/main.js +2 -2
- package/build/manager/main.js.map +1 -1
- package/build/manager/model.d.ts.map +1 -1
- package/build/manager/model.js +71 -32
- 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 +6 -6
- 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 +11 -8
- 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 +5 -0
- package/build/manager/plugins/export.d.ts.map +1 -1
- package/build/manager/plugins/export.js +4 -0
- 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/consts.d.ts +7 -0
- package/build/manager/plugins/re-captcha/consts.d.ts.map +1 -0
- package/build/manager/plugins/re-captcha/consts.js +7 -0
- package/build/manager/plugins/re-captcha/consts.js.map +1 -0
- package/build/manager/plugins/re-captcha/consts.local.d.ts +7 -0
- package/build/manager/plugins/re-captcha/consts.local.d.ts.map +1 -0
- package/build/manager/plugins/re-captcha/consts.local.js +9 -0
- package/build/manager/plugins/re-captcha/consts.local.js.map +1 -0
- package/build/manager/plugins/re-captcha/policy.d.ts +3 -0
- package/build/manager/plugins/re-captcha/policy.d.ts.map +1 -0
- package/build/manager/plugins/re-captcha/policy.js +44 -0
- package/build/manager/plugins/re-captcha/policy.js.map +1 -0
- package/build/manager/plugins/re-captcha/types.d.ts +79 -0
- package/build/manager/plugins/re-captcha/types.d.ts.map +1 -0
- package/build/manager/plugins/re-captcha/types.js +2 -0
- package/build/manager/plugins/re-captcha/types.js.map +1 -0
- package/build/manager/plugins/re-captcha/verifier.d.ts +12 -0
- package/build/manager/plugins/re-captcha/verifier.d.ts.map +1 -0
- package/build/manager/plugins/re-captcha/verifier.js +62 -0
- package/build/manager/plugins/re-captcha/verifier.js.map +1 -0
- package/build/manager/plugins/re-captcha.d.ts +10 -1
- package/build/manager/plugins/re-captcha.d.ts.map +1 -1
- package/build/manager/plugins/re-captcha.js +50 -37
- package/build/manager/plugins/re-captcha.js.map +1 -1
- package/build/manager/plugins/supervisor.d.ts +1 -2
- package/build/manager/plugins/supervisor.d.ts.map +1 -1
- package/build/manager/plugins/supervisor.js +6 -6
- package/build/manager/plugins/supervisor.js.map +1 -1
- package/build/manager/plugins/types.d.ts +22 -14
- 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 +13 -11
- package/build/manager/rely/flow.js.map +1 -1
- package/build/manager/rely.d.ts.map +1 -1
- package/build/manager/rely.js.map +1 -1
- package/build/manager/supervisor.d.ts +4 -45
- package/build/manager/supervisor.d.ts.map +1 -1
- package/build/manager/supervisor.js +5 -5
- package/build/manager/supervisor.js.map +1 -1
- package/build/manager/types.d.ts +41 -1
- package/build/manager/types.d.ts.map +1 -1
- package/build/manager/types.local.d.ts +4 -0
- package/build/manager/types.local.d.ts.map +1 -0
- package/build/manager/types.local.js +2 -0
- package/build/manager/types.local.js.map +1 -0
- package/build/manager/utils/trusted.d.ts.map +1 -1
- package/build/manager/utils/trusted.js.map +1 -1
- package/build/model/rely/consumer.d.ts +3 -1
- package/build/model/rely/consumer.d.ts.map +1 -1
- package/build/model/rely/consumer.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/model/rely/provider.d.ts +3 -1
- package/build/model/rely/provider.d.ts.map +1 -1
- package/build/model/rely/provider.js.map +1 -1
- package/build/re-captcha/guard.d.ts +12 -0
- package/build/re-captcha/guard.d.ts.map +1 -0
- package/build/re-captcha/guard.js +43 -0
- package/build/re-captcha/guard.js.map +1 -0
- package/build/re-captcha/index.d.ts +4 -0
- package/build/re-captcha/index.d.ts.map +1 -0
- package/build/re-captcha/index.js +3 -0
- package/build/re-captcha/index.js.map +1 -0
- package/build/re-captcha/token.d.ts +6 -0
- package/build/re-captcha/token.d.ts.map +1 -0
- package/build/re-captcha/token.js +74 -0
- package/build/re-captcha/token.js.map +1 -0
- package/build/re-captcha/types.d.ts +44 -0
- package/build/re-captcha/types.d.ts.map +1 -0
- package/build/re-captcha/types.js +2 -0
- package/build/re-captcha/types.js.map +1 -0
- package/build/service.d.ts +2 -3
- package/build/service.d.ts.map +1 -1
- package/build/service.js +136 -13
- package/build/service.js.map +1 -1
- package/build/types.local.d.ts +4 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/package.json +33 -30
- package/src/actions/service.ts +10 -12
- package/src/actions/types.local.ts +6 -0
- package/src/entrypoints.ts +12 -0
- package/src/index.ts +2 -2
- package/src/manager/README.md +14 -18
- 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/consts.local.ts +1 -0
- package/src/manager/context.ts +0 -2
- package/src/manager/entrypoints.ts +17 -0
- package/src/manager/exports.ts +1 -2
- package/src/manager/index.ts +1 -1
- package/src/manager/main.ts +2 -2
- package/src/manager/model.ts +82 -41
- package/src/manager/plugins/basic-ed25519.ts +8 -8
- package/src/manager/plugins/basic-rely.ts +14 -9
- package/src/manager/plugins/consts.ts +7 -0
- package/src/manager/plugins/export.ts +5 -0
- package/src/manager/plugins/index.ts +10 -12
- package/src/manager/plugins/re-captcha/consts.local.ts +8 -0
- package/src/manager/plugins/re-captcha/consts.ts +8 -0
- package/src/manager/plugins/re-captcha/policy.ts +56 -0
- package/src/manager/plugins/re-captcha/types.ts +85 -0
- package/src/manager/plugins/re-captcha/verifier.ts +74 -0
- package/src/manager/plugins/re-captcha.ts +58 -43
- package/src/manager/plugins/supervisor.ts +9 -11
- package/src/manager/plugins/types.ts +23 -14
- package/src/manager/plugins/utils.ts +24 -14
- package/src/manager/rely/flow.ts +14 -11
- package/src/manager/rely.ts +2 -5
- package/src/manager/supervisor.ts +8 -54
- package/src/manager/types.local.ts +5 -0
- package/src/manager/types.ts +46 -1
- package/src/model/rely/consumer.ts +3 -1
- package/src/model/rely/peer.ts +8 -8
- package/src/model/rely/provider.ts +3 -1
- package/src/re-captcha/guard.ts +52 -0
- package/src/re-captcha/index.ts +3 -0
- package/src/re-captcha/token.ts +89 -0
- package/src/re-captcha/types.ts +45 -0
- package/src/service.ts +133 -19
- package/src/types.local.ts +5 -0
- package/tests/context.ts +3 -2
- package/tests/re-captcha.spec.ts +298 -0
- package/tests/replay-policy.spec.ts +36 -0
- package/tests/supervisor.spec.ts +6 -4
- package/build/.gitkeep +0 -0
- package/src/manager/actions/manager.ts +0 -23
- package/src/manager/modules.ts +0 -29
- package/src/modules.ts +0 -17
package/build/service.js
CHANGED
|
@@ -2,12 +2,72 @@ import { TRUSTED } from '@owlmeans/config';
|
|
|
2
2
|
import { AUTH_CACHE, AUTH_SRV_KEY, AUTHEN_TIMEFRAME, DEFAULT_ALIAS } from './consts.js';
|
|
3
3
|
import { assertContext, createService } from '@owlmeans/context';
|
|
4
4
|
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope';
|
|
5
|
-
import { AuthenFailed, AuthorizationError, AuthroizationType } from '@owlmeans/auth';
|
|
5
|
+
import { AuthenFailed, AuthenticationType, AuthorizationError, AuthroizationType, AuthUnavailable } from '@owlmeans/auth';
|
|
6
6
|
import { createStaticResource } from '@owlmeans/static-resource';
|
|
7
7
|
import { trust, extractAuthToken } from '@owlmeans/auth-common/utils';
|
|
8
|
+
import { ENTITY_RESOLVER, TOKEN_UPDATE } from '@owlmeans/auth-common';
|
|
9
|
+
import { AUTH_IDENTITY_PROFILE } from '@owlmeans/server-auth-identity';
|
|
10
|
+
import { appendMemoryAuthSessionManager, AUTH_SESSION_MANAGER, AUTH_SESSION_TTL } from '@owlmeans/server-auth-session';
|
|
11
|
+
import { idHelper } from '@owlmeans/basic-ids';
|
|
12
|
+
import { logger } from '@owlmeans/log';
|
|
13
|
+
const log = logger('server-auth');
|
|
8
14
|
export const makeAuthService = (alias = DEFAULT_ALIAS) => {
|
|
15
|
+
/**
|
|
16
|
+
* A refused token exchange — the manager's token presented to open a session. Logged with the
|
|
17
|
+
* reason and the account id only; returns the error for the caller to throw.
|
|
18
|
+
*/
|
|
19
|
+
const refuse = (reason, error, userId) => {
|
|
20
|
+
const accountId = userId == null ? undefined
|
|
21
|
+
: userId.includes('@') ? `*@${userId.slice(userId.lastIndexOf('@') + 1)}` : userId;
|
|
22
|
+
log.warn('Session exchange refused', { reason, ...(accountId != null ? { accountId } : {}) }, { event: 'auth.refused' });
|
|
23
|
+
return error;
|
|
24
|
+
};
|
|
9
25
|
const location = `server-auth:${alias}`;
|
|
10
26
|
const cache = (context) => context.resource(AUTH_CACHE);
|
|
27
|
+
const sessions = (context) => context.hasService(AUTH_SESSION_MANAGER)
|
|
28
|
+
? context.service(AUTH_SESSION_MANAGER)
|
|
29
|
+
: null;
|
|
30
|
+
const entityIdFor = async (context, entitySlug) => {
|
|
31
|
+
if (entitySlug == null || entitySlug === '')
|
|
32
|
+
return null;
|
|
33
|
+
if (!context.hasService(ENTITY_RESOLVER))
|
|
34
|
+
return entitySlug;
|
|
35
|
+
const entity = await context.service(ENTITY_RESOLVER).resolve(entitySlug);
|
|
36
|
+
return entity?.id ?? null;
|
|
37
|
+
};
|
|
38
|
+
const refresh = async (context, auth, version) => {
|
|
39
|
+
const entityId = await entityIdFor(context, auth.entitySlug);
|
|
40
|
+
if (entityId == null || auth.profileId == null || !context.hasResource(AUTH_IDENTITY_PROFILE))
|
|
41
|
+
return null;
|
|
42
|
+
const profiles = context.resource(AUTH_IDENTITY_PROFILE);
|
|
43
|
+
let profile = null;
|
|
44
|
+
try {
|
|
45
|
+
profile = await profiles.load({ entityId, profileId: auth.profileId });
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// A missing profile is a definitive authentication refusal; a failed profile store is an
|
|
49
|
+
// availability dependency and must not look like a revoked browser session.
|
|
50
|
+
throw new AuthUnavailable('identity-profile');
|
|
51
|
+
}
|
|
52
|
+
if (profile == null || (profile.expiresAt != null && new Date(profile.expiresAt).getTime() <= Date.now()))
|
|
53
|
+
return null;
|
|
54
|
+
return {
|
|
55
|
+
...auth,
|
|
56
|
+
userId: profile.userId ?? auth.userId,
|
|
57
|
+
role: profile.role,
|
|
58
|
+
scopes: profile.scopes ?? [],
|
|
59
|
+
...(profile.permissions != null ? { permissions: profile.permissions } : {}),
|
|
60
|
+
authorizationVersion: version,
|
|
61
|
+
createdAt: new Date()
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const sign = async (context, auth) => {
|
|
65
|
+
const trusted = await trust(context, TRUSTED, context.cfg.alias ?? context.cfg.service);
|
|
66
|
+
const ttl = auth.expiresAt == null ? AUTH_SESSION_TTL : Math.max(0, new Date(auth.expiresAt).getTime() - Date.now());
|
|
67
|
+
const authorization = await makeEnvelopeModel(AuthroizationType.Ed25519BasicToken)
|
|
68
|
+
.send(auth, ttl).sign(trusted.key, EnvelopeKind.Token);
|
|
69
|
+
return `${AuthroizationType.Ed25519BasicToken.toUpperCase()} ${authorization}`;
|
|
70
|
+
};
|
|
11
71
|
const service = createService(alias, {
|
|
12
72
|
match: async (req) => extractAuthToken(req, AuthroizationType.Ed25519BasicToken) != null,
|
|
13
73
|
handle: async (req, res) => {
|
|
@@ -21,7 +81,32 @@ export const makeAuthService = (alias = DEFAULT_ALIAS) => {
|
|
|
21
81
|
if (!await envelope.verify(trusted.key)) {
|
|
22
82
|
return false;
|
|
23
83
|
}
|
|
24
|
-
|
|
84
|
+
let auth = envelope.message();
|
|
85
|
+
const manager = sessions(context);
|
|
86
|
+
if (manager != null) {
|
|
87
|
+
if (auth.sessionId == null)
|
|
88
|
+
return false;
|
|
89
|
+
let decision;
|
|
90
|
+
try {
|
|
91
|
+
decision = await manager.inspect(auth.sessionId);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// Registry availability is a security dependency. A guard cannot authenticate through it.
|
|
95
|
+
throw new AuthUnavailable('session-registry');
|
|
96
|
+
}
|
|
97
|
+
if (decision.state !== 'active' && decision.state !== 'refresh')
|
|
98
|
+
return false;
|
|
99
|
+
if (decision.state === 'refresh') {
|
|
100
|
+
const refreshed = await refresh(context, auth, decision.version);
|
|
101
|
+
if (refreshed == null)
|
|
102
|
+
return false;
|
|
103
|
+
auth = refreshed;
|
|
104
|
+
const replacement = await sign(context, auth);
|
|
105
|
+
res.responseProvider?.header(TOKEN_UPDATE, replacement);
|
|
106
|
+
req.headers = { ...req.headers, authorization: replacement };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
res.resolve(auth);
|
|
25
110
|
return true;
|
|
26
111
|
},
|
|
27
112
|
unpack: async (token) => {
|
|
@@ -32,7 +117,22 @@ export const makeAuthService = (alias = DEFAULT_ALIAS) => {
|
|
|
32
117
|
if (!await envelope.verify(trusted.key)) {
|
|
33
118
|
throw new AuthorizationError('unpack');
|
|
34
119
|
}
|
|
35
|
-
|
|
120
|
+
const auth = envelope.message();
|
|
121
|
+
const manager = sessions(context);
|
|
122
|
+
if (manager != null) {
|
|
123
|
+
if (auth.sessionId == null)
|
|
124
|
+
throw new AuthorizationError('session');
|
|
125
|
+
let decision;
|
|
126
|
+
try {
|
|
127
|
+
decision = await manager.inspect(auth.sessionId);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
throw new AuthUnavailable('session-registry');
|
|
131
|
+
}
|
|
132
|
+
if (decision.state !== 'active')
|
|
133
|
+
throw new AuthorizationError('session');
|
|
134
|
+
}
|
|
135
|
+
return auth;
|
|
36
136
|
},
|
|
37
137
|
authenticated: async () => {
|
|
38
138
|
return null;
|
|
@@ -42,21 +142,28 @@ export const makeAuthService = (alias = DEFAULT_ALIAS) => {
|
|
|
42
142
|
const envelope = makeEnvelopeModel(token.token, EnvelopeKind.Token);
|
|
43
143
|
const authService = await trust(context, TRUSTED, AUTH_SRV_KEY);
|
|
44
144
|
if (!await envelope.verify(authService.key)) {
|
|
45
|
-
throw new AuthenFailed();
|
|
145
|
+
throw refuse('signature', new AuthenFailed());
|
|
46
146
|
}
|
|
47
147
|
const credentials = envelope.message();
|
|
48
148
|
const msg = credentials.challenge;
|
|
49
|
-
//
|
|
149
|
+
// A reCAPTCHA token proves a solved challenge, never a person: it is spent by
|
|
150
|
+
// `makeReCaptchaGuard` on the one route that takes it and never becomes a session. Refused
|
|
151
|
+
// before the spend, so a token presented here stays usable where it belongs.
|
|
152
|
+
if (envelope.type() === AuthenticationType.ReCaptcha || credentials.type === AuthenticationType.ReCaptcha) {
|
|
153
|
+
throw refuse('guest', new AuthenFailed('guest'), credentials.userId);
|
|
154
|
+
}
|
|
50
155
|
try {
|
|
51
156
|
await cache(context).create({ id: msg }, { ttl: AUTHEN_TIMEFRAME / 1000 });
|
|
52
157
|
}
|
|
53
158
|
catch {
|
|
54
|
-
throw new AuthenFailed();
|
|
159
|
+
throw refuse('replay', new AuthenFailed(), credentials.userId);
|
|
55
160
|
}
|
|
56
161
|
if (credentials.credential !== authService.user.id) {
|
|
57
|
-
throw new AuthenFailed();
|
|
162
|
+
throw refuse('issuer', new AuthenFailed(), credentials.userId);
|
|
58
163
|
}
|
|
59
164
|
// @TODO Move to a plugin
|
|
165
|
+
const issuedAt = Date.now();
|
|
166
|
+
const expiresAt = new Date(issuedAt + AUTH_SESSION_TTL);
|
|
60
167
|
const auth = {
|
|
61
168
|
token: credentials.challenge,
|
|
62
169
|
userId: credentials.userId,
|
|
@@ -65,14 +172,27 @@ export const makeAuthService = (alias = DEFAULT_ALIAS) => {
|
|
|
65
172
|
type: AuthroizationType.Ed25519BasicToken,
|
|
66
173
|
source: context.cfg.service,
|
|
67
174
|
profileId: credentials.profileId,
|
|
68
|
-
|
|
175
|
+
entitySlug: credentials.entitySlug,
|
|
69
176
|
isUser: true,
|
|
70
|
-
createdAt: new Date()
|
|
177
|
+
createdAt: new Date(issuedAt),
|
|
178
|
+
expiresAt,
|
|
179
|
+
sessionId: idHelper.uuid(),
|
|
180
|
+
authorizationVersion: 1
|
|
71
181
|
};
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
182
|
+
const manager = sessions(context);
|
|
183
|
+
if (manager != null) {
|
|
184
|
+
const entityId = await entityIdFor(context, auth.entitySlug);
|
|
185
|
+
if (entityId == null || auth.profileId == null)
|
|
186
|
+
throw refuse('session', new AuthenFailed('session'), auth.userId);
|
|
187
|
+
const decision = await manager.register({
|
|
188
|
+
id: auth.sessionId, kind: 'bearer', entityId, profileId: auth.profileId,
|
|
189
|
+
issuedAt, expiresAt: expiresAt.getTime()
|
|
190
|
+
});
|
|
191
|
+
if (decision.state !== 'active')
|
|
192
|
+
throw refuse('session', new AuthenFailed('session'), auth.userId);
|
|
193
|
+
auth.authorizationVersion = decision.version;
|
|
194
|
+
}
|
|
195
|
+
return { token: await sign(context, auth) };
|
|
76
196
|
}
|
|
77
197
|
});
|
|
78
198
|
return service;
|
|
@@ -81,6 +201,9 @@ export const appendAuthService = (ctx, alias = DEFAULT_ALIAS) => {
|
|
|
81
201
|
if (!ctx.hasResource(AUTH_CACHE)) {
|
|
82
202
|
ctx.registerResource(createStaticResource(AUTH_CACHE));
|
|
83
203
|
}
|
|
204
|
+
// Every standalone server gets an expiring process-local registry. Scaled deployments replace
|
|
205
|
+
// it with appendRedisAuthSessionManager before calling this helper.
|
|
206
|
+
appendMemoryAuthSessionManager(ctx);
|
|
84
207
|
const service = makeAuthService(alias);
|
|
85
208
|
const context = ctx;
|
|
86
209
|
context.registerService(service);
|
package/build/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEvF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEvF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAA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AM,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.js","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/server-auth",
|
|
3
|
-
"version": "0.1.18
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -36,40 +36,43 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@noble/hashes": "^
|
|
40
|
-
"@owlmeans/api": "^0.1.18
|
|
41
|
-
"@owlmeans/api-config-server": "^0.1.18
|
|
42
|
-
"@owlmeans/auth": "^0.1.18
|
|
43
|
-
"@owlmeans/auth-common": "^0.1.18
|
|
44
|
-
"@owlmeans/basic-envelope": "^0.1.18
|
|
45
|
-
"@owlmeans/basic-ids": "^0.1.18
|
|
46
|
-
"@owlmeans/basic-keys": "^0.1.18
|
|
47
|
-
"@owlmeans/client-config": "^0.1.18
|
|
48
|
-
"@owlmeans/client-entrypoint": "^0.1.18
|
|
49
|
-
"@owlmeans/config": "^0.1.18
|
|
50
|
-
"@owlmeans/context": "^0.1.18
|
|
51
|
-
"@owlmeans/kluster": "^0.1.18
|
|
52
|
-
"@owlmeans/
|
|
53
|
-
"@owlmeans/
|
|
54
|
-
"@owlmeans/resource": "^0.1.18
|
|
55
|
-
"@owlmeans/
|
|
56
|
-
"@owlmeans/
|
|
57
|
-
"@owlmeans/server-
|
|
58
|
-
"@owlmeans/server-
|
|
59
|
-
"@owlmeans/server-
|
|
60
|
-
"@owlmeans/server-
|
|
61
|
-
"@owlmeans/
|
|
62
|
-
"@owlmeans/
|
|
63
|
-
"@
|
|
39
|
+
"@noble/hashes": "^2.4.0",
|
|
40
|
+
"@owlmeans/api": "^0.1.18",
|
|
41
|
+
"@owlmeans/api-config-server": "^0.1.18",
|
|
42
|
+
"@owlmeans/auth": "^0.1.18",
|
|
43
|
+
"@owlmeans/auth-common": "^0.1.18",
|
|
44
|
+
"@owlmeans/basic-envelope": "^0.1.18",
|
|
45
|
+
"@owlmeans/basic-ids": "^0.1.18",
|
|
46
|
+
"@owlmeans/basic-keys": "^0.1.18",
|
|
47
|
+
"@owlmeans/client-config": "^0.1.18",
|
|
48
|
+
"@owlmeans/client-entrypoint": "^0.1.18",
|
|
49
|
+
"@owlmeans/config": "^0.1.18",
|
|
50
|
+
"@owlmeans/context": "^0.1.18",
|
|
51
|
+
"@owlmeans/kluster": "^0.1.18",
|
|
52
|
+
"@owlmeans/log": "^0.1.18",
|
|
53
|
+
"@owlmeans/entrypoint": "^0.1.18",
|
|
54
|
+
"@owlmeans/redis-resource": "^0.1.18",
|
|
55
|
+
"@owlmeans/resource": "^0.1.18",
|
|
56
|
+
"@owlmeans/route": "^0.1.18",
|
|
57
|
+
"@owlmeans/server-api": "^0.1.18",
|
|
58
|
+
"@owlmeans/server-auth-identity": "^0.1.18",
|
|
59
|
+
"@owlmeans/server-auth-session": "^0.1.18",
|
|
60
|
+
"@owlmeans/server-context": "^0.1.18",
|
|
61
|
+
"@owlmeans/server-entrypoint": "^0.1.18",
|
|
62
|
+
"@owlmeans/server-route": "^0.1.18",
|
|
63
|
+
"@owlmeans/server-socket": "^0.1.18",
|
|
64
|
+
"@owlmeans/socket": "^0.1.18",
|
|
65
|
+
"@owlmeans/static-resource": "^0.1.18",
|
|
66
|
+
"@scure/base": "^2.4.0"
|
|
64
67
|
},
|
|
65
68
|
"peerDependencies": {
|
|
66
69
|
"ajv": "*"
|
|
67
70
|
},
|
|
68
71
|
"devDependencies": {
|
|
69
|
-
"@owlmeans/dep-config": "
|
|
70
|
-
"@owlmeans/test-auth": "^0.1.18
|
|
71
|
-
"@types/bun": "^1.
|
|
72
|
-
"@types/node": "^26.
|
|
72
|
+
"@owlmeans/dep-config": "^0.1.18",
|
|
73
|
+
"@owlmeans/test-auth": "^0.1.18",
|
|
74
|
+
"@types/bun": "^1.4.2",
|
|
75
|
+
"@types/node": "^26.6.4",
|
|
73
76
|
"nodemon": "^3.1.14",
|
|
74
77
|
"typescript": "^7.0.2"
|
|
75
78
|
},
|
package/src/actions/service.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { handlers } from '@owlmeans/server-api'
|
|
2
|
+
import type { EntrypointProtocol } from '@owlmeans/entrypoint'
|
|
2
3
|
import type { AuthToken } from '@owlmeans/auth'
|
|
3
|
-
import { handleBody } from '@owlmeans/server-api'
|
|
4
|
-
import { AuthServiceAppend } from '../types.js'
|
|
5
|
-
import type { ServerConfig, ServerContext } from '@owlmeans/server-context'
|
|
6
4
|
import { assertContext } from '@owlmeans/context'
|
|
5
|
+
import type { Context } from './types.local.js'
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
type Context = ServerContext<Config> & AuthServiceAppend
|
|
7
|
+
const api = handlers<Context>()
|
|
10
8
|
|
|
11
|
-
export const authenticate:
|
|
12
|
-
async (
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
9
|
+
export const authenticate = (protocol: EntrypointProtocol<{ body: AuthToken }, AuthToken>) =>
|
|
10
|
+
api.request(protocol, async (request, context) => {
|
|
11
|
+
const ctx = assertContext(context, 'authenticate') as Context
|
|
12
|
+
|
|
13
|
+
return await ctx.auth().authenticate(request.body)
|
|
14
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
import { bind } from '@owlmeans/server-entrypoint'
|
|
3
|
+
import type { ServerProtocolEntrypoint } from '@owlmeans/server-entrypoint'
|
|
4
|
+
import { authProtocols } from '@owlmeans/auth-common'
|
|
5
|
+
import type { EntrypointProtocolDeclaration } from '@owlmeans/entrypoint'
|
|
6
|
+
import { authenticate } from './actions/service.js'
|
|
7
|
+
|
|
8
|
+
/** Server entrypoints required by the generic authentication service. */
|
|
9
|
+
export const entrypoints: ServerProtocolEntrypoint<EntrypointProtocolDeclaration>[] = [
|
|
10
|
+
bind(authProtocols.dispatcher),
|
|
11
|
+
bind(authProtocols.dispatcherAuthenticate, authenticate(authProtocols.dispatcherAuthenticate)),
|
|
12
|
+
]
|
package/src/index.ts
CHANGED
package/src/manager/README.md
CHANGED
|
@@ -27,18 +27,18 @@ A specialized guard service that enables authentication token relay between micr
|
|
|
27
27
|
- **Wallet DID Authentication**: Decentralized identity authentication support
|
|
28
28
|
- **Challenge Validation**: Anti-replay protection using challenge-response mechanisms
|
|
29
29
|
|
|
30
|
-
###
|
|
31
|
-
The manager is built on the OwlMeans
|
|
30
|
+
### Entrypoint-Based Architecture
|
|
31
|
+
The manager is built on the OwlMeans entrypoint system, providing:
|
|
32
32
|
- **Route Management**: Standardized API endpoints for authentication operations
|
|
33
|
-
- **Handler Registration**:
|
|
34
|
-
- **Guard Integration**: Automatic security enforcement at the
|
|
33
|
+
- **Handler Registration**: Protocol-backed request handlers for different authentication flows
|
|
34
|
+
- **Guard Integration**: Automatic security enforcement at the entrypoint level
|
|
35
35
|
|
|
36
36
|
## Installation
|
|
37
37
|
|
|
38
38
|
This manager app is part of the `@owlmeans/server-auth` package:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
npm install @owlmeans/server-auth
|
|
41
|
+
npm install @owlmeans/server-auth@^0.1.18
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## API Reference
|
|
@@ -317,20 +317,16 @@ await authModel.rely(connection, authToken.auth)
|
|
|
317
317
|
|
|
318
318
|
### API Integration
|
|
319
319
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
// The manager automatically registers these API endpoints:
|
|
320
|
+
`main(context)` registers the manager's immutable `entrypoints` and starts the API server. For a
|
|
321
|
+
custom bootstrap, register the exported collection yourself; the manager's protocols are then
|
|
322
|
+
addressed through the same `context.entrypoint(protocol)` lookup as application endpoints.
|
|
324
323
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
// WebSocket /api/auth/rely - Authentication relay
|
|
324
|
+
```typescript
|
|
325
|
+
import { entrypoints, makeContext } from '@owlmeans/server-auth/manager'
|
|
328
326
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
console.log(`Method: ${module.route.method}`)
|
|
333
|
-
})
|
|
327
|
+
const context = makeContext(config)
|
|
328
|
+
context.registerEntrypoints(entrypoints)
|
|
329
|
+
await context.configure().init()
|
|
334
330
|
```
|
|
335
331
|
|
|
336
332
|
## API Endpoints
|
|
@@ -504,4 +500,4 @@ This manager app depends on:
|
|
|
504
500
|
- [`@owlmeans/server-auth`](../../../README.md) - Parent server authentication package
|
|
505
501
|
- [`@owlmeans/auth`](../../../auth/README.md) - Core authentication library
|
|
506
502
|
- [`@owlmeans/client-auth`](../../../client-auth/README.md) - Client-side authentication
|
|
507
|
-
- [`@owlmeans/context`](../../../context/README.md) - Context management system
|
|
503
|
+
- [`@owlmeans/context`](../../../context/README.md) - Context management system
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { 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
|
+
|
|
7
|
+
const api = handlers<AppContext<AppConfig>>()
|
|
8
|
+
|
|
9
|
+
export const authenticate = (protocol: EntrypointProtocol<{ body: AuthCredentials }, AuthToken>) =>
|
|
10
|
+
api.body(protocol, async (body, context) =>
|
|
11
|
+
await makeAuthModel(context).authenticate(body)
|
|
12
|
+
)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AllowanceRequest, AllowanceResponse } 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
|
+
|
|
7
|
+
const api = handlers<AppContext<AppConfig>>()
|
|
8
|
+
|
|
9
|
+
export const authenticationInit = (protocol: EntrypointProtocol<{ body: AllowanceRequest }, AllowanceResponse>) =>
|
|
10
|
+
api.body(protocol, async (body, context) =>
|
|
11
|
+
await makeAuthModel(context).init(body)
|
|
12
|
+
)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuthToken } from '@owlmeans/auth'
|
|
2
|
+
import type { EntrypointProtocol } from '@owlmeans/entrypoint'
|
|
3
|
+
import { makeAuthModel } from '../model.js'
|
|
4
|
+
import type { AppContext, AppConfig } from '../types.js'
|
|
5
|
+
import { connection } from '@owlmeans/server-socket'
|
|
6
|
+
|
|
7
|
+
export const rely = (protocol: EntrypointProtocol<{ query: Partial<AuthToken> }, undefined>) => connection(protocol,
|
|
8
|
+
// @TODO Request will contain information is there requrest
|
|
9
|
+
// privileged or not (privileged request implies auth provider)
|
|
10
|
+
async (conn, context, request) =>
|
|
11
|
+
await makeAuthModel(context as AppContext<AppConfig>).rely(conn, request.auth)
|
|
12
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_SUPERVISORS = ['master', 'superuser']
|
package/src/manager/context.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { authProtocols } from '@owlmeans/auth-common'
|
|
2
|
+
import { entrypoints as apiConfigBindings } from '@owlmeans/api-config-server'
|
|
3
|
+
import { bind } from '@owlmeans/server-entrypoint'
|
|
4
|
+
import { decorateEntrypoint } from '@owlmeans/entrypoint'
|
|
5
|
+
import * as actions from './actions/index.js'
|
|
6
|
+
import { DEFAULT_RELY } from './consts.js'
|
|
7
|
+
|
|
8
|
+
const relyProtocol = decorateEntrypoint(authProtocols.rely, { guards: DEFAULT_RELY })
|
|
9
|
+
|
|
10
|
+
/** Server entrypoints for the full authentication manager. */
|
|
11
|
+
export const entrypoints = [
|
|
12
|
+
bind(authProtocols.authen, undefined, { intermediate: true }),
|
|
13
|
+
bind(authProtocols.init, actions.authenticationInit(authProtocols.init)),
|
|
14
|
+
bind(authProtocols.authenticate, actions.authenticate(authProtocols.authenticate)),
|
|
15
|
+
bind(relyProtocol, actions.rely(relyProtocol)),
|
|
16
|
+
...apiConfigBindings,
|
|
17
|
+
]
|
package/src/manager/exports.ts
CHANGED
|
@@ -5,8 +5,7 @@ export { addWebService } from '@owlmeans/client-config'
|
|
|
5
5
|
export { service, TRUSTED } from '@owlmeans/config'
|
|
6
6
|
export { AppType, assertContext } from '@owlmeans/context'
|
|
7
7
|
export { klusterize } from '@owlmeans/kluster'
|
|
8
|
-
export {
|
|
9
|
-
export { elevate as celevate, stab } from '@owlmeans/client-entrypoint'
|
|
8
|
+
export { stab } from '@owlmeans/client-entrypoint'
|
|
10
9
|
export type { RefedEntrypointHandler } from '@owlmeans/server-entrypoint'
|
|
11
10
|
export { handleIntermediate, handleBody, handleRequest, handleParams } from '@owlmeans/server-api'
|
|
12
11
|
export type { AbstractRequest, AbstractResponse } from '@owlmeans/entrypoint'
|
package/src/manager/index.ts
CHANGED
package/src/manager/main.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import { entrypoints } from './entrypoints.js'
|
|
3
3
|
import type { AppContext, AppConfig } from './types.js'
|
|
4
4
|
|
|
5
5
|
export const main = async <C extends AppConfig, T extends AppContext<C>>(ctx: T) => {
|
|
6
|
-
ctx.registerEntrypoints(
|
|
6
|
+
ctx.registerEntrypoints(entrypoints)
|
|
7
7
|
await ctx.configure().init()
|
|
8
8
|
await ctx.getApiServer().listen()
|
|
9
9
|
}
|