@jskit-ai/auth-core 0.2.34 → 0.2.36
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
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- `GET /api/oauth/:provider/start` (`auth.login.oauth.start`) takes an optional `invitationToken` query value (at most 2048 characters), the invitation the sign-in starts from, and `authApi.oauthStartUrl(provider, { returnTo, invitationToken })` adds it to the address.
|
|
5
6
|
- **Breaking:** the dev auth policy (`resolveDevAuthPolicy`, `resolveDevAuthPolicyFromEnv`) names whether the application runs in staging or production `isStagingOrProduction`, in place of `isDeployed`. A read of the old field is `undefined`.
|
|
6
7
|
- Email change: `features.emailChange` and three auth.service operations it gates (`AUTH_OPERATION_FEATURES`): `requestEmailChange(request, { email, password })`, the signed-in person's own change; `requestEmailChangeForUser({ userId, email })`, an application's change of an account it chose; and `confirmEmailChange({ token })`, the link sent to the new address. Two actions run them over HTTP and from server code, never automation: `auth.emailChange.request` (signed in) and `auth.emailChange.confirm` (anyone with the link), from `createEmailChangeActions` (`./server/actions/emailChangeActions`), which `AuthFeature` contributes; their commands are `authEmailChangeRequestCommand` and `authEmailChangeConfirmCommand` (`./shared/commands/authEmailChangeCommands`), and their paths `AUTH_PATHS.EMAIL_CHANGE` (`/api/email-change`) and `AUTH_PATHS.EMAIL_CHANGE_CONFIRM` (`/api/email-change/confirm`). Upgrading: every auth provider implements the three operations; one without email change throws `AUTH_OPERATION_UNSUPPORTED`.
|
|
7
8
|
- The actions that sign someone in hand `auth.service` the request they came in on: `auth.register`, `auth.register.confirm`, `auth.login.password` and `auth.password.recovery.complete` call `register`, `confirmRegistration`, `login` and `completePasswordRecovery` with `(input, request)`, the request null for an internal call, as `auth.login.oauth.complete` and `auth.dev.loginAs` already did, so a provider can keep where each session was signed in from. `AuthService` documents the optional second parameter; a provider that ignores it is unchanged.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -149,6 +149,6 @@
|
|
|
149
149
|
}
|
|
150
150
|
},
|
|
151
151
|
"peerDependencies": {
|
|
152
|
-
"@jskit-ai/kernel": "0.2.
|
|
152
|
+
"@jskit-ai/kernel": "0.2.32"
|
|
153
153
|
}
|
|
154
154
|
}
|
package/src/shared/authApi.js
CHANGED
|
@@ -39,17 +39,18 @@ function createApi({ request }) {
|
|
|
39
39
|
return request(AUTH_PATHS.LOGIN_OTP_VERIFY, { method: "POST", body: payload });
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// The provider's start address, with the page to return to and the invitation the sign-in starts from, when given.
|
|
42
43
|
function oauthStartUrl(provider, options = {}) {
|
|
43
44
|
const oauthStartPath = buildAuthOauthStartPath(provider);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
const params = new URLSearchParams();
|
|
46
|
+
for (const name of ["returnTo", "invitationToken"]) {
|
|
47
|
+
const value = String(options[name] || "").trim();
|
|
48
|
+
if (value) {
|
|
49
|
+
params.set(name, value);
|
|
50
|
+
}
|
|
47
51
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
returnTo
|
|
51
|
-
});
|
|
52
|
-
return `${oauthStartPath}?${params.toString()}`;
|
|
52
|
+
const query = params.toString();
|
|
53
|
+
return query ? `${oauthStartPath}?${query}` : oauthStartPath;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
function oauthComplete(payload) {
|
|
@@ -31,7 +31,9 @@ const authLoginOAuthStartParamsValidator = deepFreeze({
|
|
|
31
31
|
|
|
32
32
|
const authLoginOAuthStartQueryValidator = deepFreeze({
|
|
33
33
|
schema: createSchema({
|
|
34
|
-
returnTo: { ...oauthReturnToFieldDefinition, required: false }
|
|
34
|
+
returnTo: { ...oauthReturnToFieldDefinition, required: false },
|
|
35
|
+
// The invitation the sign-in starts from, which the provider's sign-in hands to its end (local auth does).
|
|
36
|
+
invitationToken: { type: "string", required: false, minLength: 1, maxLength: 2048 }
|
|
35
37
|
}),
|
|
36
38
|
mode: "patch",
|
|
37
39
|
messages: AUTH_LOGIN_OAUTH_START_MESSAGES
|
package/test/authApi.test.js
CHANGED
|
@@ -56,4 +56,7 @@ test("authApi oauthStartUrl builds provider path with optional returnTo", () =>
|
|
|
56
56
|
|
|
57
57
|
assert.equal(api.oauthStartUrl("GitHub"), "/api/oauth/github/start");
|
|
58
58
|
assert.equal(api.oauthStartUrl("github", { returnTo: "/console" }), "/api/oauth/github/start?returnTo=%2Fconsole");
|
|
59
|
+
assert.equal(api.oauthStartUrl("github", { returnTo: "/invite/tok", invitationToken: " inv-1 " }),
|
|
60
|
+
"/api/oauth/github/start?returnTo=%2Finvite%2Ftok&invitationToken=inv-1");
|
|
61
|
+
assert.equal(api.oauthStartUrl("github", { invitationToken: "inv-1" }), "/api/oauth/github/start?invitationToken=inv-1");
|
|
59
62
|
});
|
|
@@ -218,3 +218,11 @@ test("auth session and oauth start commands expose explicit nested response sche
|
|
|
218
218
|
assert.equal(oauthStartResponseSchema.properties.returnTo.type, "string");
|
|
219
219
|
assert.equal(oauthStartResponseSchema.properties.url.type, "string");
|
|
220
220
|
});
|
|
221
|
+
|
|
222
|
+
test("oauth start takes the invitation a sign-in starts from, as optional text of at most 2048 characters", () => {
|
|
223
|
+
const query = authLoginOAuthStartCommand.operation.query.schema;
|
|
224
|
+
assert.deepEqual(query.patch({ returnTo: "/invite/tok", invitationToken: "inv-1" }).validatedObject,
|
|
225
|
+
{ returnTo: "/invite/tok", invitationToken: "inv-1" });
|
|
226
|
+
assert.deepEqual(query.patch({ returnTo: "/home" }).errors, {});
|
|
227
|
+
assert.ok(query.patch({ invitationToken: "x".repeat(2049) }).errors.invitationToken, "too long is refused");
|
|
228
|
+
});
|