@owlmeans/server-auth-otp 0.1.17 → 0.1.18-rc.1
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 +20 -8
- package/agent-meta/manifest.json +2 -2
- package/build/plugin.d.ts.map +1 -1
- package/build/plugin.js +10 -4
- package/build/plugin.js.map +1 -1
- package/package.json +12 -12
- package/src/plugin.ts +11 -4
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ Email OTP `AuthPlugin` for OwlMeans servers — passwordless login via time-limi
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
- `
|
|
8
|
-
- `
|
|
9
|
-
- Integrates with `@owlmeans/server-auth` plugin registry — plugs in alongside other auth strategies
|
|
7
|
+
- `appendOtpPlugin(context)` — registers the `AuthPlugin` that handles `OTP_AUTH_TYPE` (`'email-otp'`) authentication requests
|
|
8
|
+
- `makeOtpService(alias?)` — issues email challenges and verifies submitted codes; backed by `@owlmeans/auth-otp`
|
|
9
|
+
- Integrates with the `@owlmeans/server-auth` plugin registry — plugs in alongside other auth strategies
|
|
10
10
|
- Resolves identities through `@owlmeans/server-auth-identity` after OTP verification
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
@@ -18,14 +18,26 @@ bun add @owlmeans/server-auth-otp
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
21
|
+
import { makeRedisResource } from '@owlmeans/redis-resource'
|
|
22
|
+
import { OTP_RESOURCE, OTP_SERVICE } from '@owlmeans/auth-otp'
|
|
23
|
+
import { appendOtpPlugin, makeOtpService } from '@owlmeans/server-auth-otp'
|
|
24
|
+
import { MAILER_SERVICE } from '@owlmeans/mailer'
|
|
25
|
+
import { makeSmtpMailerService } from '@owlmeans/mailer-smtp'
|
|
23
26
|
|
|
24
|
-
//
|
|
25
|
-
|
|
27
|
+
context.registerResource(makeRedisResource(OTP_RESOURCE)) // challenge store
|
|
28
|
+
context.registerService(makeSmtpMailerService(MAILER_SERVICE))
|
|
29
|
+
context.registerService(makeOtpService(OTP_SERVICE))
|
|
30
|
+
|
|
31
|
+
appendOtpPlugin(context) // registers the plugin factory under 'email-otp'
|
|
26
32
|
```
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
`appendOtpPlugin` writes into a module-level registry, so it is a global side effect: the
|
|
35
|
+
`context` it takes is only returned for chaining, and the plugin factory receives the live
|
|
36
|
+
context per request.
|
|
37
|
+
|
|
38
|
+
The OTP service must be backed by a transport that can deliver the one-time code —
|
|
39
|
+
`@owlmeans/mailer-smtp` (SMTP) or `@owlmeans/server-mailer-mailgun` (Mailgun HTTP API),
|
|
40
|
+
registered under `MAILER_SERVICE`. Override the alias with `cfg.otp.mailerAlias`.
|
|
29
41
|
|
|
30
42
|
<!-- owlmeans:agent-guidance:start -->
|
|
31
43
|
## Agent guidance
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/server-auth-otp",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"generatedAt": "2026-08-
|
|
4
|
+
"version": "0.1.18-rc.0",
|
|
5
|
+
"generatedAt": "2026-08-16T22:20:50.506Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
package/build/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAmEvD,sGAAsG;AACtG,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,KAAG,CAG1F,CAAA"}
|
package/build/plugin.js
CHANGED
|
@@ -2,6 +2,9 @@ import { ALL_SCOPES, AuthenFailed, AuthRole, AuthenticationType } from '@owlmean
|
|
|
2
2
|
import { registerPlugin } from '@owlmeans/server-auth/manager/plugins';
|
|
3
3
|
import { OTP_AUTH_TYPE, OTP_SERVICE } from '@owlmeans/auth-otp';
|
|
4
4
|
import { AUTH_IDENTITY_LINKING } from '@owlmeans/server-auth-identity';
|
|
5
|
+
import { createIdOfLength, IdStyle } from '@owlmeans/basic-ids';
|
|
6
|
+
// Separates the email from the per-request nonce inside the challenge (see init() below).
|
|
7
|
+
const CHALLENGE_DELIMITER = '::';
|
|
5
8
|
/** Factory that creates the email-OTP AuthPlugin bound to the given context. */
|
|
6
9
|
const otpPlugin = (context) => ({
|
|
7
10
|
type: OTP_AUTH_TYPE,
|
|
@@ -12,12 +15,15 @@ const otpPlugin = (context) => ({
|
|
|
12
15
|
const email = request.userId.trim().toLowerCase();
|
|
13
16
|
const otp = context.service(OTP_SERVICE);
|
|
14
17
|
await otp.issueChallenge(email);
|
|
15
|
-
//
|
|
16
|
-
|
|
18
|
+
// The auth manager's anti-replay cache (AUTH_CACHE) keys on this decoded challenge, so it
|
|
19
|
+
// must be unique per request — the plaintext email alone would be identical across every
|
|
20
|
+
// independent login attempt for that address and collide with a still-cached prior one.
|
|
21
|
+
const nonce = createIdOfLength(16, IdStyle.Base58);
|
|
22
|
+
return { challenge: `${email}${CHALLENGE_DELIMITER}${nonce}` };
|
|
17
23
|
},
|
|
18
24
|
authenticate: async (credential) => {
|
|
19
|
-
// credential.challenge is
|
|
20
|
-
const email = credential.challenge;
|
|
25
|
+
// credential.challenge is "email::nonce" (opened from the signed envelope in makeAuthModel).
|
|
26
|
+
const email = credential.challenge?.split(CHALLENGE_DELIMITER)[0];
|
|
21
27
|
const code = credential.credential;
|
|
22
28
|
if (!email || !email.includes('@')) {
|
|
23
29
|
throw new AuthenFailed('otp:email');
|
package/build/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAEvF,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAEtE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAE/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAEvF,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAEtE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAE/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAG/D,0FAA0F;AAC1F,MAAM,mBAAmB,GAAG,IAAI,CAAA;AAEhC,gFAAgF;AAChF,MAAM,SAAS,GAAG,CAA+C,OAAU,EAAc,EAAE,CAAC,CAAC;IAC3F,IAAI,EAAE,aAAa;IAEnB,IAAI,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE;QACpB,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,YAAY,CAAC,WAAW,CAAC,CAAA;QACrC,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,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22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@owlmeans/auth": "^0.1.
|
|
26
|
-
"@owlmeans/auth-otp": "^0.1.
|
|
27
|
-
"@owlmeans/basic-ids": "^0.1.
|
|
28
|
-
"@owlmeans/context": "^0.1.
|
|
29
|
-
"@owlmeans/mailer": "^0.1.
|
|
30
|
-
"@owlmeans/oidc": "^0.1.
|
|
31
|
-
"@owlmeans/redis-resource": "^0.1.
|
|
32
|
-
"@owlmeans/resource": "^0.1.
|
|
33
|
-
"@owlmeans/server-auth": "^0.1.
|
|
34
|
-
"@owlmeans/server-auth-identity": "^0.1.
|
|
35
|
-
"@owlmeans/server-context": "^0.1.
|
|
25
|
+
"@owlmeans/auth": "^0.1.18-rc.1",
|
|
26
|
+
"@owlmeans/auth-otp": "^0.1.18-rc.1",
|
|
27
|
+
"@owlmeans/basic-ids": "^0.1.18-rc.1",
|
|
28
|
+
"@owlmeans/context": "^0.1.18-rc.1",
|
|
29
|
+
"@owlmeans/mailer": "^0.1.18-rc.1",
|
|
30
|
+
"@owlmeans/oidc": "^0.1.18-rc.1",
|
|
31
|
+
"@owlmeans/redis-resource": "^0.1.18-rc.1",
|
|
32
|
+
"@owlmeans/resource": "^0.1.18-rc.1",
|
|
33
|
+
"@owlmeans/server-auth": "^0.1.18-rc.1",
|
|
34
|
+
"@owlmeans/server-auth-identity": "^0.1.18-rc.1",
|
|
35
|
+
"@owlmeans/server-context": "^0.1.18-rc.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@owlmeans/dep-config": "workspace:*",
|
package/src/plugin.ts
CHANGED
|
@@ -5,8 +5,12 @@ import type { OtpService } from '@owlmeans/auth-otp'
|
|
|
5
5
|
import { OTP_AUTH_TYPE, OTP_SERVICE } from '@owlmeans/auth-otp'
|
|
6
6
|
import type { IdentityLinkingService } from '@owlmeans/server-auth-identity'
|
|
7
7
|
import { AUTH_IDENTITY_LINKING } from '@owlmeans/server-auth-identity'
|
|
8
|
+
import { createIdOfLength, IdStyle } from '@owlmeans/basic-ids'
|
|
8
9
|
import type { OtpConfig, OtpContext } from './types.js'
|
|
9
10
|
|
|
11
|
+
// Separates the email from the per-request nonce inside the challenge (see init() below).
|
|
12
|
+
const CHALLENGE_DELIMITER = '::'
|
|
13
|
+
|
|
10
14
|
/** Factory that creates the email-OTP AuthPlugin bound to the given context. */
|
|
11
15
|
const otpPlugin = <C extends OtpConfig, T extends OtpContext<C>>(context: T): AuthPlugin => ({
|
|
12
16
|
type: OTP_AUTH_TYPE,
|
|
@@ -18,13 +22,16 @@ const otpPlugin = <C extends OtpConfig, T extends OtpContext<C>>(context: T): Au
|
|
|
18
22
|
const email = request.userId.trim().toLowerCase()
|
|
19
23
|
const otp = context.service<OtpService>(OTP_SERVICE)
|
|
20
24
|
await otp.issueChallenge(email)
|
|
21
|
-
//
|
|
22
|
-
|
|
25
|
+
// The auth manager's anti-replay cache (AUTH_CACHE) keys on this decoded challenge, so it
|
|
26
|
+
// must be unique per request — the plaintext email alone would be identical across every
|
|
27
|
+
// independent login attempt for that address and collide with a still-cached prior one.
|
|
28
|
+
const nonce = createIdOfLength(16, IdStyle.Base58)
|
|
29
|
+
return { challenge: `${email}${CHALLENGE_DELIMITER}${nonce}` }
|
|
23
30
|
},
|
|
24
31
|
|
|
25
32
|
authenticate: async credential => {
|
|
26
|
-
// credential.challenge is
|
|
27
|
-
const email = credential.challenge
|
|
33
|
+
// credential.challenge is "email::nonce" (opened from the signed envelope in makeAuthModel).
|
|
34
|
+
const email = credential.challenge?.split(CHALLENGE_DELIMITER)[0]
|
|
28
35
|
const code = credential.credential
|
|
29
36
|
|
|
30
37
|
if (!email || !email.includes('@')) {
|