@manta-eu/auth 0.2.0 → 0.3.0
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
CHANGED
|
@@ -140,7 +140,9 @@ const tokenFor = (userId: string) => {
|
|
|
140
140
|
};
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
A visitor works the same way,
|
|
143
|
+
A visitor works the same way, with `anonymousId` in place of `userId`: a random id you keep for them, such as one in a
|
|
144
|
+
cookie or in your session, following the same rule of 1 to 128 letters, digits or `- _ . @ |`. Give exactly one of the
|
|
145
|
+
two. The same `anonymousId` brings back that visitor's chats, so keep it private.
|
|
144
146
|
|
|
145
147
|
It sends the app's secret, so it runs on the app's server only; the token it returns may go to the
|
|
146
148
|
browser. `datastores` narrows the token to some of the datastores the app reaches. `teams` places
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-app-user-token.d.ts","sourceRoot":"","sources":["../src/custom-app-user-token.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"custom-app-user-token.d.ts","sourceRoot":"","sources":["../src/custom-app-user-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,oBAAoB,EAE1B,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,KAAK,SAAS,EAAyC,MAAM,WAAW,CAAC;AAElF,MAAM,MAAM,sBAAsB,GAAG;IACnC,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,gGAAgG;AAChG,MAAM,MAAM,uBAAuB,GAAG,sBAAsB,GAC1D,oBAAoB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEjE,kHAAkH;AAClH,MAAM,MAAM,yBAAyB,GAAG,sBAAsB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEzG,MAAM,MAAM,+BAA+B,GAAG,uBAAuB,GAAG,yBAAyB,CAAC;AAyBlG;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,+BAA+B,EACxC,SAAS,GAAE,SAAiB,GAC3B,OAAO,CAAC,MAAM,CAAC,CAyCjB"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { customAppClientIdProblem, customAppUserDatastoresProblem, customAppUserIdProblem, customAppUserProfileProblem, customAppUserTeamsProblem, customAppUserTokenPath, } from "@manta-eu/lib/custom-app";
|
|
1
|
+
import { anonymousVisitorIdName, customAppClientIdProblem, customAppUserDatastoresProblem, customAppUserIdProblem, customAppUserProfileProblem, customAppUserTeamsProblem, customAppUserTokenPath, } from "@manta-eu/lib/custom-app";
|
|
2
2
|
import { isPresent } from "@manta-eu/lib/present";
|
|
3
3
|
import { defaultDeployment } from "./default-deployment.js";
|
|
4
4
|
import { postTo, readJson, RefusedRequestError } from "./http.js";
|
|
5
|
+
// Blank ids count as absent, as Manta reads them.
|
|
6
|
+
function isVisitor(options) {
|
|
7
|
+
return isPresent(options.anonymousId);
|
|
8
|
+
}
|
|
5
9
|
function requestFor(options) {
|
|
6
10
|
const { clientId, clientSecret, datastores, teams } = options;
|
|
7
11
|
const narrowed = { ...(datastores === undefined ? {} : { datastores }), ...(teams === undefined ? {} : { teams }) };
|
|
8
|
-
if (options
|
|
12
|
+
if (isVisitor(options)) {
|
|
9
13
|
return { client_id: clientId, client_secret: clientSecret, anonymous_id: options.anonymousId, ...narrowed };
|
|
10
14
|
}
|
|
11
15
|
const { userId, name, email, fields } = options;
|
|
@@ -32,10 +36,15 @@ export async function customAppUserAccessToken(options, fetchImpl = fetch) {
|
|
|
32
36
|
throw new Error(clientIdProblem);
|
|
33
37
|
if (!isPresent(options.clientSecret))
|
|
34
38
|
throw new Error("The app's client secret is required");
|
|
35
|
-
|
|
39
|
+
if (isPresent(options.userId) === isPresent(options.anonymousId)) {
|
|
40
|
+
throw new Error("Give exactly one of userId, for a person your app knows, and anonymousId, for a visitor");
|
|
41
|
+
}
|
|
42
|
+
const problem = (isVisitor(options)
|
|
43
|
+
? customAppUserIdProblem(options.anonymousId, anonymousVisitorIdName)
|
|
44
|
+
: customAppUserIdProblem(options.userId)) ??
|
|
36
45
|
customAppUserDatastoresProblem(options.datastores) ??
|
|
37
46
|
customAppUserTeamsProblem(options.teams) ??
|
|
38
|
-
(options
|
|
47
|
+
(isVisitor(options) ? undefined : customAppUserProfileProblem(options));
|
|
39
48
|
if (problem !== undefined)
|
|
40
49
|
throw new Error(problem);
|
|
41
50
|
const endpoint = new URL(customAppUserTokenPath, options.apiUrl ?? defaultDeployment.apiUrl).toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-app-user-token.js","sourceRoot":"","sources":["../src/custom-app-user-token.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,8BAA8B,EAC9B,sBAAsB,EACtB,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,GAGvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAkB,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AA0BlF,SAAS,UAAU,CAAC,OAAwC;IAC1D,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC9D,MAAM,QAAQ,GAAG,EAAE,GAAG,CAAC,UAAU,KAAK,SAAS,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,QAAQ,CAAC,CAAC;IAC3E,IAAI,OAAO,IAAI,CAAC,YAAY,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACrG,OAAO,IAAI,CAAC,YAAY,CAAC;AAC3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manta-eu/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Keycloak login for the SDK CLIs: browser and device-code login, silent token renewal, and credential storage; plus the default deployment the SDK targets",
|
|
5
5
|
"homepage": "https://developers.manta.eu",
|
|
6
6
|
"keywords": [
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"commander": "^15.0.0",
|
|
32
32
|
"jose": "^6.2.12",
|
|
33
33
|
"openid-client": "^6.8.8",
|
|
34
|
-
"@manta-eu/lib": "0.
|
|
34
|
+
"@manta-eu/lib": "0.3.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^24.13.3",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
anonymousVisitorIdName,
|
|
2
3
|
customAppClientIdProblem,
|
|
3
4
|
customAppUserDatastoresProblem,
|
|
4
5
|
customAppUserIdProblem,
|
|
@@ -36,10 +37,15 @@ export type AnonymousCustomAppVisitor = CustomAppUserGrantBase & { anonymousId:
|
|
|
36
37
|
|
|
37
38
|
export type CustomAppUserAccessTokenOptions = IdentifiedCustomAppUser | AnonymousCustomAppVisitor;
|
|
38
39
|
|
|
40
|
+
// Blank ids count as absent, as Manta reads them.
|
|
41
|
+
function isVisitor(options: CustomAppUserAccessTokenOptions): options is AnonymousCustomAppVisitor {
|
|
42
|
+
return isPresent(options.anonymousId);
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
function requestFor(options: CustomAppUserAccessTokenOptions): CustomAppUserTokenRequest {
|
|
40
46
|
const { clientId, clientSecret, datastores, teams } = options;
|
|
41
47
|
const narrowed = { ...(datastores === undefined ? {} : { datastores }), ...(teams === undefined ? {} : { teams }) };
|
|
42
|
-
if (options
|
|
48
|
+
if (isVisitor(options)) {
|
|
43
49
|
return { client_id: clientId, client_secret: clientSecret, anonymous_id: options.anonymousId, ...narrowed };
|
|
44
50
|
}
|
|
45
51
|
const { userId, name, email, fields } = options;
|
|
@@ -68,11 +74,16 @@ export async function customAppUserAccessToken(
|
|
|
68
74
|
const clientIdProblem = customAppClientIdProblem(options.clientId);
|
|
69
75
|
if (clientIdProblem !== undefined) throw new Error(clientIdProblem);
|
|
70
76
|
if (!isPresent(options.clientSecret)) throw new Error("The app's client secret is required");
|
|
77
|
+
if (isPresent(options.userId) === isPresent(options.anonymousId)) {
|
|
78
|
+
throw new Error("Give exactly one of userId, for a person your app knows, and anonymousId, for a visitor");
|
|
79
|
+
}
|
|
71
80
|
const problem =
|
|
72
|
-
|
|
81
|
+
(isVisitor(options)
|
|
82
|
+
? customAppUserIdProblem(options.anonymousId, anonymousVisitorIdName)
|
|
83
|
+
: customAppUserIdProblem(options.userId)) ??
|
|
73
84
|
customAppUserDatastoresProblem(options.datastores) ??
|
|
74
85
|
customAppUserTeamsProblem(options.teams) ??
|
|
75
|
-
(options
|
|
86
|
+
(isVisitor(options) ? undefined : customAppUserProfileProblem(options));
|
|
76
87
|
if (problem !== undefined) throw new Error(problem);
|
|
77
88
|
|
|
78
89
|
const endpoint = new URL(customAppUserTokenPath, options.apiUrl ?? defaultDeployment.apiUrl).toString();
|