@xemahq/oidc-session-nest 0.1.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/LICENSE +176 -0
- package/README.md +101 -0
- package/dist/config/oidc-session-env.d.ts +6 -0
- package/dist/config/oidc-session-env.d.ts.map +1 -0
- package/dist/config/oidc-session-env.js +123 -0
- package/dist/config/oidc-session-env.js.map +1 -0
- package/dist/config/oidc-session-options.d.ts +33 -0
- package/dist/config/oidc-session-options.d.ts.map +1 -0
- package/dist/config/oidc-session-options.js +67 -0
- package/dist/config/oidc-session-options.js.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +60 -0
- package/dist/errors.js.map +1 -0
- package/dist/http/cookie.d.ts +12 -0
- package/dist/http/cookie.d.ts.map +1 -0
- package/dist/http/cookie.js +82 -0
- package/dist/http/cookie.js.map +1 -0
- package/dist/http/headers.d.ts +2 -0
- package/dist/http/headers.d.ts.map +1 -0
- package/dist/http/headers.js +5 -0
- package/dist/http/headers.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/nest/oidc-session-auth.controller.d.ts +30 -0
- package/dist/nest/oidc-session-auth.controller.d.ts.map +1 -0
- package/dist/nest/oidc-session-auth.controller.js +182 -0
- package/dist/nest/oidc-session-auth.controller.js.map +1 -0
- package/dist/nest/oidc-session-context.d.ts +11 -0
- package/dist/nest/oidc-session-context.d.ts.map +1 -0
- package/dist/nest/oidc-session-context.js +37 -0
- package/dist/nest/oidc-session-context.js.map +1 -0
- package/dist/nest/oidc-session.guard.d.ts +5 -0
- package/dist/nest/oidc-session.guard.d.ts.map +1 -0
- package/dist/nest/oidc-session.guard.js +43 -0
- package/dist/nest/oidc-session.guard.js.map +1 -0
- package/dist/nest/oidc-session.middleware.d.ts +19 -0
- package/dist/nest/oidc-session.middleware.d.ts.map +1 -0
- package/dist/nest/oidc-session.middleware.js +57 -0
- package/dist/nest/oidc-session.middleware.js.map +1 -0
- package/dist/nest/oidc-session.module.d.ts +22 -0
- package/dist/nest/oidc-session.module.d.ts.map +1 -0
- package/dist/nest/oidc-session.module.js +100 -0
- package/dist/nest/oidc-session.module.js.map +1 -0
- package/dist/nest/session-actor.decorator.d.ts +2 -0
- package/dist/nest/session-actor.decorator.d.ts.map +1 -0
- package/dist/nest/session-actor.decorator.js +13 -0
- package/dist/nest/session-actor.decorator.js.map +1 -0
- package/dist/nest/session-client-transport.d.ts +6 -0
- package/dist/nest/session-client-transport.d.ts.map +1 -0
- package/dist/nest/session-client-transport.js +41 -0
- package/dist/nest/session-client-transport.js.map +1 -0
- package/dist/nest/tokens.d.ts +3 -0
- package/dist/nest/tokens.d.ts.map +1 -0
- package/dist/nest/tokens.js +6 -0
- package/dist/nest/tokens.js.map +1 -0
- package/dist/oidc/discovery.d.ts +30 -0
- package/dist/oidc/discovery.d.ts.map +1 -0
- package/dist/oidc/discovery.js +101 -0
- package/dist/oidc/discovery.js.map +1 -0
- package/dist/oidc/oidc-client.d.ts +44 -0
- package/dist/oidc/oidc-client.d.ts.map +1 -0
- package/dist/oidc/oidc-client.js +190 -0
- package/dist/oidc/oidc-client.js.map +1 -0
- package/dist/oidc/pkce.d.ts +8 -0
- package/dist/oidc/pkce.d.ts.map +1 -0
- package/dist/oidc/pkce.js +15 -0
- package/dist/oidc/pkce.js.map +1 -0
- package/dist/session/actor.d.ts +14 -0
- package/dist/session/actor.d.ts.map +1 -0
- package/dist/session/actor.js +32 -0
- package/dist/session/actor.js.map +1 -0
- package/dist/session/in-memory-session-store.d.ts +21 -0
- package/dist/session/in-memory-session-store.d.ts.map +1 -0
- package/dist/session/in-memory-session-store.js +79 -0
- package/dist/session/in-memory-session-store.js.map +1 -0
- package/dist/session/redis-session-store.d.ts +28 -0
- package/dist/session/redis-session-store.d.ts.map +1 -0
- package/dist/session/redis-session-store.js +121 -0
- package/dist/session/redis-session-store.js.map +1 -0
- package/dist/session/session-service.d.ts +55 -0
- package/dist/session/session-service.d.ts.map +1 -0
- package/dist/session/session-service.js +224 -0
- package/dist/session/session-service.js.map +1 -0
- package/dist/session/session-store.d.ts +35 -0
- package/dist/session/session-store.d.ts.map +1 -0
- package/dist/session/session-store.js +3 -0
- package/dist/session/session-store.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<!-- Banner: inline SVG (from assets/banner-template.svg). Renders on GitHub; npm strips inline SVG. -->
|
|
2
|
+
<p align="center">
|
|
3
|
+
<svg width="680" height="120" viewBox="0 0 680 120" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="@xemahq/oidc-session-nest">
|
|
4
|
+
<rect width="680" height="120" rx="14" fill="#0B1020"/>
|
|
5
|
+
<g transform="translate(28,34)">
|
|
6
|
+
<path d="M26 0 L52 15 L52 45 L26 60 L0 45 L0 15 Z" fill="#8B5CF6" opacity="0.18"/>
|
|
7
|
+
<path d="M26 12 L41 21 L41 39 L26 48 L11 39 L11 21 Z" fill="#8B5CF6"/>
|
|
8
|
+
</g>
|
|
9
|
+
<text x="92" y="52" font-family="ui-monospace,SFMono-Regular,Menlo,monospace" font-size="26" fill="#F8FAFC" font-weight="700">@xemahq/oidc-session-nest</text>
|
|
10
|
+
<text x="92" y="80" font-family="ui-sans-serif,system-ui,sans-serif" font-size="15" fill="#94A3B8">The browser holds a cookie. The server holds the tokens.</text>
|
|
11
|
+
<text x="652" y="105" text-anchor="end" font-family="ui-sans-serif,system-ui,sans-serif" font-size="12" fill="#475569">xema.dev</text>
|
|
12
|
+
</svg>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://xema.dev">Website</a> ·
|
|
17
|
+
<a href="https://www.npmjs.com/package/@xemahq/oidc-session-nest">npm</a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<p align="center">
|
|
21
|
+
<img alt="npm" src="https://img.shields.io/npm/v/%40xemahq%2Foidc-session-nest?color=2563eb&label=npm">
|
|
22
|
+
<img alt="license" src="https://img.shields.io/npm/l/%40xemahq%2Foidc-session-nest?color=10b981">
|
|
23
|
+
<img alt="types" src="https://img.shields.io/npm/types/%40xemahq%2Foidc-session-nest?color=3178c6">
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
# @xemahq/oidc-session-nest
|
|
27
|
+
|
|
28
|
+
> The browser holds a cookie. The server holds the tokens.
|
|
29
|
+
|
|
30
|
+
## Overview
|
|
31
|
+
|
|
32
|
+
This package belongs to Layer 1 — it is an SDK a NestJS application composes, not
|
|
33
|
+
a service. It gives a backend-for-frontend a complete server-side OIDC session:
|
|
34
|
+
the authorization-code exchange with PKCE, a session store the application owns,
|
|
35
|
+
a refresh that happens once no matter how many requests or replicas ask for it,
|
|
36
|
+
and an ambient request scope the generated Xema clients read their bearer from.
|
|
37
|
+
|
|
38
|
+
The browser receives exactly one thing — an httpOnly cookie carrying an opaque
|
|
39
|
+
id. It never receives an access token, a refresh token or an id token, so there
|
|
40
|
+
is no token in `localStorage` for a script to read and nothing to leak through a
|
|
41
|
+
`postMessage`, a source map or a crash reporter.
|
|
42
|
+
|
|
43
|
+
## When to use it
|
|
44
|
+
|
|
45
|
+
- Use this when a browser talks to a backend you ship, and that backend talks to
|
|
46
|
+
Xema. It is the recommended shape for browsers and it is not mandated: a
|
|
47
|
+
server-to-server integration needs no session at all, and a mobile client that
|
|
48
|
+
already has an OIDC library keeps it.
|
|
49
|
+
- Reach for `@xemahq/oidc-guard` instead when you only need to VERIFY a token
|
|
50
|
+
somebody else obtained — this package composes it for exactly that and adds
|
|
51
|
+
the session around it.
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pnpm add @xemahq/oidc-session-nest
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import {
|
|
63
|
+
InMemorySessionStore,
|
|
64
|
+
OidcSessionModule,
|
|
65
|
+
loadOidcSessionOptionsFromEnv,
|
|
66
|
+
sessionClientTransport,
|
|
67
|
+
} from '@xemahq/oidc-session-nest';
|
|
68
|
+
|
|
69
|
+
@Module({
|
|
70
|
+
imports: [
|
|
71
|
+
OidcSessionModule.forRootAsync({
|
|
72
|
+
inject: [ConfigService],
|
|
73
|
+
useFactory: (config: ConfigService) => ({
|
|
74
|
+
options: loadOidcSessionOptionsFromEnv((name) => config.get(name)),
|
|
75
|
+
store: new InMemorySessionStore(), // RedisSessionStore when scaled
|
|
76
|
+
}),
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
})
|
|
80
|
+
export class AppModule {}
|
|
81
|
+
|
|
82
|
+
// Once, at boot — every request then calls peers as whoever is signed in.
|
|
83
|
+
configureClient({ baseUrl, ...sessionClientTransport() });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Fence a route with `OidcSessionGuard` and read the caller with `@SessionActor()`.
|
|
87
|
+
A route without the guard still gets the ambient scope, so an anonymous page can
|
|
88
|
+
render — it simply has no bearer to call Xema with.
|
|
89
|
+
|
|
90
|
+
## Peer requirements
|
|
91
|
+
|
|
92
|
+
- `@nestjs/common` and `@nestjs/core` `^10 || ^11` — the framework this mounts into.
|
|
93
|
+
- `@xemahq/oidc-guard` `>=0.6.0` — verifies every token this package accepts.
|
|
94
|
+
- `@xemahq/platform-common` `>=0.28.2` — supplies the org claim and header names.
|
|
95
|
+
- `@xemahq/xema-decorators` `>=0.15.0` — declares the four browser routes public
|
|
96
|
+
so a global JWT guard does not fence the sign-in door.
|
|
97
|
+
- `@xemahq/kernel-contracts` `>=34.0.0` — reached through the types above.
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
Apache-2.0 © Xema — [xema.dev](https://xema.dev)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type OidcSessionOptions } from './oidc-session-options';
|
|
2
|
+
export type EnvReader = (name: string) => string | undefined;
|
|
3
|
+
export declare const OIDC_SESSION_REQUIRED_ENV_VARS: readonly string[];
|
|
4
|
+
export declare const OIDC_SESSION_OPTIONAL_ENV_VARS: readonly string[];
|
|
5
|
+
export declare function loadOidcSessionOptionsFromEnv(read: EnvReader): OidcSessionOptions;
|
|
6
|
+
//# sourceMappingURL=oidc-session-env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-session-env.d.ts","sourceRoot":"","sources":["../../src/config/oidc-session-env.ts"],"names":[],"mappings":"AAaA,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,wBAAwB,CAAC;AAGhC,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAU7D,eAAO,MAAM,8BAA8B,EAAE,SAAS,MAAM,EAK3D,CAAC;AAOF,eAAO,MAAM,8BAA8B,EAAE,SAAS,MAAM,EAa3D,CAAC;AAoBF,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,SAAS,GACd,kBAAkB,CA+CpB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OIDC_SESSION_OPTIONAL_ENV_VARS = exports.OIDC_SESSION_REQUIRED_ENV_VARS = void 0;
|
|
4
|
+
exports.loadOidcSessionOptionsFromEnv = loadOidcSessionOptionsFromEnv;
|
|
5
|
+
const oidc_session_options_1 = require("./oidc-session-options");
|
|
6
|
+
exports.OIDC_SESSION_REQUIRED_ENV_VARS = [
|
|
7
|
+
'OIDC_ISSUER_URL',
|
|
8
|
+
'OIDC_CLIENT_ID',
|
|
9
|
+
'OIDC_REDIRECT_URI',
|
|
10
|
+
'SESSION_COOKIE_NAME',
|
|
11
|
+
];
|
|
12
|
+
exports.OIDC_SESSION_OPTIONAL_ENV_VARS = [
|
|
13
|
+
'OIDC_CLIENT_SECRET',
|
|
14
|
+
'OIDC_POST_LOGOUT_REDIRECT_URI',
|
|
15
|
+
'OIDC_SCOPE',
|
|
16
|
+
'SESSION_COOKIE_SECURE',
|
|
17
|
+
'SESSION_COOKIE_DOMAIN',
|
|
18
|
+
'SESSION_COOKIE_SAME_SITE',
|
|
19
|
+
'SESSION_COOKIE_PATH',
|
|
20
|
+
'SESSION_IDLE_TTL_SECONDS',
|
|
21
|
+
'SESSION_ABSOLUTE_TTL_SECONDS',
|
|
22
|
+
'SESSION_REFRESH_LEAD_SECONDS',
|
|
23
|
+
'SESSION_REFRESH_WAIT_MS',
|
|
24
|
+
'SESSION_KEY_PREFIX',
|
|
25
|
+
];
|
|
26
|
+
const DEFAULT_IDLE_TTL_SECONDS = 8 * 60 * 60;
|
|
27
|
+
const DEFAULT_ABSOLUTE_TTL_SECONDS = 24 * 60 * 60;
|
|
28
|
+
const DEFAULT_REFRESH_LEAD_SECONDS = 60;
|
|
29
|
+
const DEFAULT_REFRESH_WAIT_MS = 2_000;
|
|
30
|
+
const DEFAULT_KEY_PREFIX = 'oidc-session';
|
|
31
|
+
const DEFAULT_COOKIE_PATH = '/';
|
|
32
|
+
const DEFAULT_SAME_SITE = 'lax';
|
|
33
|
+
const SAME_SITE_VALUES = ['lax', 'strict', 'none'];
|
|
34
|
+
function loadOidcSessionOptionsFromEnv(read) {
|
|
35
|
+
const clientSecret = optional(read, 'OIDC_CLIENT_SECRET');
|
|
36
|
+
const postLogoutRedirectUri = optional(read, 'OIDC_POST_LOGOUT_REDIRECT_URI');
|
|
37
|
+
const cookieDomain = optional(read, 'SESSION_COOKIE_DOMAIN');
|
|
38
|
+
const options = {
|
|
39
|
+
oidc: {
|
|
40
|
+
issuerUrl: required(read, 'OIDC_ISSUER_URL'),
|
|
41
|
+
clientId: required(read, 'OIDC_CLIENT_ID'),
|
|
42
|
+
...(clientSecret === undefined ? {} : { clientSecret }),
|
|
43
|
+
redirectUri: required(read, 'OIDC_REDIRECT_URI'),
|
|
44
|
+
...(postLogoutRedirectUri === undefined ? {} : { postLogoutRedirectUri }),
|
|
45
|
+
scope: withRequiredScope(optional(read, 'OIDC_SCOPE') ?? oidc_session_options_1.REQUIRED_OIDC_SCOPE),
|
|
46
|
+
},
|
|
47
|
+
cookie: {
|
|
48
|
+
name: required(read, 'SESSION_COOKIE_NAME'),
|
|
49
|
+
secure: readBoolean(read, 'SESSION_COOKIE_SECURE', true),
|
|
50
|
+
...(cookieDomain === undefined ? {} : { domain: cookieDomain }),
|
|
51
|
+
path: optional(read, 'SESSION_COOKIE_PATH') ?? DEFAULT_COOKIE_PATH,
|
|
52
|
+
sameSite: readSameSite(read, 'SESSION_COOKIE_SAME_SITE', DEFAULT_SAME_SITE),
|
|
53
|
+
},
|
|
54
|
+
ttl: {
|
|
55
|
+
idleTtlSeconds: readPositiveNumber(read, 'SESSION_IDLE_TTL_SECONDS', DEFAULT_IDLE_TTL_SECONDS),
|
|
56
|
+
absoluteTtlSeconds: readPositiveNumber(read, 'SESSION_ABSOLUTE_TTL_SECONDS', DEFAULT_ABSOLUTE_TTL_SECONDS),
|
|
57
|
+
refreshLeadSeconds: readPositiveNumber(read, 'SESSION_REFRESH_LEAD_SECONDS', DEFAULT_REFRESH_LEAD_SECONDS),
|
|
58
|
+
refreshWaitMs: readPositiveNumber(read, 'SESSION_REFRESH_WAIT_MS', DEFAULT_REFRESH_WAIT_MS),
|
|
59
|
+
},
|
|
60
|
+
keyPrefix: optional(read, 'SESSION_KEY_PREFIX') ?? DEFAULT_KEY_PREFIX,
|
|
61
|
+
};
|
|
62
|
+
return (0, oidc_session_options_1.assertOidcSessionOptions)(options);
|
|
63
|
+
}
|
|
64
|
+
function optional(read, name) {
|
|
65
|
+
const raw = read(name);
|
|
66
|
+
if (raw === undefined || raw.trim() === '') {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
return raw.trim();
|
|
70
|
+
}
|
|
71
|
+
function required(read, name) {
|
|
72
|
+
const value = optional(read, name);
|
|
73
|
+
if (value === undefined) {
|
|
74
|
+
throw new oidc_session_options_1.OidcSessionConfigError(`${name} is required and is unset or empty. It has no safe default: ` +
|
|
75
|
+
'without it this application cannot complete a sign-in.');
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
function withRequiredScope(scope) {
|
|
80
|
+
const parts = scope.split(/\s+/u).filter((part) => part !== '');
|
|
81
|
+
if (parts.includes(oidc_session_options_1.REQUIRED_OIDC_SCOPE)) {
|
|
82
|
+
return parts.join(' ');
|
|
83
|
+
}
|
|
84
|
+
return [oidc_session_options_1.REQUIRED_OIDC_SCOPE, ...parts].join(' ');
|
|
85
|
+
}
|
|
86
|
+
function readBoolean(read, name, fallback) {
|
|
87
|
+
const raw = optional(read, name);
|
|
88
|
+
if (raw === undefined) {
|
|
89
|
+
return fallback;
|
|
90
|
+
}
|
|
91
|
+
const lowered = raw.toLowerCase();
|
|
92
|
+
if (lowered === 'true') {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
if (lowered === 'false') {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
throw new oidc_session_options_1.OidcSessionConfigError(`${name} must be "true" or "false"; got "${raw}".`);
|
|
99
|
+
}
|
|
100
|
+
function readPositiveNumber(read, name, fallback) {
|
|
101
|
+
const raw = optional(read, name);
|
|
102
|
+
if (raw === undefined) {
|
|
103
|
+
return fallback;
|
|
104
|
+
}
|
|
105
|
+
const parsed = Number(raw);
|
|
106
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
107
|
+
throw new oidc_session_options_1.OidcSessionConfigError(`${name} must be a positive number; got "${raw}".`);
|
|
108
|
+
}
|
|
109
|
+
return parsed;
|
|
110
|
+
}
|
|
111
|
+
function readSameSite(read, name, fallback) {
|
|
112
|
+
const raw = optional(read, name);
|
|
113
|
+
if (raw === undefined) {
|
|
114
|
+
return fallback;
|
|
115
|
+
}
|
|
116
|
+
const lowered = raw.toLowerCase();
|
|
117
|
+
const match = SAME_SITE_VALUES.find((value) => value === lowered);
|
|
118
|
+
if (match === undefined) {
|
|
119
|
+
throw new oidc_session_options_1.OidcSessionConfigError(`${name} must be one of ${SAME_SITE_VALUES.join(', ')}; got "${raw}".`);
|
|
120
|
+
}
|
|
121
|
+
return match;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=oidc-session-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-session-env.js","sourceRoot":"","sources":["../../src/config/oidc-session-env.ts"],"names":[],"mappings":";;;AA4EA,sEAiDC;AAhHD,iEAKgC;AAanB,QAAA,8BAA8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: string;
|
|
3
|
+
readonly clientId: string;
|
|
4
|
+
readonly clientSecret?: string;
|
|
5
|
+
readonly redirectUri: string;
|
|
6
|
+
readonly postLogoutRedirectUri?: string;
|
|
7
|
+
readonly scope: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SessionCookieOptions {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly secure: boolean;
|
|
12
|
+
readonly domain?: string;
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly sameSite: 'lax' | 'strict' | 'none';
|
|
15
|
+
}
|
|
16
|
+
export interface SessionTtlOptions {
|
|
17
|
+
readonly idleTtlSeconds: number;
|
|
18
|
+
readonly absoluteTtlSeconds: number;
|
|
19
|
+
readonly refreshLeadSeconds: number;
|
|
20
|
+
readonly refreshWaitMs: number;
|
|
21
|
+
}
|
|
22
|
+
export interface OidcSessionOptions {
|
|
23
|
+
readonly oidc: OidcProviderOptions;
|
|
24
|
+
readonly cookie: SessionCookieOptions;
|
|
25
|
+
readonly ttl: SessionTtlOptions;
|
|
26
|
+
readonly keyPrefix: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class OidcSessionConfigError extends Error {
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
export declare const REQUIRED_OIDC_SCOPE = "openid";
|
|
32
|
+
export declare function assertOidcSessionOptions(options: OidcSessionOptions): OidcSessionOptions;
|
|
33
|
+
//# sourceMappingURL=oidc-session-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-session-options.d.ts","sourceRoot":"","sources":["../../src/config/oidc-session-options.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,mBAAmB;IAQlC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAM1B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAM/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAKxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAGD,MAAM,WAAW,oBAAoB;IAEnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAMtB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAOtB,QAAQ,CAAC,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;CAC9C;AAGD,MAAM,WAAW,iBAAiB;IAMhC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAKhC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAMpC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAOpC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAGD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IACtC,QAAQ,CAAC,GAAG,EAAE,iBAAiB,CAAC;IAMhC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAGD,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAGD,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAU5C,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,kBAAkB,GAC1B,kBAAkB,CAwDpB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REQUIRED_OIDC_SCOPE = exports.OidcSessionConfigError = void 0;
|
|
4
|
+
exports.assertOidcSessionOptions = assertOidcSessionOptions;
|
|
5
|
+
class OidcSessionConfigError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(`[oidc-session-nest] ${message}`);
|
|
8
|
+
this.name = 'OidcSessionConfigError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.OidcSessionConfigError = OidcSessionConfigError;
|
|
12
|
+
exports.REQUIRED_OIDC_SCOPE = 'openid';
|
|
13
|
+
function assertOidcSessionOptions(options) {
|
|
14
|
+
const { oidc, cookie, ttl, keyPrefix } = options;
|
|
15
|
+
for (const [name, value] of [
|
|
16
|
+
['issuerUrl', oidc.issuerUrl],
|
|
17
|
+
['clientId', oidc.clientId],
|
|
18
|
+
['redirectUri', oidc.redirectUri],
|
|
19
|
+
['cookie.name', cookie.name],
|
|
20
|
+
['keyPrefix', keyPrefix],
|
|
21
|
+
]) {
|
|
22
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
23
|
+
throw new OidcSessionConfigError(`${name} must be a non-empty string.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
assertAbsoluteHttpUrl('issuerUrl', oidc.issuerUrl);
|
|
27
|
+
assertAbsoluteHttpUrl('redirectUri', oidc.redirectUri);
|
|
28
|
+
if (oidc.postLogoutRedirectUri !== undefined) {
|
|
29
|
+
assertAbsoluteHttpUrl('postLogoutRedirectUri', oidc.postLogoutRedirectUri);
|
|
30
|
+
}
|
|
31
|
+
if (!oidc.scope.split(/\s+/u).includes(exports.REQUIRED_OIDC_SCOPE)) {
|
|
32
|
+
throw new OidcSessionConfigError(`scope must include "${exports.REQUIRED_OIDC_SCOPE}"; got "${oidc.scope}".`);
|
|
33
|
+
}
|
|
34
|
+
for (const [name, value] of [
|
|
35
|
+
['ttl.idleTtlSeconds', ttl.idleTtlSeconds],
|
|
36
|
+
['ttl.absoluteTtlSeconds', ttl.absoluteTtlSeconds],
|
|
37
|
+
['ttl.refreshLeadSeconds', ttl.refreshLeadSeconds],
|
|
38
|
+
['ttl.refreshWaitMs', ttl.refreshWaitMs],
|
|
39
|
+
]) {
|
|
40
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
41
|
+
throw new OidcSessionConfigError(`${name} must be a positive finite number; got ${String(value)}.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (ttl.idleTtlSeconds > ttl.absoluteTtlSeconds) {
|
|
45
|
+
throw new OidcSessionConfigError(`ttl.idleTtlSeconds (${ttl.idleTtlSeconds}) exceeds ttl.absoluteTtlSeconds ` +
|
|
46
|
+
`(${ttl.absoluteTtlSeconds}), so the idle window could never be reached. ` +
|
|
47
|
+
'Lower the idle TTL or raise the absolute one.');
|
|
48
|
+
}
|
|
49
|
+
if (cookie.sameSite === 'none' && !cookie.secure) {
|
|
50
|
+
throw new OidcSessionConfigError('cookie.sameSite "none" requires cookie.secure — browsers reject the pair, ' +
|
|
51
|
+
'so the session cookie would be silently dropped on every response.');
|
|
52
|
+
}
|
|
53
|
+
return options;
|
|
54
|
+
}
|
|
55
|
+
function assertAbsoluteHttpUrl(name, value) {
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = new URL(value);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
throw new OidcSessionConfigError(`${name} must be an absolute URL; got "${value}".`);
|
|
62
|
+
}
|
|
63
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
64
|
+
throw new OidcSessionConfigError(`${name} must be http or https; got "${parsed.protocol}".`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=oidc-session-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-session-options.js","sourceRoot":"","sources":["../../src/config/oidc-session-options.ts"],"names":[],"mappings":";;;AA4HA,4DA0DC;AA5ED,MAAa,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;A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QAAQ,IAAI,CAC3D,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { HttpException, HttpStatus } from '@nestjs/common';
|
|
2
|
+
export declare enum OidcSessionErrorCode {
|
|
3
|
+
SessionRequired = "SESSION_REQUIRED",
|
|
4
|
+
SessionExpired = "SESSION_EXPIRED",
|
|
5
|
+
OidcCallbackRejected = "OIDC_CALLBACK_REJECTED",
|
|
6
|
+
OidcLoginStateUnknown = "OIDC_LOGIN_STATE_UNKNOWN",
|
|
7
|
+
OidcTokenEndpointFailed = "OIDC_TOKEN_ENDPOINT_FAILED",
|
|
8
|
+
SessionRefreshContended = "SESSION_REFRESH_CONTENDED"
|
|
9
|
+
}
|
|
10
|
+
export interface OidcSessionErrorBody {
|
|
11
|
+
readonly code: OidcSessionErrorCode;
|
|
12
|
+
readonly title: string;
|
|
13
|
+
readonly detail: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class OidcSessionError extends HttpException {
|
|
16
|
+
readonly code: OidcSessionErrorCode;
|
|
17
|
+
constructor(code: OidcSessionErrorCode, status: HttpStatus, title: string, detail: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class SessionRequiredError extends OidcSessionError {
|
|
20
|
+
constructor(detail?: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class SessionExpiredError extends OidcSessionError {
|
|
23
|
+
constructor(detail?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class OidcCallbackRejectedError extends OidcSessionError {
|
|
26
|
+
constructor(detail: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class OidcLoginStateUnknownError extends OidcSessionError {
|
|
29
|
+
constructor(detail?: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class OidcTokenEndpointFailedError extends OidcSessionError {
|
|
32
|
+
constructor(detail: string);
|
|
33
|
+
}
|
|
34
|
+
export declare class SessionRefreshContendedError extends OidcSessionError {
|
|
35
|
+
constructor(detail?: string);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAM3D,oBAAY,oBAAoB;IAE9B,eAAe,qBAAqB;IAOpC,cAAc,oBAAoB;IAElC,oBAAoB,2BAA2B;IAM/C,qBAAqB,6BAA6B;IAMlD,uBAAuB,+BAA+B;IAMtD,uBAAuB,8BAA8B;CACtD;AAGD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAGD,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;gBAGlC,IAAI,EAAE,oBAAoB,EAC1B,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM;CAYjB;AAED,qBAAa,oBAAqB,SAAQ,gBAAgB;gBAC5C,MAAM,SAAgD;CAQnE;AAED,qBAAa,mBAAoB,SAAQ,gBAAgB;gBAC3C,MAAM,SAAsD;CAQzE;AAED,qBAAa,yBAA0B,SAAQ,gBAAgB;gBACjD,MAAM,EAAE,MAAM;CAQ3B;AAED,qBAAa,0BAA2B,SAAQ,gBAAgB;gBAE5D,MAAM,SAAgF;CASzF;AAED,qBAAa,4BAA6B,SAAQ,gBAAgB;gBACpD,MAAM,EAAE,MAAM;CAQ3B;AAED,qBAAa,4BAA6B,SAAQ,gBAAgB;gBAE9D,MAAM,SAA+D;CASxE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SessionRefreshContendedError = exports.OidcTokenEndpointFailedError = exports.OidcLoginStateUnknownError = exports.OidcCallbackRejectedError = exports.SessionExpiredError = exports.SessionRequiredError = exports.OidcSessionError = exports.OidcSessionErrorCode = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
var OidcSessionErrorCode;
|
|
6
|
+
(function (OidcSessionErrorCode) {
|
|
7
|
+
OidcSessionErrorCode["SessionRequired"] = "SESSION_REQUIRED";
|
|
8
|
+
OidcSessionErrorCode["SessionExpired"] = "SESSION_EXPIRED";
|
|
9
|
+
OidcSessionErrorCode["OidcCallbackRejected"] = "OIDC_CALLBACK_REJECTED";
|
|
10
|
+
OidcSessionErrorCode["OidcLoginStateUnknown"] = "OIDC_LOGIN_STATE_UNKNOWN";
|
|
11
|
+
OidcSessionErrorCode["OidcTokenEndpointFailed"] = "OIDC_TOKEN_ENDPOINT_FAILED";
|
|
12
|
+
OidcSessionErrorCode["SessionRefreshContended"] = "SESSION_REFRESH_CONTENDED";
|
|
13
|
+
})(OidcSessionErrorCode || (exports.OidcSessionErrorCode = OidcSessionErrorCode = {}));
|
|
14
|
+
class OidcSessionError extends common_1.HttpException {
|
|
15
|
+
code;
|
|
16
|
+
constructor(code, status, title, detail) {
|
|
17
|
+
const body = { code, title, detail };
|
|
18
|
+
super(body, status);
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.message = detail;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.OidcSessionError = OidcSessionError;
|
|
24
|
+
class SessionRequiredError extends OidcSessionError {
|
|
25
|
+
constructor(detail = 'This endpoint requires a signed-in session.') {
|
|
26
|
+
super(OidcSessionErrorCode.SessionRequired, common_1.HttpStatus.UNAUTHORIZED, 'Session required', detail);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.SessionRequiredError = SessionRequiredError;
|
|
30
|
+
class SessionExpiredError extends OidcSessionError {
|
|
31
|
+
constructor(detail = 'The session has ended. Sign in again to continue.') {
|
|
32
|
+
super(OidcSessionErrorCode.SessionExpired, common_1.HttpStatus.UNAUTHORIZED, 'Session expired', detail);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.SessionExpiredError = SessionExpiredError;
|
|
36
|
+
class OidcCallbackRejectedError extends OidcSessionError {
|
|
37
|
+
constructor(detail) {
|
|
38
|
+
super(OidcSessionErrorCode.OidcCallbackRejected, common_1.HttpStatus.BAD_REQUEST, 'Sign-in was rejected', detail);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.OidcCallbackRejectedError = OidcCallbackRejectedError;
|
|
42
|
+
class OidcLoginStateUnknownError extends OidcSessionError {
|
|
43
|
+
constructor(detail = 'This sign-in attempt is unknown, already used, or has expired. Start again.') {
|
|
44
|
+
super(OidcSessionErrorCode.OidcLoginStateUnknown, common_1.HttpStatus.BAD_REQUEST, 'Unknown sign-in attempt', detail);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.OidcLoginStateUnknownError = OidcLoginStateUnknownError;
|
|
48
|
+
class OidcTokenEndpointFailedError extends OidcSessionError {
|
|
49
|
+
constructor(detail) {
|
|
50
|
+
super(OidcSessionErrorCode.OidcTokenEndpointFailed, common_1.HttpStatus.BAD_GATEWAY, 'Identity provider unavailable', detail);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.OidcTokenEndpointFailedError = OidcTokenEndpointFailedError;
|
|
54
|
+
class SessionRefreshContendedError extends OidcSessionError {
|
|
55
|
+
constructor(detail = 'Another request is refreshing this session. Retry shortly.') {
|
|
56
|
+
super(OidcSessionErrorCode.SessionRefreshContended, common_1.HttpStatus.SERVICE_UNAVAILABLE, 'Session refresh in progress', detail);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.SessionRefreshContendedError = SessionRefreshContendedError;
|
|
60
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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