@jskit-ai/auth-provider-oidc-core 0.1.5 → 0.2.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/CHANGELOG.md +51 -0
- package/locales/en.json +31 -0
- package/package.json +7 -6
- package/patterns/oidc-sign-in/example/package.json +2 -2
- package/src/server/lib/config.js +10 -5
- package/src/server/lib/issuer.js +10 -6
- package/src/server/lib/service.js +34 -17
- package/test/i18nCatalog.test.js +16 -0
- package/test/providerRuntime.test.js +2 -0
- package/test/relyingPartySecurity.test.js +6 -2
- package/test/signInFlow.test.js +13 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 - 2026-10-29
|
|
4
|
+
|
|
5
|
+
- Translation ready: every user-visible text is a message key with its English in `locales/en.json`, so an app translates it by supplying translation files only. With no translations, texts and behaviour are unchanged. See the guide "Translating a JSKIT app".
|
|
6
|
+
|
|
7
|
+
### New message keys (15)
|
|
8
|
+
|
|
9
|
+
All keys in `locales/en.json` (exported as `./locales/en.json`) are new in this version.
|
|
10
|
+
|
|
11
|
+
<details><summary>Key list</summary>
|
|
12
|
+
|
|
13
|
+
- `jskit.auth.oidc.setup.issuerMissing`
|
|
14
|
+
- `jskit.auth.oidc.setup.clientMissing`
|
|
15
|
+
- `jskit.auth.oidc.issuer.unreachable`
|
|
16
|
+
- `jskit.auth.oidc.issuer.blocked`
|
|
17
|
+
- `jskit.auth.oidc.issuer.tokenRefused`
|
|
18
|
+
- `jskit.auth.oidc.request.noAddress`
|
|
19
|
+
- `jskit.auth.oidc.request.publicUrlRequired`
|
|
20
|
+
- `jskit.auth.oidc.signIn.providerInvalid`
|
|
21
|
+
- `jskit.auth.oidc.signIn.emailMissing`
|
|
22
|
+
- `jskit.auth.oidc.signIn.emailUnconfirmed`
|
|
23
|
+
- `jskit.auth.oidc.signIn.cancelled`
|
|
24
|
+
- `jskit.auth.oidc.signIn.incomplete`
|
|
25
|
+
- `jskit.auth.oidc.signIn.expired`
|
|
26
|
+
- `jskit.auth.oidc.signIn.codeRequired`
|
|
27
|
+
- `jskit.auth.oidc.signIn.unverified`
|
|
28
|
+
|
|
29
|
+
</details>
|
|
30
|
+
|
|
31
|
+
### Codes (15)
|
|
32
|
+
|
|
33
|
+
Error, field-error and message codes this package sends, with their English. Undotted codes kept their existing values and render from `jskit.errors.<code>`.
|
|
34
|
+
|
|
35
|
+
| Code | English |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `auth.oidc.setup.issuerMissing` | Sign-in is not set up yet: AUTH_OIDC_ISSUER is missing. |
|
|
38
|
+
| `auth.oidc.setup.clientMissing` | Sign-in is not set up yet: set AUTH_OIDC_REGISTRATION_TOKEN, or AUTH_OIDC_CLIENT_ID and AUTH_OIDC_CLIENT_SECRET. |
|
|
39
|
+
| `auth.oidc.issuer.unreachable` | Your accounts hub can't be reached right now. Try again in a moment. |
|
|
40
|
+
| `auth.oidc.issuer.blocked` | Your accounts hub has blocked this app's address. |
|
|
41
|
+
| `auth.oidc.issuer.tokenRefused` | Your accounts hub refused this app's registration token. Check AUTH_OIDC_REGISTRATION_TOKEN. |
|
|
42
|
+
| `auth.oidc.request.noAddress` | This request has no usable address. |
|
|
43
|
+
| `auth.oidc.request.publicUrlRequired` | Set APP_PUBLIC_URL so sign-in returns to this app's https address. |
|
|
44
|
+
| `auth.oidc.signIn.providerInvalid` | OAuth provider must be {provider}. |
|
|
45
|
+
| `auth.oidc.signIn.emailMissing` | Your account provider did not share an email address. |
|
|
46
|
+
| `auth.oidc.signIn.emailUnconfirmed` | Your account provider has not confirmed your email address yet. Confirm it there, then sign in again. |
|
|
47
|
+
| `auth.oidc.signIn.cancelled` | Sign-in was cancelled. |
|
|
48
|
+
| `auth.oidc.signIn.incomplete` | Sign-in was not completed. Start again. |
|
|
49
|
+
| `auth.oidc.signIn.expired` | This sign-in took too long or started in another browser. Start again. |
|
|
50
|
+
| `auth.oidc.signIn.codeRequired` | OAuth code is required. |
|
|
51
|
+
| `auth.oidc.signIn.unverified` | Your sign-in could not be verified. Start again. |
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jskit": {
|
|
3
|
+
"auth": {
|
|
4
|
+
"oidc": {
|
|
5
|
+
"setup": {
|
|
6
|
+
"issuerMissing": "Sign-in is not set up yet: AUTH_OIDC_ISSUER is missing.",
|
|
7
|
+
"clientMissing": "Sign-in is not set up yet: set AUTH_OIDC_REGISTRATION_TOKEN, or AUTH_OIDC_CLIENT_ID and AUTH_OIDC_CLIENT_SECRET."
|
|
8
|
+
},
|
|
9
|
+
"issuer": {
|
|
10
|
+
"unreachable": "Your accounts hub can't be reached right now. Try again in a moment.",
|
|
11
|
+
"blocked": "Your accounts hub has blocked this app's address.",
|
|
12
|
+
"tokenRefused": "Your accounts hub refused this app's registration token. Check AUTH_OIDC_REGISTRATION_TOKEN."
|
|
13
|
+
},
|
|
14
|
+
"request": {
|
|
15
|
+
"noAddress": "This request has no usable address.",
|
|
16
|
+
"publicUrlRequired": "Set APP_PUBLIC_URL so sign-in returns to this app's https address."
|
|
17
|
+
},
|
|
18
|
+
"signIn": {
|
|
19
|
+
"providerInvalid": "OAuth provider must be {provider}.",
|
|
20
|
+
"emailMissing": "Your account provider did not share an email address.",
|
|
21
|
+
"emailUnconfirmed": "Your account provider has not confirmed your email address yet. Confirm it there, then sign in again.",
|
|
22
|
+
"cancelled": "Sign-in was cancelled.",
|
|
23
|
+
"incomplete": "Sign-in was not completed. Start again.",
|
|
24
|
+
"expired": "This sign-in took too long or started in another browser. Start again.",
|
|
25
|
+
"codeRequired": "OAuth code is required.",
|
|
26
|
+
"unverified": "Your sign-in could not be verified. Start again."
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-provider-oidc-core",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
"./server/providers/AuthOidcProvider": "./src/server/providers/AuthOidcProvider.js",
|
|
10
10
|
"./server/lib/index": "./src/server/lib/index.js",
|
|
11
|
-
"./shared": "./src/shared/index.js"
|
|
11
|
+
"./shared": "./src/shared/index.js",
|
|
12
|
+
"./locales/en.json": "./locales/en.json"
|
|
12
13
|
},
|
|
13
14
|
"bin": {
|
|
14
15
|
"jskit-oidc-sign-in": "./bin/jskit-oidc-sign-in.js"
|
|
@@ -19,8 +20,8 @@
|
|
|
19
20
|
"openid-client": "6.8.8"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"@jskit-ai/auth-provider-local-core": "0.1
|
|
23
|
-
"@jskit-ai/auth-web": "0.1
|
|
23
|
+
"@jskit-ai/auth-provider-local-core": "0.2.1",
|
|
24
|
+
"@jskit-ai/auth-web": "0.2.1",
|
|
24
25
|
"oidc-provider": "9.12.2"
|
|
25
26
|
},
|
|
26
27
|
"description": "Sign in through any OpenID Connect issuer: self-registration or a static client, app-owned sessions, and back-channel logout.",
|
|
@@ -90,7 +91,7 @@
|
|
|
90
91
|
}
|
|
91
92
|
},
|
|
92
93
|
"peerDependencies": {
|
|
93
|
-
"@jskit-ai/auth-core": "0.1
|
|
94
|
-
"@jskit-ai/kernel": "0.1
|
|
94
|
+
"@jskit-ai/auth-core": "0.2.1",
|
|
95
|
+
"@jskit-ai/kernel": "0.2.1"
|
|
95
96
|
}
|
|
96
97
|
}
|
package/src/server/lib/config.js
CHANGED
|
@@ -93,10 +93,14 @@ function resolveOidcConfig({ env = {}, appRoot = process.cwd() } = {}) {
|
|
|
93
93
|
const devAuth = resolveDevAuthPolicyFromEnv(env);
|
|
94
94
|
assertDevAuthPolicy(devAuth);
|
|
95
95
|
|
|
96
|
-
let setupProblem =
|
|
97
|
-
if (!issuer)
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
let setupProblem = null;
|
|
97
|
+
if (!issuer) {
|
|
98
|
+
setupProblem = { code: "auth.oidc.setup.issuerMissing", message: "Sign-in is not set up yet: AUTH_OIDC_ISSUER is missing." };
|
|
99
|
+
} else if (!registrationToken && !clientId) {
|
|
100
|
+
setupProblem = {
|
|
101
|
+
code: "auth.oidc.setup.clientMissing",
|
|
102
|
+
message: "Sign-in is not set up yet: set AUTH_OIDC_REGISTRATION_TOKEN, or AUTH_OIDC_CLIENT_ID and AUTH_OIDC_CLIENT_SECRET."
|
|
103
|
+
};
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
return Object.freeze({
|
|
@@ -109,7 +113,8 @@ function resolveOidcConfig({ env = {}, appRoot = process.cwd() } = {}) {
|
|
|
109
113
|
appPublicOrigin,
|
|
110
114
|
sessionSecret: resolveSessionSecret(env, { appRoot, isProduction }),
|
|
111
115
|
devAuth,
|
|
112
|
-
setupProblem
|
|
116
|
+
setupProblem: setupProblem?.message || "",
|
|
117
|
+
setupProblemCode: setupProblem?.code || ""
|
|
113
118
|
});
|
|
114
119
|
}
|
|
115
120
|
|
package/src/server/lib/issuer.js
CHANGED
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
import { isLoopbackHostname } from "./config.js";
|
|
8
8
|
|
|
9
9
|
const DISCOVERY_TTL_MS = 60 * 60 * 1000;
|
|
10
|
-
const BLOCKED_MESSAGE = "Your accounts hub has blocked this app's address.";
|
|
11
|
-
const UNREACHABLE_MESSAGE = "Your accounts hub can't be reached right now. Try again in a moment.";
|
|
12
10
|
|
|
13
11
|
function registrationMetadata(origin, appName) {
|
|
14
12
|
return {
|
|
@@ -25,7 +23,9 @@ function registrationMetadata(origin, appName) {
|
|
|
25
23
|
function unreachable(error, logger) {
|
|
26
24
|
if (error instanceof AppError) return error;
|
|
27
25
|
logger?.warn?.({ err: error }, "OIDC issuer request failed.");
|
|
28
|
-
return new AppError(503,
|
|
26
|
+
return new AppError(503, "Your accounts hub can't be reached right now. Try again in a moment.", {
|
|
27
|
+
code: "auth.oidc.issuer.unreachable"
|
|
28
|
+
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -77,9 +77,13 @@ function createIssuerClient({ config, store, logger = null, fetchImpl = null, no
|
|
|
77
77
|
});
|
|
78
78
|
} catch (error) {
|
|
79
79
|
// An accounts hub refuses an address its owner blocked with 403.
|
|
80
|
-
if (error?.status === 403)
|
|
80
|
+
if (error?.status === 403) {
|
|
81
|
+
throw new AppError(403, "Your accounts hub has blocked this app's address.", { code: "auth.oidc.issuer.blocked" });
|
|
82
|
+
}
|
|
81
83
|
if (error?.status === 401 || String(error?.error || "") === "invalid_token") {
|
|
82
|
-
throw new AppError(503, "Your accounts hub refused this app's registration token. Check AUTH_OIDC_REGISTRATION_TOKEN."
|
|
84
|
+
throw new AppError(503, "Your accounts hub refused this app's registration token. Check AUTH_OIDC_REGISTRATION_TOKEN.", {
|
|
85
|
+
code: "auth.oidc.issuer.tokenRefused"
|
|
86
|
+
});
|
|
83
87
|
}
|
|
84
88
|
throw unreachable(error, logger);
|
|
85
89
|
}
|
|
@@ -99,7 +103,7 @@ function createIssuerClient({ config, store, logger = null, fetchImpl = null, no
|
|
|
99
103
|
* still waiting for approval signs in to the hub's own waiting page.
|
|
100
104
|
*/
|
|
101
105
|
async function clientFor(origin, { appName = "App" } = {}) {
|
|
102
|
-
if (config.setupProblem) throw new AppError(503, config.setupProblem);
|
|
106
|
+
if (config.setupProblem) throw new AppError(503, config.setupProblem, { code: config.setupProblemCode });
|
|
103
107
|
if (config.staticClient) return { clientId: config.staticClient.clientId, clientSecret: config.staticClient.clientSecret };
|
|
104
108
|
return (await store.findClient(config.issuer, origin)) || register(origin, appName);
|
|
105
109
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "@jskit-ai/auth-core/server/devAuth";
|
|
10
10
|
import { hostOnlyCookieName, normalizeEmail, normalizeReturnToPath } from "@jskit-ai/auth-core/server/utils";
|
|
11
11
|
import { throwUnsupportedAuthOperation } from "@jskit-ai/auth-core/server/unsupportedOperation";
|
|
12
|
+
import { AUTH_TEXTS, authFieldErrorDetails, createAuthError } from "@jskit-ai/auth-core/server/authTexts";
|
|
12
13
|
import { AUTH_OIDC_PROVIDER_ID, AUTH_OIDC_REDIRECT_PATH } from "../../shared/index.js";
|
|
13
14
|
import { isLoopbackHostname } from "./config.js";
|
|
14
15
|
import {
|
|
@@ -21,10 +22,6 @@ const SESSION_COOKIE = "jskit_oidc_session";
|
|
|
21
22
|
const SESSION_TTL_SECONDS = 60 * 60 * 24 * 30;
|
|
22
23
|
const DEV_AUTH_SESSION_PURPOSE = "dev-auth";
|
|
23
24
|
const SIGN_IN_SCOPE = "openid email profile";
|
|
24
|
-
const EXPIRED_ATTEMPT_MESSAGE = "This sign-in took too long or started in another browser. Start again.";
|
|
25
|
-
const UNVERIFIED_MESSAGE = "Your sign-in could not be verified. Start again.";
|
|
26
|
-
const UNCONFIRMED_EMAIL_MESSAGE =
|
|
27
|
-
"Your account provider has not confirmed your email address yet. Confirm it there, then sign in again.";
|
|
28
25
|
|
|
29
26
|
function sha256(value) {
|
|
30
27
|
return createHash("sha256").update(value).digest("base64url");
|
|
@@ -159,10 +156,12 @@ function createOidcAuthService({ config, store, issuer, profileProjector = null,
|
|
|
159
156
|
try {
|
|
160
157
|
origin = new URL(`${https ? "https" : "http"}://${host}`);
|
|
161
158
|
} catch {
|
|
162
|
-
throw new AppError(400, "This request has no usable address.");
|
|
159
|
+
throw new AppError(400, "This request has no usable address.", { code: "auth.oidc.request.noAddress" });
|
|
163
160
|
}
|
|
164
161
|
if (origin.protocol === "http:" && !isLoopbackHostname(origin.hostname) && config.isProduction) {
|
|
165
|
-
throw new AppError(400, "Set APP_PUBLIC_URL so sign-in returns to this app's https address."
|
|
162
|
+
throw new AppError(400, "Set APP_PUBLIC_URL so sign-in returns to this app's https address.", {
|
|
163
|
+
code: "auth.oidc.request.publicUrlRequired"
|
|
164
|
+
});
|
|
166
165
|
}
|
|
167
166
|
return origin.origin;
|
|
168
167
|
}
|
|
@@ -170,7 +169,10 @@ function createOidcAuthService({ config, store, issuer, profileProjector = null,
|
|
|
170
169
|
async function oauthStart(input = {}, request = null) {
|
|
171
170
|
const provider = String(input.provider || AUTH_OIDC_PROVIDER_ID).trim().toLowerCase();
|
|
172
171
|
if (provider !== AUTH_OIDC_PROVIDER_ID) {
|
|
173
|
-
throw new AppError(400, `OAuth provider must be ${AUTH_OIDC_PROVIDER_ID}
|
|
172
|
+
throw new AppError(400, `OAuth provider must be ${AUTH_OIDC_PROVIDER_ID}.`, {
|
|
173
|
+
code: "auth.oidc.signIn.providerInvalid",
|
|
174
|
+
params: { provider: AUTH_OIDC_PROVIDER_ID }
|
|
175
|
+
});
|
|
174
176
|
}
|
|
175
177
|
const returnTo = normalizeReturnToPath(input.returnTo, { fallback: "/" });
|
|
176
178
|
const origin = requestOrigin(request);
|
|
@@ -210,23 +212,35 @@ function createOidcAuthService({ config, store, issuer, profileProjector = null,
|
|
|
210
212
|
source = await client.fetchUserInfo(configuration, tokens.access_token, claims.sub);
|
|
211
213
|
email = normalizeEmail(source.email);
|
|
212
214
|
}
|
|
213
|
-
if (!email)
|
|
215
|
+
if (!email) {
|
|
216
|
+
throw new AppError(401, "Your account provider did not share an email address.", { code: "auth.oidc.signIn.emailMissing" });
|
|
217
|
+
}
|
|
214
218
|
// Apps trust this address (invitations match it), so an issuer's explicit
|
|
215
219
|
// "not confirmed" stops the sign-in. Issuers that never send the claim pass.
|
|
216
|
-
if (source.email_verified === false)
|
|
220
|
+
if (source.email_verified === false) {
|
|
221
|
+
throw new AppError(401, "Your account provider has not confirmed your email address yet. Confirm it there, then sign in again.", {
|
|
222
|
+
code: "auth.oidc.signIn.emailUnconfirmed"
|
|
223
|
+
});
|
|
224
|
+
}
|
|
217
225
|
return { sub: String(claims.sub), email, displayName: displayNameFrom(source, email), sid: String(claims.sid || "") };
|
|
218
226
|
}
|
|
219
227
|
|
|
220
228
|
async function oauthComplete(input = {}, request = null) {
|
|
221
229
|
const errorCode = String(input.error || input.error_code || "").trim();
|
|
222
230
|
if (errorCode) {
|
|
223
|
-
throw
|
|
231
|
+
throw errorCode === "access_denied"
|
|
232
|
+
? new AppError(401, "Sign-in was cancelled.", { code: "auth.oidc.signIn.cancelled" })
|
|
233
|
+
: new AppError(401, "Sign-in was not completed. Start again.", { code: "auth.oidc.signIn.incomplete" });
|
|
224
234
|
}
|
|
225
235
|
const attempt = sealer.open(cookiesOf(request)[TRANSACTION_COOKIE]);
|
|
226
236
|
const state = String(input.state || "");
|
|
227
|
-
if (!attempt || !state || state !== attempt.state)
|
|
237
|
+
if (!attempt || !state || state !== attempt.state) {
|
|
238
|
+
throw new AppError(400, "This sign-in took too long or started in another browser. Start again.", {
|
|
239
|
+
code: "auth.oidc.signIn.expired"
|
|
240
|
+
});
|
|
241
|
+
}
|
|
228
242
|
const code = String(input.code || "").trim();
|
|
229
|
-
if (!code) throw new AppError(400, "OAuth code is required.");
|
|
243
|
+
if (!code) throw new AppError(400, "OAuth code is required.", { code: "auth.oidc.signIn.codeRequired" });
|
|
230
244
|
|
|
231
245
|
const configuration = await issuer.configurationForOrigin(attempt.origin, { appName: config.appName });
|
|
232
246
|
const callback = new URL(`${attempt.origin}${AUTH_OIDC_REDIRECT_PATH}`);
|
|
@@ -243,7 +257,7 @@ function createOidcAuthService({ config, store, issuer, profileProjector = null,
|
|
|
243
257
|
});
|
|
244
258
|
} catch (error) {
|
|
245
259
|
logger?.warn?.({ err: { name: error?.name, code: error?.code, message: error?.message } }, "OIDC sign-in was rejected.");
|
|
246
|
-
throw new AppError(401,
|
|
260
|
+
throw new AppError(401, "Your sign-in could not be verified. Start again.", { code: "auth.oidc.signIn.unverified" });
|
|
247
261
|
}
|
|
248
262
|
const identity = await identityFromTokens(configuration, tokens);
|
|
249
263
|
const session = await createSession(identity, {
|
|
@@ -291,16 +305,19 @@ function createOidcAuthService({ config, store, issuer, profileProjector = null,
|
|
|
291
305
|
const userId = String(input?.userId || "").trim();
|
|
292
306
|
const email = normalizeEmail(input?.email);
|
|
293
307
|
if (!userId && !email) {
|
|
294
|
-
throw
|
|
295
|
-
details: {
|
|
308
|
+
throw createAuthError(AUTH_TEXTS.devUserRequired, {
|
|
309
|
+
details: authFieldErrorDetails({ userId: AUTH_TEXTS.devUserRequired, email: AUTH_TEXTS.devUserRequired })
|
|
296
310
|
});
|
|
297
311
|
}
|
|
298
312
|
const known = await store.findKnownUser(AUTH_OIDC_PROVIDER_ID, { userId, email });
|
|
299
313
|
const identity = known ? { sub: known.sub, email: known.email, displayName: known.displayName } : null;
|
|
300
314
|
const appProfile = identity ? await existingProfile(identity) : null;
|
|
301
315
|
if (!identity || (profileProjector && !appProfile)) {
|
|
302
|
-
throw
|
|
303
|
-
details:
|
|
316
|
+
throw createAuthError(AUTH_TEXTS.devUserNotFound, {
|
|
317
|
+
details: authFieldErrorDetails({
|
|
318
|
+
...(userId ? { userId: AUTH_TEXTS.devUserNotFound } : {}),
|
|
319
|
+
...(email ? { email: AUTH_TEXTS.devUserNotFound } : {})
|
|
320
|
+
})
|
|
304
321
|
});
|
|
305
322
|
}
|
|
306
323
|
const session = await createSession(identity, { purpose: DEV_AUTH_SESSION_PURPOSE });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { evaluateI18nCatalogContract } from "../../../tooling/test-support/i18nCatalogContract.mjs";
|
|
6
|
+
|
|
7
|
+
const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const REPO_ROOT = path.resolve(TEST_DIRECTORY, "..", "..", "..");
|
|
9
|
+
|
|
10
|
+
test("auth-provider-oidc-core English catalog matches its source", () => {
|
|
11
|
+
const { problems } = evaluateI18nCatalogContract({
|
|
12
|
+
repoRoot: REPO_ROOT,
|
|
13
|
+
packageDir: path.join(REPO_ROOT, "packages", "auth-provider-oidc-core")
|
|
14
|
+
});
|
|
15
|
+
assert.deepEqual(problems, []);
|
|
16
|
+
});
|
|
@@ -158,6 +158,8 @@ test("a sign-in that cannot start is explained on the login page", async (t) =>
|
|
|
158
158
|
const explained = new URL(reply.redirectedTo, "http://localhost:5173");
|
|
159
159
|
assert.equal(explained.pathname, "/auth/login");
|
|
160
160
|
assert.equal(explained.searchParams.get("error_description"), "Sign-in is not set up yet: AUTH_OIDC_ISSUER is missing.");
|
|
161
|
+
assert.equal(explained.searchParams.get("error_code"), "auth.oidc.setup.issuerMissing");
|
|
162
|
+
assert.equal(explained.searchParams.get("error_params"), null);
|
|
161
163
|
assert.equal(reply.cookies.jskit_oidc_attempt, undefined);
|
|
162
164
|
});
|
|
163
165
|
|
|
@@ -6,8 +6,12 @@ import { BACKCHANNEL_LOGOUT_EVENT } from "../src/server/lib/backchannelLogout.js
|
|
|
6
6
|
import { startMockIssuer } from "../test-support/mockIssuer.js";
|
|
7
7
|
import { APP_ORIGIN, createRelyingParty, requestAt, signInAtIssuer } from "../test-support/harness.js";
|
|
8
8
|
|
|
9
|
-
const VERIFY_FAILED = { statusCode: 401, message: "Your sign-in could not be verified. Start again." };
|
|
10
|
-
const ATTEMPT_MISMATCH = {
|
|
9
|
+
const VERIFY_FAILED = { statusCode: 401, message: "Your sign-in could not be verified. Start again.", code: "auth.oidc.signIn.unverified" };
|
|
10
|
+
const ATTEMPT_MISMATCH = {
|
|
11
|
+
statusCode: 400,
|
|
12
|
+
message: "This sign-in took too long or started in another browser. Start again.",
|
|
13
|
+
code: "auth.oidc.signIn.expired"
|
|
14
|
+
};
|
|
11
15
|
|
|
12
16
|
// Re-signs the issuer's ID token with changed claims, as a hostile token endpoint would.
|
|
13
17
|
function tamperingFetch(issuer, change) {
|
package/test/signInFlow.test.js
CHANGED
|
@@ -78,7 +78,7 @@ test("an address the hub blocked is explained", async (t) => {
|
|
|
78
78
|
});
|
|
79
79
|
await assert.rejects(
|
|
80
80
|
rp.service.oauthStart({ provider: "oidc" }, requestAt()),
|
|
81
|
-
{ statusCode: 403, message: "Your accounts hub has blocked this app's address." }
|
|
81
|
+
{ statusCode: 403, message: "Your accounts hub has blocked this app's address.", code: "auth.oidc.issuer.blocked" }
|
|
82
82
|
);
|
|
83
83
|
assert.equal((await rp.knex("auth_oidc_clients").count({ count: "*" }))[0].count, 0);
|
|
84
84
|
});
|
|
@@ -92,7 +92,8 @@ test("a wrong registration token is explained", async (t) => {
|
|
|
92
92
|
});
|
|
93
93
|
await assert.rejects(rp.service.oauthStart({ provider: "oidc" }, requestAt()), {
|
|
94
94
|
statusCode: 503,
|
|
95
|
-
message: "Your accounts hub refused this app's registration token. Check AUTH_OIDC_REGISTRATION_TOKEN."
|
|
95
|
+
message: "Your accounts hub refused this app's registration token. Check AUTH_OIDC_REGISTRATION_TOKEN.",
|
|
96
|
+
code: "auth.oidc.issuer.tokenRefused"
|
|
96
97
|
});
|
|
97
98
|
});
|
|
98
99
|
|
|
@@ -152,7 +153,8 @@ test("a missing issuer leaves the app running and explains what to set", async (
|
|
|
152
153
|
});
|
|
153
154
|
await assert.rejects(rp.service.oauthStart({ provider: "oidc" }, requestAt()), {
|
|
154
155
|
statusCode: 503,
|
|
155
|
-
message: "Sign-in is not set up yet: AUTH_OIDC_ISSUER is missing."
|
|
156
|
+
message: "Sign-in is not set up yet: AUTH_OIDC_ISSUER is missing.",
|
|
157
|
+
code: "auth.oidc.setup.issuerMissing"
|
|
156
158
|
});
|
|
157
159
|
});
|
|
158
160
|
|
|
@@ -167,7 +169,14 @@ test("preview identity signs in as an existing oidc users row only", async (t) =
|
|
|
167
169
|
await issuer.close();
|
|
168
170
|
});
|
|
169
171
|
const previewRequest = { ...requestAt(), headers: { host: "localhost:5173", "x-jskit-dev-auth-secret": "preview-secret-0123456789abcdef" } };
|
|
170
|
-
await assert.rejects(rp.service.devLoginAs(previewRequest, { email: issuer.account.email }), {
|
|
172
|
+
await assert.rejects(rp.service.devLoginAs(previewRequest, { email: issuer.account.email }), {
|
|
173
|
+
message: "User not found.",
|
|
174
|
+
code: "auth.dev.userNotFound",
|
|
175
|
+
details: {
|
|
176
|
+
fieldErrors: { email: "User not found." },
|
|
177
|
+
fieldErrorCodes: { email: { code: "auth.dev.userNotFound", params: {} } }
|
|
178
|
+
}
|
|
179
|
+
});
|
|
171
180
|
|
|
172
181
|
const { input, request } = await signInAtIssuer(rp);
|
|
173
182
|
await rp.service.oauthComplete(input, request);
|