@amedia/user 1.10.4 → 1.11.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @amedia/user
2
2
 
3
+ ## 1.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1353](https://github.com/amedia/amedia-user-js/pull/1353) [`856dee3`](https://github.com/amedia/amedia-user-js/commit/856dee37aca51a045585deda519974212b3aab75) Thanks [@hennikul](https://github.com/hennikul)! - `logout()` now ends by passing through aID's logout handover, so the browser learns the reader is logged out and FedCM stops prompting them to sign in to aid.no. It lands on the current page, or on `logout({ requestedUrl })`, and its promise no longer resolves when the page navigates: **callers that reload or redirect after `await logout()` should drop that code**, or pass their target as `requestedUrl`. `ON_LOGGED_OUT` still fires, before the page leaves. A FedCM sign-in that aID refuses for the account the browser had — typically an unapproved service provider — now falls back to the ordinary redirect login, at most once every 15 minutes, and never where storage cannot hold that limit. `logoutHandoverUrl` is exported from `@amedia/user/node` for server-side logouts; it throws on anything but a bare aID host and an absolute `https:` address.
8
+
9
+ ## 1.10.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1270](https://github.com/amedia/amedia-user-js/pull/1270) [`b135b38`](https://github.com/amedia/amedia-user-js/commit/b135b3850658981760d3d33a6fb15f72e0ed2414) Thanks [@dependabot](https://github.com/apps/dependabot)! - Upgrade jose to 6.2.16 for token validation in `@amedia/user/node`. jose 6 is ESM-only.
14
+
3
15
  ## 1.10.4
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -61,6 +61,8 @@ Available node exports:
61
61
  - `validateToken` — JWT verification with JWKS caching.
62
62
  - `createAidClient({ baseUrl, token })` — server-side aID HTTP client.
63
63
  - `createShamoClient({ baseUrl, token })` — server-side shamo HTTP client.
64
+ - `logoutHandoverUrl(aidDomain, requestedUrl)` — where to redirect a reader after a server-side logout, so the browser
65
+ learns they are logged out.
64
66
  - Shared types: `UserAttributes`, `ServiceUser`, `LoginStatus`, `PrimarySite`, etc.
65
67
  - Shared exceptions: `ProblemJsonError`, `ResponseError`, `ValidationError`, ...
66
68
 
@@ -381,11 +383,13 @@ callback will be executed if anything changes.
381
383
 
382
384
  **Note**: A data refresh will be automatically performed every time the page regains focus (eg. user switches tabs)
383
385
 
384
- ### `logout(): Promise<void>`
386
+ ### `logout({ requestedUrl }?): Promise<void>`
385
387
 
386
388
  This action will log the user out of aID. The logout is global, meaning it will log the session out of all sites and
387
- aid.no. After logout has completed the promise will resolve, giving your app the opportunity to reset state / reload the
388
- page etc.
389
+ aid.no. It then passes through aID, which tells the browser the reader is logged out, and lands on `requestedUrl` —
390
+ the current page unless you give another address on the site. The page is leaving, so the promise never resolves: don't
391
+ reload or navigate after it, or the visit to aID is cancelled and FedCM keeps prompting the reader to sign in. In a
392
+ frame, where it cannot navigate, it resolves once the session has ended.
389
393
 
390
394
  ### `pollForAccess(requredAccessFeatures = ['pluss'], timeout_millis = 3000): Promise<true>`
391
395
 
package/index.d.ts CHANGED
@@ -135,6 +135,11 @@ type VerificationOutcome = {
135
135
 
136
136
  type ClientId = string;
137
137
 
138
+ interface LogoutOptions {
139
+ /** Where the reader lands once logged out; the current page by default. */
140
+ requestedUrl?: string;
141
+ }
142
+
138
143
  /**
139
144
  * The providers aID may offer this reader, in aID's own order — what to call
140
145
  * each one and what it looks like, so a page can draw the logo it is about to
@@ -342,7 +347,7 @@ type LoginPageParams = {
342
347
  */
343
348
  declare const goToLoginPage: (requestedUrlOrParams?: string | LoginPageParams) => void;
344
349
  declare const getLoginUrl: (requestedUrlOrParams?: string | LoginPageParams) => URL;
345
- declare const logout: () => Promise<void>;
350
+ declare const logout: (options?: LogoutOptions) => Promise<void>;
346
351
  declare const requestDataRefresh: () => void;
347
352
  declare const aidUrls: {
348
353
  mainPage: URL;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "git+https://github.com/amedia/amedia-user-js.git"
7
7
  },
8
8
  "author": "Amedia Produkt og Teknologi AS (https://amedia.no)",
9
- "version": "1.10.4",
9
+ "version": "1.11.0",
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
@@ -40,7 +40,7 @@
40
40
  "CHANGELOG.md"
41
41
  ],
42
42
  "dependencies": {
43
- "jose": "5.9.6",
43
+ "jose": "6.2.16",
44
44
  "valibot": "1.5.0"
45
45
  },
46
46
  "eik": {
package/user.node.d.ts CHANGED
@@ -649,6 +649,17 @@ declare const isLoggedOut: (value: unknown) => boolean;
649
649
  */
650
650
  declare const namesNoReader: (value: unknown) => boolean;
651
651
 
652
+ /**
653
+ * aID's logout handover: ends the reader's aID session in the browser's own
654
+ * visit to aID, then returns to `requestedUrl`. Only that visit can tell the
655
+ * browser the reader is logged out, which stops FedCM prompting them to sign in
656
+ * to aid.no on the next page.
657
+ *
658
+ * Throws a `ValidationError` unless `aidDomain` is a bare host and
659
+ * `requestedUrl` an absolute `https:` address, both of which aID would refuse.
660
+ */
661
+ declare const logoutHandoverUrl: (aidDomain: string, requestedUrl: string) => URL;
662
+
652
663
  /**
653
664
  * The attribute a page marks user-specific markup with: the uuid of the reader
654
665
  * it was rendered for, or `''` when it was rendered for no one logged in.
@@ -926,5 +937,5 @@ interface ValidatedToken {
926
937
  */
927
938
  declare const validateToken: (jwt: string, options: ValidateTokenOptions) => Promise<ValidatedToken>;
928
939
 
929
- export { ACCESS_REFRESH_PATH, AffiliationType, AidProblem, DEFAULT_CLIENT_ID, FetchTimeoutError, IgnoredNetworkError, LOGGED_OUT_PROBLEMS, LoginStatus, MAX_AGE_CEILING_SECONDS, PAGE_OWNER_ATTRIBUTE, ProblemJsonError, ResponseError, SESSION_HEADER, SITE_HEADER, ServerError, VERIFIABLE_ATTRIBUTES, VERIFICATION_SOURCES, ValidationError, buildVerificationUrl, clearJwksCache, createAidClient, createOnSiteClient, createShamoClient, fetchVerificationProviders, findForeignUuids, isAidProblem, isLoggedOut, namesNoReader, normalizeVerificationRequirement, parseAccessRefreshRequest, readVerificationOutcome, validateToken, verificationSourceOf, verificationUrlFor };
940
+ export { ACCESS_REFRESH_PATH, AffiliationType, AidProblem, DEFAULT_CLIENT_ID, FetchTimeoutError, IgnoredNetworkError, LOGGED_OUT_PROBLEMS, LoginStatus, MAX_AGE_CEILING_SECONDS, PAGE_OWNER_ATTRIBUTE, ProblemJsonError, ResponseError, SESSION_HEADER, SITE_HEADER, ServerError, VERIFIABLE_ATTRIBUTES, VERIFICATION_SOURCES, ValidationError, buildVerificationUrl, clearJwksCache, createAidClient, createOnSiteClient, createShamoClient, fetchVerificationProviders, findForeignUuids, isAidProblem, isLoggedOut, logoutHandoverUrl, namesNoReader, normalizeVerificationRequirement, parseAccessRefreshRequest, readVerificationOutcome, validateToken, verificationSourceOf, verificationUrlFor };
930
941
  export type { AccessFeatures, AccessRefreshOutcome, AccessRefreshRequest, AccessRefreshResponse, AidClient, AidClientOptions, AidProblemType, JwksOptions, OnSiteClient, OnSiteClientOptions, PrimarySite, ServerVerificationRequirement, ServiceUser, ShamoClient, ShamoClientOptions, State, UserAttributes, ValidateTokenOptions, ValidatedToken, VerifiableAttribute, VerificationError, VerificationOutcome, VerificationProvider, VerificationRequirement, VerificationSource, VerificationStatus };
package/user.node.js CHANGED
@@ -713,6 +713,44 @@ const isLoggedOut = (value) => isAidProblem(value, ...LOGGED_OUT_PROBLEMS);
713
713
  */
714
714
  const namesNoReader = (value) => isLoggedOut(value) || isAidProblem(value, AidProblem.MISSING_PARAMETER);
715
715
 
716
+ /**
717
+ * aID's logout handover: ends the reader's aID session in the browser's own
718
+ * visit to aID, then returns to `requestedUrl`. Only that visit can tell the
719
+ * browser the reader is logged out, which stops FedCM prompting them to sign in
720
+ * to aid.no on the next page.
721
+ *
722
+ * Throws a `ValidationError` unless `aidDomain` is a bare host and
723
+ * `requestedUrl` an absolute `https:` address, both of which aID would refuse.
724
+ */
725
+ const logoutHandoverUrl = (aidDomain, requestedUrl) => {
726
+ const url = new URL('/handover/logout', `https://${assertBareHost(aidDomain)}`);
727
+ url.searchParams.set('requested_url', assertHttpsUrl(requestedUrl));
728
+ return url;
729
+ };
730
+ const parse = (url) => {
731
+ try {
732
+ return new URL(url);
733
+ }
734
+ catch {
735
+ return undefined;
736
+ }
737
+ };
738
+ const assertBareHost = (aidDomain) => {
739
+ const parsed = parse(`https://${aidDomain}`);
740
+ // The round trip rejects a scheme, path, query, userinfo or backslash.
741
+ if (!parsed || `https://${parsed.host}/` !== `https://${aidDomain}/`) {
742
+ throw new ValidationError('logout_invalid_aid_domain', `aidDomain must be a bare host such as www.aid.no, was ${JSON.stringify(aidDomain)}`);
743
+ }
744
+ return parsed.host;
745
+ };
746
+ const assertHttpsUrl = (requestedUrl) => {
747
+ const parsed = parse(requestedUrl);
748
+ if (parsed?.protocol !== 'https:') {
749
+ throw new ValidationError('logout_invalid_requested_url', `requestedUrl must be an absolute https: address, was ${JSON.stringify(requestedUrl)}`);
750
+ }
751
+ return parsed.href;
752
+ };
753
+
716
754
  /**
717
755
  * The attribute a page marks user-specific markup with: the uuid of the reader
718
756
  * it was rendered for, or `''` when it was rendered for no one logged in.
@@ -1054,5 +1092,5 @@ function mapJoseError(err) {
1054
1092
  return new ValidationError('validation_failed', String(err));
1055
1093
  }
1056
1094
 
1057
- export { ACCESS_REFRESH_PATH, AffiliationType, AidProblem, DEFAULT_CLIENT_ID, FetchTimeoutError, IgnoredNetworkError, LOGGED_OUT_PROBLEMS, LoginStatus, MAX_AGE_CEILING_SECONDS, PAGE_OWNER_ATTRIBUTE, ProblemJsonError, ResponseError, SESSION_HEADER, SITE_HEADER, ServerError, VERIFIABLE_ATTRIBUTES, VERIFICATION_SOURCES, ValidationError, buildVerificationUrl, clearJwksCache, createAidClient, createOnSiteClient, createShamoClient, fetchVerificationProviders, findForeignUuids, isAidProblem, isLoggedOut, namesNoReader, normalizeVerificationRequirement, parseAccessRefreshRequest, readVerificationOutcome, validateToken, verificationSourceOf, verificationUrlFor };
1095
+ export { ACCESS_REFRESH_PATH, AffiliationType, AidProblem, DEFAULT_CLIENT_ID, FetchTimeoutError, IgnoredNetworkError, LOGGED_OUT_PROBLEMS, LoginStatus, MAX_AGE_CEILING_SECONDS, PAGE_OWNER_ATTRIBUTE, ProblemJsonError, ResponseError, SESSION_HEADER, SITE_HEADER, ServerError, VERIFIABLE_ATTRIBUTES, VERIFICATION_SOURCES, ValidationError, buildVerificationUrl, clearJwksCache, createAidClient, createOnSiteClient, createShamoClient, fetchVerificationProviders, findForeignUuids, isAidProblem, isLoggedOut, logoutHandoverUrl, namesNoReader, normalizeVerificationRequirement, parseAccessRefreshRequest, readVerificationOutcome, validateToken, verificationSourceOf, verificationUrlFor };
1058
1096
  //# sourceMappingURL=user.node.js.map