@owlmeans/server-auth-otp 0.1.18-rc.0 → 0.1.18-rc.2
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/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/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,E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CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,CAAA;QAElD,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;IACtB,CAAC;CACF,CAAC,CAAA;AAEF,sGAAsG;AACtG,MAAM,CAAC,MAAM,eAAe,GAAG,CAA+C,OAAU,EAAK,EAAE;IAC7F,cAAc,CAAC,aAAa,EAAE,SAAiD,CAAC,CAAA;IAChF,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/server-auth-otp",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@owlmeans/auth": "^0.1.18-rc.
|
|
26
|
-
"@owlmeans/auth-otp": "^0.1.18-rc.
|
|
27
|
-
"@owlmeans/basic-ids": "^0.1.18-rc.
|
|
28
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
29
|
-
"@owlmeans/mailer": "^0.1.18-rc.
|
|
30
|
-
"@owlmeans/oidc": "^0.1.18-rc.
|
|
31
|
-
"@owlmeans/redis-resource": "^0.1.18-rc.
|
|
32
|
-
"@owlmeans/resource": "^0.1.18-rc.
|
|
33
|
-
"@owlmeans/server-auth": "^0.1.18-rc.
|
|
34
|
-
"@owlmeans/server-auth-identity": "^0.1.18-rc.
|
|
35
|
-
"@owlmeans/server-context": "^0.1.18-rc.
|
|
25
|
+
"@owlmeans/auth": "^0.1.18-rc.2",
|
|
26
|
+
"@owlmeans/auth-otp": "^0.1.18-rc.2",
|
|
27
|
+
"@owlmeans/basic-ids": "^0.1.18-rc.2",
|
|
28
|
+
"@owlmeans/context": "^0.1.18-rc.2",
|
|
29
|
+
"@owlmeans/mailer": "^0.1.18-rc.2",
|
|
30
|
+
"@owlmeans/oidc": "^0.1.18-rc.2",
|
|
31
|
+
"@owlmeans/redis-resource": "^0.1.18-rc.2",
|
|
32
|
+
"@owlmeans/resource": "^0.1.18-rc.2",
|
|
33
|
+
"@owlmeans/server-auth": "^0.1.18-rc.2",
|
|
34
|
+
"@owlmeans/server-auth-identity": "^0.1.18-rc.2",
|
|
35
|
+
"@owlmeans/server-context": "^0.1.18-rc.2"
|
|
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('@')) {
|