@o3co/auth-provider-upstream-login 0.0.0-stage → 0.18.0-rc.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/LICENSE +201 -0
- package/README.md +4 -2
- package/federation/README.md +59 -0
- package/federation/src/audit-events.d.ts +23 -0
- package/federation/src/audit-events.js +23 -0
- package/federation/src/contract.d.ts +1 -0
- package/federation/src/contract.js +1 -0
- package/federation/src/handoff/README.md +32 -0
- package/federation/src/handoff/handoff.d.ts +40 -0
- package/federation/src/handoff/handoff.js +149 -0
- package/federation/src/idps/README.md +23 -0
- package/federation/src/idps/idps.d.ts +32 -0
- package/federation/src/idps/idps.js +93 -0
- package/federation/src/link/README.md +26 -0
- package/federation/src/link/link.d.ts +20 -0
- package/federation/src/link/link.js +98 -0
- package/federation/src/module.d.ts +2 -0
- package/federation/src/module.js +34 -0
- package/federation/src/round-trip/README.md +43 -0
- package/federation/src/round-trip/login.d.ts +17 -0
- package/federation/src/round-trip/login.js +73 -0
- package/federation/src/round-trip/round-trip.d.ts +86 -0
- package/federation/src/round-trip/round-trip.js +244 -0
- package/federation/src/round-trip/transaction.d.ts +24 -0
- package/federation/src/round-trip/transaction.js +21 -0
- package/federation/src/section.d.ts +12 -0
- package/federation/src/section.js +39 -0
- package/federation/src/store.d.ts +26 -0
- package/federation/src/store.js +8 -0
- package/federation/src/testing.d.ts +50 -0
- package/federation/src/testing.js +128 -0
- package/federation-tokens/README.md +59 -0
- package/federation-tokens/src/audit-events.d.ts +15 -0
- package/federation-tokens/src/audit-events.js +15 -0
- package/federation-tokens/src/caller/README.md +20 -0
- package/federation-tokens/src/caller/caller.d.ts +42 -0
- package/federation-tokens/src/caller/caller.js +56 -0
- package/federation-tokens/src/contract.d.ts +11 -0
- package/federation-tokens/src/contract.js +3 -0
- package/federation-tokens/src/end-session.d.ts +5 -0
- package/federation-tokens/src/end-session.js +15 -0
- package/federation-tokens/src/module.d.ts +2 -0
- package/federation-tokens/src/module.js +77 -0
- package/federation-tokens/src/renewal/README.md +29 -0
- package/federation-tokens/src/renewal/renewal.d.ts +57 -0
- package/federation-tokens/src/renewal/renewal.js +296 -0
- package/federation-tokens/src/routes.d.ts +23 -0
- package/federation-tokens/src/routes.js +112 -0
- package/federation-tokens/src/section.d.ts +8 -0
- package/federation-tokens/src/section.js +12 -0
- package/federation-tokens/src/store.d.ts +44 -0
- package/federation-tokens/src/store.js +7 -0
- package/federation-tokens/src/testing.d.ts +32 -0
- package/federation-tokens/src/testing.js +84 -0
- package/federation-tokens/src/vault/README.md +23 -0
- package/federation-tokens/src/vault/vault.d.ts +39 -0
- package/federation-tokens/src/vault/vault.js +53 -0
- package/idp-apple/README.md +57 -0
- package/idp-apple/src/client-secret/README.md +20 -0
- package/idp-apple/src/client-secret/secret.d.ts +18 -0
- package/idp-apple/src/client-secret/secret.js +33 -0
- package/idp-apple/src/module.d.ts +2 -0
- package/idp-apple/src/module.js +17 -0
- package/idp-apple/src/settings.d.ts +43 -0
- package/idp-apple/src/settings.js +57 -0
- package/idp-apple/src/upstream.d.ts +12 -0
- package/idp-apple/src/upstream.js +93 -0
- package/idp-github/README.md +34 -0
- package/idp-github/src/module.d.ts +2 -0
- package/idp-github/src/module.js +12 -0
- package/idp-github/src/settings.d.ts +30 -0
- package/idp-github/src/settings.js +28 -0
- package/idp-github/src/upstream.d.ts +5 -0
- package/idp-github/src/upstream.js +77 -0
- package/idp-google/README.md +51 -0
- package/idp-google/src/module.d.ts +2 -0
- package/idp-google/src/module.js +17 -0
- package/idp-google/src/settings.d.ts +36 -0
- package/idp-google/src/settings.js +29 -0
- package/idp-google/src/upstream.d.ts +11 -0
- package/idp-google/src/upstream.js +83 -0
- package/idp-oidc/README.md +57 -0
- package/idp-oidc/src/module.d.ts +2 -0
- package/idp-oidc/src/module.js +17 -0
- package/idp-oidc/src/settings.d.ts +36 -0
- package/idp-oidc/src/settings.js +68 -0
- package/idp-oidc/src/upstream.d.ts +17 -0
- package/idp-oidc/src/upstream.js +170 -0
- package/package.json +88 -3
- package/rp-logout-federation/README.md +20 -0
- package/rp-logout-federation/src/module.d.ts +2 -0
- package/rp-logout-federation/src/module.js +22 -0
- package/upstream-client/README.md +39 -0
- package/upstream-client/src/contract.d.ts +49 -0
- package/upstream-client/src/contract.js +140 -0
- package/upstream-client/src/id-token/README.md +23 -0
- package/upstream-client/src/id-token/reader.d.ts +24 -0
- package/upstream-client/src/id-token/reader.js +59 -0
- package/upstreams/README.md +33 -0
- package/upstreams/src/contract.d.ts +135 -0
- package/upstreams/src/contract.js +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 1o1 Co. Ltd.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @o3co/auth-provider-upstream-login
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Part of auth-provider 0.18.0-rc.1, built from `modules/upstream-login` of https://github.com/o3co/auth.provider. Its modules, settings and documentation are there.
|
|
4
|
+
|
|
5
|
+
Copyright 2026 1o1 Co. Ltd. Licensed under the Apache License, Version 2.0.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# federation
|
|
2
|
+
|
|
3
|
+
## Responsibilities
|
|
4
|
+
- Logs a browser in through an upstream IdP and hands the login to `login-gates`.
|
|
5
|
+
- Links an upstream identity to the account a browser is logged in as, at its explicit request (`link`).
|
|
6
|
+
|
|
7
|
+
## Not here
|
|
8
|
+
- What an IdP type, an upstream and a receiver are (`upstreams`).
|
|
9
|
+
- The link records and their conflicts (`users`).
|
|
10
|
+
- Where a login may return to (`login-gates`).
|
|
11
|
+
- Opening the session (`session`, through `login-gates`).
|
|
12
|
+
|
|
13
|
+
## Offers
|
|
14
|
+
- Composition definition: `GET /session/oauth/federation/<idp>` (start: `redirect_to`, `prompt` (only `login` is passed on), `max_age`, `link` (`1` or `true` links; any other value is a login)) and `…/<idp>/callback` (`code`, `state`, `iss`, `error`; by POST for an IdP that answers in a posted form, else GET; the other method is 405); starts and callbacks are limited per source
|
|
15
|
+
- Provides `upstreams`, as its default adapter.
|
|
16
|
+
- The operator section (its keys in the settings list).
|
|
17
|
+
- Store interface for transactions, its needs (survives failover) and contract test; test configuration builders and an IdP type for tests (`./testing`)
|
|
18
|
+
- Audit events for a callback that took its transaction, with `idp` and the source `request-source` determined: `federation.login.succeeded`, or `federation.login.held` when a gate held it, with the local subject; `federation.login.failed` with `reason` (`upstream_refused`, `exchange_failed`, `login_required`, `unknown_user`)
|
|
19
|
+
- For a link, `federation.identity.linked`, or `federation.identity.link_refused` with `reason` (`conflict` or one of the first three), for the subject it started for.
|
|
20
|
+
- No audit event comes before the take or records an unavailable answer, and none holds the upstream subject, tokens or text.
|
|
21
|
+
- Answer codes: `not_found` (404), `repeated_parameter`, `invalid_redirect`, `invalid_request`, `invalid_state`, `upstream_refused` (400), `unknown_user`, `login_required` (401), a gate's or a session requirement's answer, `link_requires_trusted_origin` (403), `identity_conflict` (409), `method_not_allowed` (405, with `allow`), `exchange_failed` (502), `temporarily_unavailable` (503)
|
|
22
|
+
- Success is a 302 to the return target or the landing; a held login is a 403 with the gate's answer and cookies.
|
|
23
|
+
|
|
24
|
+
## Invariants
|
|
25
|
+
- A login's state, nonce and PKCE verifier (S256) are kept server-side in its transaction for `transaction-seconds`. Only a callback at the same IdP carrying its state takes it, once, before the code is exchanged; a callback from elsewhere spends nothing.
|
|
26
|
+
- The transaction is kept under a random cookie named per IdP. The cookie, state, nonce and PKCE verifier are 256 random bits each.
|
|
27
|
+
- The start refuses a return target `login-gates` does not allow (`invalid_redirect`) and a `max_age` that is not 1 to 9 digits. A repeated parameter is refused after the path and method.
|
|
28
|
+
- A start finding a transaction under its cookie is unavailable.
|
|
29
|
+
- The state is compared in constant time. No cookie, no state, or no transaction to take is `invalid_state`. From the take on, every answer clears the cookie, unavailable included.
|
|
30
|
+
- An `error` or no code is `upstream_refused`, with no exchange.
|
|
31
|
+
- A failed exchange is logged with the IdP and its kind only. An unavailable upstream is 503.
|
|
32
|
+
- A login reports the upstream's login time as when the user authenticated, on our clock (a time within the type's clock allowance before the start's second counts as that second), or that it is unknown.
|
|
33
|
+
- After `prompt=login` or a max age, a login counts only when the upstream says when the user logged in.
|
|
34
|
+
- Fresh enough: after `prompt=login`, the upstream's login time plus the type's clock allowance is not before the start's second; with a max age, it is within the max age of now.
|
|
35
|
+
- The local user is found only by the IdP's name and the upstream subject. An unknown identity is refused, and nothing is created.
|
|
36
|
+
- Only a start that asks links, from this deployment's own page (`csrf`'s origin evidence), for a session entered at `credentials`.
|
|
37
|
+
- Its callback links only while that session is open with the same subject and the browser is in no other session; never by email.
|
|
38
|
+
- A link creates no session and changes no session cookie.
|
|
39
|
+
- Without `mfa`, an open session of any age may link.
|
|
40
|
+
- A link whose tokens cannot be handed over is `503`, and one whose session closed or changed hands meanwhile `401`, the link kept.
|
|
41
|
+
- The login proves `fed` plus only the upstream amr values the operator maps (declared as provable). An upstream's text and tokens never reach the browser or the logs.
|
|
42
|
+
- Of what an upstream says of the user, only its profile's email, name and picture reach the session, as strings, under the IdP's source name (`loginSource.upstream`).
|
|
43
|
+
- Its email is verified only where the type says the upstream verified it in the type's own form; otherwise it is unverified.
|
|
44
|
+
- Groups and other claims never reach the session.
|
|
45
|
+
- A held login's tokens are kept for `transaction-seconds` from the hold; if they cannot be kept, the callback is unavailable.
|
|
46
|
+
- A held login resumes within `transaction-seconds` of the callback.
|
|
47
|
+
- An IdP's redirect URI is the public origin plus its callback path.
|
|
48
|
+
- Boot is refused for an unknown type, settings the type refuses, an upstream that does not match its settings, or no public origin, one reason per issue, all at once.
|
|
49
|
+
- An IdP that answers in a posted form has a cross-site cookie, so only `__Host-` and Secure; it refuses boot where cookies cannot be secure.
|
|
50
|
+
|
|
51
|
+
## Data
|
|
52
|
+
- Transaction record, by its cookie. The store derives its name from the cookie and never keeps the cookie in clear.
|
|
53
|
+
- Held login record, in the transaction store. It must never come back on failover.
|
|
54
|
+
|
|
55
|
+
## Depends on
|
|
56
|
+
- `kernel`, `upstreams`, `audit`, `csrf` (origin evidence), `http`, `cookies`, `request-source`, `url-setting`, `login-attributes`, `login-gates`, `session`, `users`, `rate-limit`, `seal` (only with token receivers)
|
|
57
|
+
|
|
58
|
+
## Vocabulary
|
|
59
|
+
- transaction: one round trip, a login's or a link's, from its start to its callback, taken once.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
readonly "federation.login.succeeded": {
|
|
3
|
+
readonly attributes: readonly ["idp", "source"];
|
|
4
|
+
readonly when: "a login through the IdP opened, with the local subject";
|
|
5
|
+
};
|
|
6
|
+
readonly "federation.login.held": {
|
|
7
|
+
readonly attributes: readonly ["idp", "source"];
|
|
8
|
+
readonly when: "a gate held the login, with the local subject";
|
|
9
|
+
};
|
|
10
|
+
readonly "federation.login.failed": {
|
|
11
|
+
readonly attributes: readonly ["idp", "source", "reason"];
|
|
12
|
+
readonly when: "the callback refused the login, with why (`reason`)";
|
|
13
|
+
};
|
|
14
|
+
readonly "federation.identity.linked": {
|
|
15
|
+
readonly attributes: readonly ["idp", "source", "userAgent"];
|
|
16
|
+
readonly when: "a link's callback tied the upstream identity to the subject it started for";
|
|
17
|
+
};
|
|
18
|
+
readonly "federation.identity.link_refused": {
|
|
19
|
+
readonly attributes: readonly ["idp", "source", "userAgent", "reason"];
|
|
20
|
+
readonly when: "a link's callback refused to tie it, with the subject it started for and why (`reason`)";
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export default _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { auditEvents } from "@o3co/auth-provider-foundation/audit";
|
|
2
|
+
export default auditEvents({
|
|
3
|
+
"federation.login.succeeded": {
|
|
4
|
+
attributes: ["idp", "source"],
|
|
5
|
+
when: "a login through the IdP opened, with the local subject",
|
|
6
|
+
},
|
|
7
|
+
"federation.login.held": {
|
|
8
|
+
attributes: ["idp", "source"],
|
|
9
|
+
when: "a gate held the login, with the local subject",
|
|
10
|
+
},
|
|
11
|
+
"federation.login.failed": {
|
|
12
|
+
attributes: ["idp", "source", "reason"],
|
|
13
|
+
when: "the callback refused the login, with why (`reason`)",
|
|
14
|
+
},
|
|
15
|
+
"federation.identity.linked": {
|
|
16
|
+
attributes: ["idp", "source", "userAgent"],
|
|
17
|
+
when: "a link's callback tied the upstream identity to the subject it started for",
|
|
18
|
+
},
|
|
19
|
+
"federation.identity.link_refused": {
|
|
20
|
+
attributes: ["idp", "source", "userAgent", "reason"],
|
|
21
|
+
when: "a link's callback refused to tie it, with the subject it started for and why (`reason`)",
|
|
22
|
+
},
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./store.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./store.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# handoff
|
|
2
|
+
|
|
3
|
+
Internal module of `federation`: handing the upstream tokens of a login to the receivers.
|
|
4
|
+
|
|
5
|
+
## Responsibilities
|
|
6
|
+
- Tells every receiver the upstream tokens of a login once its session opens: at once, or, when a gate held the login, when `login-gates` says it opened. A link's tokens go at once to the open session it joined.
|
|
7
|
+
- Keeps the tokens of a held login sealed until then.
|
|
8
|
+
|
|
9
|
+
## Not here
|
|
10
|
+
- The login, its transaction and the local user (`round-trip`). What a receiver keeps (the receiver). How sealing works (`seal`).
|
|
11
|
+
|
|
12
|
+
## Offers
|
|
13
|
+
- `handoffIn` and `openedIn`: from the build context, the handoff over the receivers in name order (`noHandoff` where there are none), and `login-gates`' news that a held login opened.
|
|
14
|
+
- `handoffWith` (receivers, `seal`, transaction store, `kernel`'s runtime, lifetime):
|
|
15
|
+
- for one login: the `from` that `login-gates` carries and what follows the login's outcome
|
|
16
|
+
- `opened` (session, carry), for `login-gates`
|
|
17
|
+
- `joined` (session, IdP, tokens), for a link, handed at once: a receiver failing undoes those given (`withdrawn`) and is unavailable, logged as `federation.link_join_failed`
|
|
18
|
+
- `withdrawn` (session, IdP) takes a link's tokens back from every receiver; an undo that fails is logged as `federation.link_join_undo_failed`, and the rest still go
|
|
19
|
+
- `noHandoff`, where no module receives upstream tokens
|
|
20
|
+
|
|
21
|
+
## Invariants
|
|
22
|
+
- Only a login whose upstream gave tokens, where some module receives them, carries a `from`; any other carries and keeps nothing.
|
|
23
|
+
- Receivers are told in name order. One that throws is logged by name and error kind; the others are still told, and the login stays open.
|
|
24
|
+
- A held login's tokens are sealed with its IdP and local subject, under a carry of 256 random bits, kept for `transaction-seconds` from the hold. If they cannot be kept, the callback is unavailable.
|
|
25
|
+
- The `from` names a deadline `transaction-seconds` from the callback, before the kept tokens are gone, so `login-gates` refuses a resume from then on and no session opens without them.
|
|
26
|
+
- The kept tokens are taken once, in one rewrite, then removed after telling. They go only to a session of the subject that logged in, with their lifetime counted from the hand-over.
|
|
27
|
+
|
|
28
|
+
## Data
|
|
29
|
+
- Held login record, by its carry, in the transaction store: format 1, the sealed IdP, subject, hold time and tokens, and whether it was taken. One of another shape is none. Needs never to come back on failover (a taken one coming back could hand the tokens over twice).
|
|
30
|
+
|
|
31
|
+
## Depends on
|
|
32
|
+
- `kernel`, `login-gates`, `seal`, `session`; `upstreams` (the receivers, the tokens); `federation`'s section and store interface
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type BuildContext, type Clock, type Log, type Random } from "@o3co/auth-provider-foundation/kernel";
|
|
2
|
+
import type { LoginFrom, LoginOutcome } from "@o3co/auth-provider-identity/login-gates";
|
|
3
|
+
import { type Seal } from "@o3co/auth-provider-foundation/seal";
|
|
4
|
+
import type { Session } from "@o3co/auth-provider-identity/session";
|
|
5
|
+
import { type UpstreamLoginReceiver, type UpstreamTokens } from "@o3co/auth-provider-upstream-login/upstreams";
|
|
6
|
+
import type { Settings } from "../section.js";
|
|
7
|
+
import { type TransactionStore } from "../store.js";
|
|
8
|
+
export declare const caller = "federation";
|
|
9
|
+
/** Hands a login's upstream tokens to the receivers once its session opens. */
|
|
10
|
+
export interface Handoff {
|
|
11
|
+
/** For a login whose upstream gave tokens someone receives: what login-gates carries, and what follows it. */
|
|
12
|
+
of(idp: string, subject: string, tokens: UpstreamTokens | undefined): {
|
|
13
|
+
readonly from: LoginFrom;
|
|
14
|
+
after(outcome: LoginOutcome): Promise<void>;
|
|
15
|
+
} | undefined;
|
|
16
|
+
/** login-gates' news that a held login opened. */
|
|
17
|
+
opened(session: Session, carry: string): Promise<void>;
|
|
18
|
+
/** A link's tokens, handed now to the receivers of the open session it joined; one failing undoes the others and is unavailable. */
|
|
19
|
+
joined(session: Session, idp: string, tokens: UpstreamTokens): Promise<void>;
|
|
20
|
+
/** A link's tokens for the session and IdP taken back from every receiver, any held before included, when its session closed, changed hands or could not tell after the join. */
|
|
21
|
+
withdrawn(sessionId: string, idp: string): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export declare const handoff: import("@o3co/auth-provider-foundation/kernel").Contract<Handoff>;
|
|
24
|
+
export declare const noHandoff: Handoff;
|
|
25
|
+
interface Parts {
|
|
26
|
+
readonly receivers: readonly UpstreamLoginReceiver[];
|
|
27
|
+
readonly seal: Seal;
|
|
28
|
+
readonly transactions: TransactionStore;
|
|
29
|
+
readonly clock: Clock;
|
|
30
|
+
readonly random: Random;
|
|
31
|
+
readonly log: Log;
|
|
32
|
+
readonly lifetimeMs: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function handoffIn(c: BuildContext<Settings>): Promise<Handoff>;
|
|
35
|
+
export declare const openedIn: (c: BuildContext<Settings>) => Promise<{
|
|
36
|
+
caller: string;
|
|
37
|
+
opened: (session: Session, carry: string) => Promise<void>;
|
|
38
|
+
}>;
|
|
39
|
+
export declare function handoffWith(parts: Parts): Handoff;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { contract, Unavailable, } from "@o3co/auth-provider-foundation/kernel";
|
|
2
|
+
import { seal } from "@o3co/auth-provider-foundation/seal";
|
|
3
|
+
import { upstreamLoginReceivers, } from "@o3co/auth-provider-upstream-login/upstreams";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { transactionStore } from "../store.js";
|
|
6
|
+
export const caller = "federation";
|
|
7
|
+
export const handoff = contract("federation.handoff");
|
|
8
|
+
export const noHandoff = {
|
|
9
|
+
of: () => undefined,
|
|
10
|
+
opened: async () => { },
|
|
11
|
+
joined: async () => { },
|
|
12
|
+
withdrawn: async () => { },
|
|
13
|
+
};
|
|
14
|
+
const tokensShape = z.strictObject({
|
|
15
|
+
accessToken: z.string(),
|
|
16
|
+
tokenType: z.string(),
|
|
17
|
+
refreshToken: z.string().optional(),
|
|
18
|
+
idToken: z.string().optional(),
|
|
19
|
+
expiresInSeconds: z.number().optional(),
|
|
20
|
+
scope: z.array(z.string()),
|
|
21
|
+
});
|
|
22
|
+
const heldShape = z.strictObject({
|
|
23
|
+
idp: z.string(),
|
|
24
|
+
subject: z.string(),
|
|
25
|
+
heldAt: z.number(),
|
|
26
|
+
tokens: tokensShape,
|
|
27
|
+
});
|
|
28
|
+
const keptShape = z.strictObject({
|
|
29
|
+
format: z.literal(1),
|
|
30
|
+
sealed: z.string(),
|
|
31
|
+
taken: z.literal(true).optional(),
|
|
32
|
+
});
|
|
33
|
+
const keptOf = (stored) => {
|
|
34
|
+
const read = keptShape.safeParse(stored);
|
|
35
|
+
return read.success ? read.data : undefined;
|
|
36
|
+
};
|
|
37
|
+
const stored = (kept) => kept;
|
|
38
|
+
const contextOf = (carry) => `federation.held-login\n${carry}`;
|
|
39
|
+
export async function handoffIn(c) {
|
|
40
|
+
const receivers = (await c.collect(upstreamLoginReceivers)).toSorted((a, b) => a.name < b.name ? -1 : 1);
|
|
41
|
+
// Sealing is needed only where a module receives upstream tokens.
|
|
42
|
+
if (receivers.length === 0)
|
|
43
|
+
return noHandoff;
|
|
44
|
+
return handoffWith({
|
|
45
|
+
receivers,
|
|
46
|
+
seal: await c.get(seal),
|
|
47
|
+
transactions: await c.get(transactionStore),
|
|
48
|
+
clock: c.clock,
|
|
49
|
+
random: c.random,
|
|
50
|
+
log: c.log,
|
|
51
|
+
lifetimeMs: c.section["transaction-seconds"] * 1000,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** login-gates' news that a held login opened, for the handoff. */
|
|
55
|
+
const openedWith = (handing) => ({
|
|
56
|
+
caller,
|
|
57
|
+
opened: handing.opened,
|
|
58
|
+
});
|
|
59
|
+
export const openedIn = async (c) => openedWith(await c.get(handoff));
|
|
60
|
+
export function handoffWith(parts) {
|
|
61
|
+
const tell = async (session, idp, tokens) => {
|
|
62
|
+
for (const receiver of parts.receivers) {
|
|
63
|
+
try {
|
|
64
|
+
await receiver.received({ session, idp, tokens });
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const kind = error instanceof Error ? error.name : typeof error;
|
|
68
|
+
parts.log.error("federation.receiver_failed", { receiver: receiver.name, kind });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/** Takes the tokens back from each receiver named, going on past one that fails. */
|
|
73
|
+
const withdraw = async (given, sessionId, idp) => {
|
|
74
|
+
for (const done of given) {
|
|
75
|
+
try {
|
|
76
|
+
await done.withdrawn(sessionId, idp);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
parts.log.warn("federation.link_join_undo_failed", { receiver: done.name });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const opened = (kept, carry, subject) => {
|
|
84
|
+
const plain = parts.seal.open(kept.sealed, contextOf(carry));
|
|
85
|
+
const held = plain.kind === "opened" ? heldShape.safeParse(JSON.parse(plain.plain)) : undefined;
|
|
86
|
+
return held?.success && held.data.subject === subject ? held.data : undefined;
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
of: (idp, subject, tokens) => {
|
|
90
|
+
if (tokens === undefined)
|
|
91
|
+
return undefined;
|
|
92
|
+
// login-gates refuses a resume from the deadline on, when the kept tokens are gone.
|
|
93
|
+
const deadline = parts.clock.now() + parts.lifetimeMs;
|
|
94
|
+
const carry = Buffer.from(parts.random.bytes(32)).toString("base64url");
|
|
95
|
+
return {
|
|
96
|
+
from: { caller, carry, deadline },
|
|
97
|
+
after: async (outcome) => {
|
|
98
|
+
if (outcome.kind === "opened")
|
|
99
|
+
return tell(outcome.session, idp, tokens);
|
|
100
|
+
const held = { idp, subject, heldAt: parts.clock.now(), tokens };
|
|
101
|
+
const sealed = parts.seal.seal(JSON.stringify(held), contextOf(carry));
|
|
102
|
+
const saved = await parts.transactions.save(carry, stored({ format: 1, sealed }), parts.lifetimeMs);
|
|
103
|
+
if (saved !== "created")
|
|
104
|
+
throw new Unavailable("federation");
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
opened: async (session, carry) => {
|
|
109
|
+
const taking = await parts.transactions.update(carry, (record) => {
|
|
110
|
+
const kept = keptOf(record);
|
|
111
|
+
return kept && !kept.taken ? { value: stored({ ...kept, taken: true }) } : undefined;
|
|
112
|
+
});
|
|
113
|
+
const kept = keptOf(taking?.before);
|
|
114
|
+
if (!kept || kept.taken || keptOf(taking?.after)?.taken !== true)
|
|
115
|
+
return;
|
|
116
|
+
try {
|
|
117
|
+
const held = opened(kept, carry, session.context.subject);
|
|
118
|
+
if (!held)
|
|
119
|
+
return parts.log.warn("federation.held_login_refused", {});
|
|
120
|
+
// Said from the hold; handed over now, so the time since is spent.
|
|
121
|
+
const spent = Math.ceil((parts.clock.now() - held.heldAt) / 1000);
|
|
122
|
+
const { expiresInSeconds: expires, ...rest } = held.tokens;
|
|
123
|
+
const tokens = (expires === undefined
|
|
124
|
+
? rest
|
|
125
|
+
: { ...rest, expiresInSeconds: Math.max(0, expires - Math.max(0, spent)) });
|
|
126
|
+
await tell(session, held.idp, tokens);
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
await parts.transactions.remove(carry);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
joined: async (session, idp, tokens) => {
|
|
133
|
+
const given = [];
|
|
134
|
+
for (const receiver of parts.receivers) {
|
|
135
|
+
try {
|
|
136
|
+
await receiver.received({ session, idp, tokens });
|
|
137
|
+
given.push(receiver);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
const kind = error instanceof Error ? error.name : typeof error;
|
|
141
|
+
parts.log.error("federation.link_join_failed", { receiver: receiver.name, kind });
|
|
142
|
+
await withdraw(given, session.id, idp);
|
|
143
|
+
throw new Unavailable("federation");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
withdrawn: (sessionId, idp) => withdraw(parts.receivers, sessionId, idp),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# idps
|
|
2
|
+
|
|
3
|
+
Internal module of `federation`: opening the configured IdPs at boot.
|
|
4
|
+
|
|
5
|
+
## Responsibilities
|
|
6
|
+
- Opens each configured IdP through its type, and gives the round trip what it needs of it.
|
|
7
|
+
- Finds every reason to refuse boot at once.
|
|
8
|
+
|
|
9
|
+
## Not here
|
|
10
|
+
- What a type checks of its settings and its upstream (the type). Refusing boot (the package's module, with the reasons found here).
|
|
11
|
+
|
|
12
|
+
## Offers
|
|
13
|
+
- `idpsIn`, `upstreamsIn` and `amrSourceIn`: from the build context, the opened IdPs (refusing boot with every reason), `upstreams` over them, and `login-gates`' amr source (what a federation login proves and what the IdPs' amr maps to).
|
|
14
|
+
- `openIdps` (the offered IdP types, the section's `idps`, `http`'s public origin and whether its cookies can be secure) → the opened IdPs by name, and the reasons to refuse boot.
|
|
15
|
+
|
|
16
|
+
## Invariants
|
|
17
|
+
- Each IdP's redirect URI is the public origin plus its own callback path.
|
|
18
|
+
- An IdP is refused when no module offers its type, when its type refuses its settings (one reason per issue), with no public origin, or when its upstream does not match its settings.
|
|
19
|
+
- An IdP whose upstream answers in a posted form is refused when cookies cannot be secure.
|
|
20
|
+
- An IdP's type sees only its own settings, without `type` and `upstream-amr`.
|
|
21
|
+
|
|
22
|
+
## Depends on
|
|
23
|
+
- `http` (the site); `kernel` (the build context, refusals); `upstreams` (the IdP types); `federation`'s section; `round-trip` (what an opened IdP is, the callback path, the opened IdPs' contract, what a login proves)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Site } from "@o3co/auth-provider-foundation/http";
|
|
2
|
+
import type { BuildContext, Refusal } from "@o3co/auth-provider-foundation/kernel";
|
|
3
|
+
import { type IdpType } from "@o3co/auth-provider-upstream-login/upstreams";
|
|
4
|
+
import { type Idp } from "../round-trip/round-trip.js";
|
|
5
|
+
import type { Settings } from "../section.js";
|
|
6
|
+
interface Parts {
|
|
7
|
+
readonly types: readonly IdpType[];
|
|
8
|
+
readonly settings: Settings["idps"];
|
|
9
|
+
readonly site: Pick<Site, "origin" | "secureCookies">;
|
|
10
|
+
}
|
|
11
|
+
export declare function idpsIn(c: BuildContext<Settings>): Promise<ReadonlyMap<string, Idp>>;
|
|
12
|
+
export declare const upstreamsIn: (c: BuildContext<Settings>) => Promise<{
|
|
13
|
+
of: (idp: string) => {
|
|
14
|
+
delegation?: import("@o3co/auth-provider-upstream-login/upstreams").Delegation;
|
|
15
|
+
endSession?: (at: {
|
|
16
|
+
readonly idTokenHint?: string;
|
|
17
|
+
readonly postLogoutRedirectUri?: string;
|
|
18
|
+
readonly state?: string;
|
|
19
|
+
}) => string;
|
|
20
|
+
refresh?: (refreshToken: string, scope: readonly string[]) => Promise<import("@o3co/auth-provider-upstream-login/upstreams").UpstreamRefresh>;
|
|
21
|
+
} | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const amrSourceIn: (c: BuildContext<Settings>) => {
|
|
24
|
+
name: string;
|
|
25
|
+
amr: string[];
|
|
26
|
+
};
|
|
27
|
+
/** Opens every configured IdP through its type, with every problem found, so boot is refused once. */
|
|
28
|
+
export declare function openIdps(parts: Parts): Promise<{
|
|
29
|
+
idps: ReadonlyMap<string, Idp>;
|
|
30
|
+
refusals: Refusal[];
|
|
31
|
+
}>;
|
|
32
|
+
export {};
|