@tstdl/base 0.93.139 → 0.93.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +166 -0
- package/ai/genkit/multi-region.plugin.js +5 -3
- package/ai/genkit/tests/multi-region.test.d.ts +1 -0
- package/ai/genkit/tests/multi-region.test.js +5 -2
- package/ai/parser/parser.js +2 -2
- package/ai/prompts/build.js +1 -0
- package/ai/prompts/instructions-formatter.d.ts +15 -2
- package/ai/prompts/instructions-formatter.js +36 -31
- package/ai/prompts/prompt-builder.js +5 -5
- package/ai/prompts/steering.d.ts +3 -2
- package/ai/prompts/steering.js +3 -1
- package/ai/tests/instructions-formatter.test.js +1 -0
- package/api/README.md +403 -0
- package/api/client/client.js +7 -13
- package/api/client/tests/api-client.test.js +10 -10
- package/api/default-error-handlers.js +1 -1
- package/api/response.d.ts +2 -2
- package/api/response.js +22 -33
- package/api/server/api-controller.d.ts +1 -1
- package/api/server/api-controller.js +3 -3
- package/api/server/api-request-token.provider.d.ts +1 -0
- package/api/server/api-request-token.provider.js +1 -0
- package/api/server/middlewares/allowed-methods.middleware.js +2 -1
- package/api/server/middlewares/content-type.middleware.js +2 -1
- package/api/types.d.ts +3 -2
- package/application/README.md +240 -0
- package/application/application.d.ts +1 -1
- package/application/application.js +3 -3
- package/application/providers.d.ts +20 -2
- package/application/providers.js +34 -7
- package/audit/README.md +267 -0
- package/audit/module.d.ts +5 -0
- package/audit/module.js +9 -1
- package/authentication/README.md +288 -0
- package/authentication/client/authentication.service.d.ts +12 -11
- package/authentication/client/authentication.service.js +21 -21
- package/authentication/client/http-client.middleware.js +2 -2
- package/authentication/server/module.d.ts +5 -0
- package/authentication/server/module.js +9 -1
- package/authentication/tests/authentication.api-controller.test.js +1 -1
- package/authentication/tests/authentication.api-request-token.provider.test.js +1 -1
- package/authentication/tests/authentication.client-error-handling.test.js +2 -1
- package/authentication/tests/authentication.client-service-refresh.test.js +5 -3
- package/authentication/tests/authentication.client-service.test.js +1 -1
- package/browser/README.md +401 -0
- package/cancellation/README.md +156 -0
- package/cancellation/tests/coverage.test.d.ts +1 -0
- package/cancellation/tests/coverage.test.js +49 -0
- package/cancellation/tests/leak.test.js +24 -29
- package/cancellation/tests/token.test.d.ts +1 -0
- package/cancellation/tests/token.test.js +136 -0
- package/cancellation/token.d.ts +53 -177
- package/cancellation/token.js +132 -208
- package/circuit-breaker/postgres/module.d.ts +1 -0
- package/circuit-breaker/postgres/module.js +5 -1
- package/context/README.md +174 -0
- package/cookie/README.md +161 -0
- package/css/README.md +157 -0
- package/data-structures/README.md +320 -0
- package/decorators/README.md +140 -0
- package/distributed-loop/README.md +231 -0
- package/distributed-loop/distributed-loop.js +1 -1
- package/document-management/README.md +403 -0
- package/document-management/server/configure.js +5 -1
- package/document-management/server/module.d.ts +1 -1
- package/document-management/server/module.js +1 -1
- package/document-management/server/services/document-management-ancillary.service.js +1 -1
- package/document-management/server/services/document-management.service.js +9 -7
- package/document-management/tests/ai-config-hierarchy.test.js +0 -5
- package/document-management/tests/document-management-ai-overrides.test.js +0 -1
- package/document-management/tests/document-management-core.test.js +2 -7
- package/document-management/tests/document-management.api.test.js +6 -7
- package/document-management/tests/document-statistics.service.test.js +11 -12
- package/document-management/tests/document-validation-ai-overrides.test.js +0 -1
- package/document-management/tests/document.service.test.js +3 -3
- package/document-management/tests/enum-helpers.test.js +2 -3
- package/dom/README.md +213 -0
- package/enumerable/README.md +259 -0
- package/enumeration/README.md +121 -0
- package/errors/README.md +267 -0
- package/examples/document-management/main.d.ts +1 -0
- package/examples/document-management/main.js +14 -11
- package/file/README.md +191 -0
- package/formats/README.md +210 -0
- package/function/README.md +144 -0
- package/http/README.md +318 -0
- package/http/client/adapters/undici.adapter.js +1 -1
- package/http/client/http-client-request.d.ts +6 -5
- package/http/client/http-client-request.js +8 -9
- package/http/server/node/node-http-server.js +1 -2
- package/image-service/README.md +137 -0
- package/injector/README.md +491 -0
- package/intl/README.md +113 -0
- package/json-path/README.md +182 -0
- package/jsx/README.md +154 -0
- package/key-value-store/README.md +191 -0
- package/key-value-store/postgres/module.d.ts +1 -0
- package/key-value-store/postgres/module.js +5 -1
- package/lock/README.md +249 -0
- package/lock/postgres/module.d.ts +1 -0
- package/lock/postgres/module.js +5 -1
- package/lock/web/web-lock.js +119 -47
- package/logger/README.md +287 -0
- package/mail/README.md +256 -0
- package/mail/module.d.ts +5 -1
- package/mail/module.js +11 -6
- package/memory/README.md +144 -0
- package/message-bus/README.md +244 -0
- package/message-bus/message-bus-base.js +1 -1
- package/module/README.md +182 -0
- package/module/module.d.ts +1 -1
- package/module/module.js +77 -17
- package/module/modules/web-server.module.js +3 -4
- package/notification/server/module.d.ts +1 -0
- package/notification/server/module.js +5 -1
- package/notification/tests/notification-flow.test.js +2 -2
- package/notification/tests/notification-type.service.test.js +24 -15
- package/object-storage/README.md +300 -0
- package/openid-connect/README.md +274 -0
- package/orm/README.md +423 -0
- package/orm/decorators.d.ts +5 -1
- package/orm/decorators.js +1 -1
- package/orm/server/drizzle/schema-converter.js +17 -30
- package/orm/server/encryption.d.ts +0 -1
- package/orm/server/encryption.js +1 -4
- package/orm/server/index.d.ts +1 -6
- package/orm/server/index.js +1 -6
- package/orm/server/migration.d.ts +19 -0
- package/orm/server/migration.js +72 -0
- package/orm/server/repository.d.ts +1 -1
- package/orm/server/transaction.d.ts +5 -10
- package/orm/server/transaction.js +22 -26
- package/orm/server/transactional.js +3 -3
- package/orm/tests/database-migration.test.d.ts +1 -0
- package/orm/tests/database-migration.test.js +82 -0
- package/orm/tests/encryption.test.js +3 -4
- package/orm/utils.d.ts +17 -2
- package/orm/utils.js +49 -1
- package/package.json +9 -6
- package/password/README.md +164 -0
- package/pdf/README.md +246 -0
- package/polyfills.js +1 -0
- package/pool/README.md +198 -0
- package/process/README.md +237 -0
- package/promise/README.md +252 -0
- package/promise/cancelable-promise.js +1 -1
- package/random/README.md +193 -0
- package/rate-limit/postgres/module.d.ts +1 -0
- package/rate-limit/postgres/module.js +5 -1
- package/reflection/README.md +305 -0
- package/reflection/decorator-data.js +11 -12
- package/rpc/README.md +386 -0
- package/rxjs-utils/README.md +262 -0
- package/schema/README.md +342 -0
- package/serializer/README.md +342 -0
- package/signals/implementation/README.md +134 -0
- package/sse/README.md +278 -0
- package/task-queue/README.md +293 -0
- package/task-queue/postgres/drizzle/{0000_simple_invisible_woman.sql → 0000_wakeful_sunspot.sql} +22 -14
- package/task-queue/postgres/drizzle/meta/0000_snapshot.json +160 -82
- package/task-queue/postgres/drizzle/meta/_journal.json +2 -2
- package/task-queue/postgres/module.d.ts +1 -0
- package/task-queue/postgres/module.js +5 -1
- package/task-queue/postgres/schemas.d.ts +9 -6
- package/task-queue/postgres/schemas.js +4 -3
- package/task-queue/postgres/task-queue.d.ts +4 -13
- package/task-queue/postgres/task-queue.js +462 -355
- package/task-queue/postgres/task.model.d.ts +12 -5
- package/task-queue/postgres/task.model.js +51 -25
- package/task-queue/task-context.d.ts +2 -2
- package/task-queue/task-context.js +8 -8
- package/task-queue/task-queue.d.ts +53 -19
- package/task-queue/task-queue.js +121 -55
- package/task-queue/tests/cascading-cancellations.test.d.ts +1 -0
- package/task-queue/tests/cascading-cancellations.test.js +38 -0
- package/task-queue/tests/complex.test.js +45 -229
- package/task-queue/tests/coverage-branch.test.d.ts +1 -0
- package/task-queue/tests/coverage-branch.test.js +407 -0
- package/task-queue/tests/coverage-enhancement.test.d.ts +1 -0
- package/task-queue/tests/coverage-enhancement.test.js +144 -0
- package/task-queue/tests/dag-dependencies.test.d.ts +1 -0
- package/task-queue/tests/dag-dependencies.test.js +41 -0
- package/task-queue/tests/dependencies.test.js +28 -26
- package/task-queue/tests/extensive-dependencies.test.js +64 -139
- package/task-queue/tests/fan-out-spawning.test.d.ts +1 -0
- package/task-queue/tests/fan-out-spawning.test.js +53 -0
- package/task-queue/tests/idempotent-replacement.test.d.ts +1 -0
- package/task-queue/tests/idempotent-replacement.test.js +61 -0
- package/task-queue/tests/missing-idempotent-tasks.test.d.ts +1 -0
- package/task-queue/tests/missing-idempotent-tasks.test.js +38 -0
- package/task-queue/tests/queue.test.js +128 -8
- package/task-queue/tests/worker.test.js +39 -16
- package/task-queue/tests/zombie-parent.test.d.ts +1 -0
- package/task-queue/tests/zombie-parent.test.js +45 -0
- package/task-queue/tests/zombie-recovery.test.d.ts +1 -0
- package/task-queue/tests/zombie-recovery.test.js +51 -0
- package/templates/README.md +287 -0
- package/test5.js +5 -5
- package/testing/README.md +157 -0
- package/testing/integration-setup.d.ts +4 -4
- package/testing/integration-setup.js +54 -29
- package/text/README.md +346 -0
- package/text/localization.service.js +2 -2
- package/threading/README.md +238 -0
- package/types/README.md +311 -0
- package/utils/README.md +322 -0
- package/utils/async-iterable-helpers/observable-iterable.d.ts +1 -1
- package/utils/async-iterable-helpers/observable-iterable.js +4 -8
- package/utils/async-iterable-helpers/take-until.js +4 -4
- package/utils/backoff.js +89 -30
- package/utils/file-reader.js +1 -2
- package/utils/retry-with-backoff.js +1 -1
- package/utils/timer.d.ts +1 -1
- package/utils/timer.js +5 -7
- package/utils/timing.d.ts +1 -1
- package/utils/timing.js +2 -4
- package/utils/z-base32.d.ts +1 -0
- package/utils/z-base32.js +1 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# OpenID Connect
|
|
2
|
+
|
|
3
|
+
A robust, type-safe OpenID Connect (OIDC) client implementation for TypeScript applications. It simplifies integration with OIDC providers by handling configuration discovery, secure state management, PKCE, and token exchanges.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Features](#-features)
|
|
8
|
+
- [Core Concepts](#core-concepts)
|
|
9
|
+
- [Prerequisites](#prerequisites)
|
|
10
|
+
- [🚀 Basic Usage](#-basic-usage)
|
|
11
|
+
- [1. Setup & Configuration](#1-setup--configuration)
|
|
12
|
+
- [2. Initiating Authorization (Login)](#2-initiating-authorization-login)
|
|
13
|
+
- [3. Handling the Callback](#3-handling-the-callback)
|
|
14
|
+
- [🔧 Advanced Topics](#-advanced-topics)
|
|
15
|
+
- [Client Credentials Flow](#client-credentials-flow)
|
|
16
|
+
- [Refreshing Tokens](#refreshing-tokens)
|
|
17
|
+
- [Fetching User Info](#fetching-user-info)
|
|
18
|
+
- [Custom State Data](#custom-state-data)
|
|
19
|
+
- [📚 API](#-api)
|
|
20
|
+
|
|
21
|
+
## ✨ Features
|
|
22
|
+
|
|
23
|
+
- **Auto-Discovery**: Automatically fetches and caches provider configuration from `.well-known/openid-configuration`.
|
|
24
|
+
- **Secure by Default**: Implements Authorization Code Flow with **PKCE** (Proof Key for Code Exchange, SHA-256) and cryptographically secure state generation.
|
|
25
|
+
- **State Persistence**: Persists authorization state via the ORM to securely validate callbacks and prevent CSRF/replay attacks.
|
|
26
|
+
- **Multiple Flows**: Supports Authorization Code and Client Credentials flows.
|
|
27
|
+
- **Automated Authentication**: Supports both `body` and `basic-auth` authentication methods for token endpoints.
|
|
28
|
+
- **Token Management**: Simple methods to exchange codes for tokens, refresh existing tokens, and fetch user info.
|
|
29
|
+
- **Type-Safe**: Full TypeScript support for token responses and custom state data.
|
|
30
|
+
|
|
31
|
+
## Core Concepts
|
|
32
|
+
|
|
33
|
+
### OidcService
|
|
34
|
+
|
|
35
|
+
The central service class. It orchestrates the entire flow: fetching configuration, generating secure parameters, storing state in the database, and communicating with the OIDC provider to exchange tokens.
|
|
36
|
+
|
|
37
|
+
### OidcState
|
|
38
|
+
|
|
39
|
+
An entity model used to persist the state of an authentication attempt. It stores:
|
|
40
|
+
|
|
41
|
+
- The generated `state` string (for CSRF protection).
|
|
42
|
+
- The `codeVerifier` (for PKCE).
|
|
43
|
+
- Configuration details (endpoint, client ID).
|
|
44
|
+
- Optional custom `data` attached to the flow.
|
|
45
|
+
|
|
46
|
+
This entity must be registered with your ORM configuration so the service can save and retrieve it during the callback phase.
|
|
47
|
+
|
|
48
|
+
## Prerequisites
|
|
49
|
+
|
|
50
|
+
This module relies on the `@tstdl/base/orm` module to store the `OidcState`. Ensure your application has the ORM configured and the `OidcState` entity is included in your database schema.
|
|
51
|
+
|
|
52
|
+
## 🚀 Basic Usage
|
|
53
|
+
|
|
54
|
+
This example demonstrates the standard **Authorization Code Flow** with PKCE, commonly used for user login.
|
|
55
|
+
|
|
56
|
+
### 1. Setup & Configuration
|
|
57
|
+
|
|
58
|
+
Ensure `OidcState` is registered in your ORM configuration (e.g., in your `bootstrap.ts` or module configuration).
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { configureOrm } from '@tstdl/base/orm/server';
|
|
62
|
+
import { OidcState } from '@tstdl/base/openid-connect';
|
|
63
|
+
|
|
64
|
+
// In your bootstrap/configuration file
|
|
65
|
+
configureOrm({
|
|
66
|
+
// ... connection settings
|
|
67
|
+
entities: [
|
|
68
|
+
// ... other entities
|
|
69
|
+
OidcState, // <--- Register the OidcState entity
|
|
70
|
+
],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 2. Initiating Authorization (Login)
|
|
75
|
+
|
|
76
|
+
When a user clicks "Login", generate the authorization URL. This creates a state record in the database.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { inject } from '@tstdl/base/injector';
|
|
80
|
+
import { OidcService } from '@tstdl/base/openid-connect';
|
|
81
|
+
import { millisecondsPerMinute } from '@tstdl/base/utils/units';
|
|
82
|
+
|
|
83
|
+
class AuthService {
|
|
84
|
+
// Inject the OidcService. You can type the generic to define custom data stored in state.
|
|
85
|
+
readonly oidcService = inject(OidcService<void>);
|
|
86
|
+
|
|
87
|
+
async getLoginUrl(): Promise<string> {
|
|
88
|
+
const result = await this.oidcService.initAuthorization({
|
|
89
|
+
endpoint: 'https://accounts.google.com', // The OIDC provider URL
|
|
90
|
+
clientId: 'my-client-id',
|
|
91
|
+
clientSecret: 'my-client-secret',
|
|
92
|
+
scope: 'openid profile email',
|
|
93
|
+
expiration: 5 * millisecondsPerMinute, // How long the login attempt is valid
|
|
94
|
+
data: undefined, // No custom data for this example
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Construct the URL to redirect the user to
|
|
98
|
+
const url = new URL(result.authorizationEndpoint);
|
|
99
|
+
url.searchParams.set('response_type', 'code');
|
|
100
|
+
url.searchParams.set('client_id', result.clientId);
|
|
101
|
+
url.searchParams.set('scope', result.scope);
|
|
102
|
+
url.searchParams.set('redirect_uri', 'https://myapp.com/callback');
|
|
103
|
+
url.searchParams.set('state', result.state);
|
|
104
|
+
url.searchParams.set('code_challenge', result.codeChallenge);
|
|
105
|
+
url.searchParams.set('code_challenge_method', result.codeChallengeMethod);
|
|
106
|
+
|
|
107
|
+
return url.toString();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 3. Handling the Callback
|
|
113
|
+
|
|
114
|
+
When the user is redirected back to your application (e.g., `https://myapp.com/callback?code=...&state=...`), validate the state and exchange the code for tokens.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { inject } from '@tstdl/base/injector';
|
|
118
|
+
import { OidcService } from '@tstdl/base/openid-connect';
|
|
119
|
+
|
|
120
|
+
class CallbackController {
|
|
121
|
+
readonly oidcService = inject(OidcService<void>);
|
|
122
|
+
|
|
123
|
+
async handleCallback(code: string, state: string): Promise<void> {
|
|
124
|
+
// 1. Validate and retrieve the stored state.
|
|
125
|
+
// This throws if the state is invalid, expired, or missing.
|
|
126
|
+
// It also deletes the state from the DB to prevent replay attacks.
|
|
127
|
+
const storedState = await this.oidcService.validateState(state);
|
|
128
|
+
|
|
129
|
+
// 2. Exchange the authorization code for tokens
|
|
130
|
+
const tokenResponse = await this.oidcService.getToken({
|
|
131
|
+
grantType: 'authorization_code',
|
|
132
|
+
endpoint: storedState.endpoint,
|
|
133
|
+
clientId: storedState.clientId,
|
|
134
|
+
clientSecret: storedState.clientSecret,
|
|
135
|
+
code: code,
|
|
136
|
+
codeVerifier: storedState.codeVerifier, // Retrieved from DB
|
|
137
|
+
redirectUri: 'https://myapp.com/callback',
|
|
138
|
+
authType: 'body', // or 'basic-auth' depending on provider
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
console.log('Access Token:', tokenResponse.accessToken);
|
|
142
|
+
console.log('ID Token:', tokenResponse.idToken);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 🔧 Advanced Topics
|
|
148
|
+
|
|
149
|
+
### Client Credentials Flow
|
|
150
|
+
|
|
151
|
+
Used for machine-to-machine communication where no user is involved.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
const token = await oidcService.getToken({
|
|
155
|
+
grantType: 'client_credentials',
|
|
156
|
+
endpoint: 'https://auth.example.com',
|
|
157
|
+
clientId: 'service-account-id',
|
|
158
|
+
clientSecret: 'service-account-secret',
|
|
159
|
+
scope: 'api:read',
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Refreshing Tokens
|
|
164
|
+
|
|
165
|
+
If you received a `refresh_token` in the initial flow, you can use it to get a new access token.
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
const newToken = await oidcService.refreshToken({
|
|
169
|
+
endpoint: 'https://accounts.google.com',
|
|
170
|
+
clientId: 'my-client-id',
|
|
171
|
+
clientSecret: 'my-client-secret',
|
|
172
|
+
refreshToken: 'existing-refresh-token',
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Fetching User Info
|
|
177
|
+
|
|
178
|
+
Retrieve the user's profile information using the `userinfo_endpoint` discovered from the configuration.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const userInfo = await oidcService.getUserInfo(
|
|
182
|
+
'https://accounts.google.com',
|
|
183
|
+
tokenResponse, // The object returned from getToken
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
console.log(userInfo);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Custom State Data
|
|
190
|
+
|
|
191
|
+
You can attach custom data to the `OidcState` when initializing authorization. This is useful for remembering where to redirect the user after login, storing a nonce, or keeping track of the original request's context.
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
type MyCustomData = { returnUrl: string };
|
|
195
|
+
|
|
196
|
+
// Define a service or inject directly with the desired type
|
|
197
|
+
const oidcService = inject(OidcService<MyCustomData>);
|
|
198
|
+
|
|
199
|
+
// Initialize
|
|
200
|
+
const result = await oidcService.initAuthorization({
|
|
201
|
+
// ... other params
|
|
202
|
+
data: { returnUrl: '/dashboard/settings' },
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// ... later in callback ...
|
|
206
|
+
|
|
207
|
+
const storedState = await oidcService.validateState(state);
|
|
208
|
+
const returnUrl = storedState.data.returnUrl; // Properly typed as string
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Additional Parameters and Auth Types
|
|
212
|
+
|
|
213
|
+
Some OIDC providers require additional parameters during token exchange or use a different authentication method.
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
const tokenResponse = await oidcService.getToken({
|
|
217
|
+
grantType: 'authorization_code',
|
|
218
|
+
// ...
|
|
219
|
+
authType: 'basic-auth', // Uses HTTP Basic Auth (clientId:clientSecret)
|
|
220
|
+
}, {
|
|
221
|
+
// Additional form-data parameters (some providers require 'resource')
|
|
222
|
+
resource: 'https://api.example.com',
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## ⚠️ Error Handling
|
|
227
|
+
|
|
228
|
+
The `OidcService` utilizes standard errors from the library:
|
|
229
|
+
|
|
230
|
+
- `ForbiddenError`: Thrown by `validateState` if the state is missing, invalid, or already used (to prevent replay attacks).
|
|
231
|
+
- `NotImplementedError`: Thrown if an unsupported grant type or authentication type is requested.
|
|
232
|
+
- `Error`: Thrown if required endpoints (like `userinfo_endpoint`) are not present in the provider's configuration.
|
|
233
|
+
|
|
234
|
+
Always wrap callback logic in a `try...catch` block to handle these cases gracefully.
|
|
235
|
+
|
|
236
|
+
## 📚 API
|
|
237
|
+
|
|
238
|
+
### Services
|
|
239
|
+
|
|
240
|
+
| Class | Description |
|
|
241
|
+
| :------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
242
|
+
| `OidcService<Data>` | Main service for OIDC operations. Handles state creation, validation, token exchange, and user info retrieval. |
|
|
243
|
+
| `OidcConfigurationService` | Fetches OIDC configuration from the provider's well-known endpoint. |
|
|
244
|
+
| `CachedOidcConfigurationService` | A cached implementation of `OidcConfigurationService`. Used by default with a 5-minute cache duration (configurable via dependency injection). |
|
|
245
|
+
|
|
246
|
+
### OidcService Methods
|
|
247
|
+
|
|
248
|
+
| Method | Description |
|
|
249
|
+
| :------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------ |
|
|
250
|
+
| `initAuthorization(params)` | Discovers configuration, creates a secure state in the DB, and returns data to build the redirect URL. |
|
|
251
|
+
| `validateState(state)` | Attempts to load a state by its value, then **deletes it**. Throws if not found. Essential for security. |
|
|
252
|
+
| `getState(state)` | Just retrieves the state without deleting it. |
|
|
253
|
+
| `deleteState(state)` | Manually removes a state from the database. |
|
|
254
|
+
| `getToken(params, additionalData?)` | Exchanges a code (or credentials) for tokens. Supports `authorization_code` and `client_credentials`. |
|
|
255
|
+
| `refreshToken(params)` | Uses a refresh token to obtain a new set of tokens. |
|
|
256
|
+
| `getUserInfo(endpoint, token)` | Fetches the user's profile information using the access token. |
|
|
257
|
+
| `oidcConfigurationService.getConfiguration` | Directly fetches (and potentially caches) the OIDC provider's configuration. |
|
|
258
|
+
|
|
259
|
+
### Models
|
|
260
|
+
|
|
261
|
+
| Class | Description |
|
|
262
|
+
| :---------------- | :------------------------------------------------------------------------------------------------------------------------------------- |
|
|
263
|
+
| `OidcState<Data>` | Database entity representing the authorization state. Must be registered with ORM. Uses the `oidc` schema and `state` table by default. |
|
|
264
|
+
|
|
265
|
+
### Types & Interfaces
|
|
266
|
+
|
|
267
|
+
| Type | Description |
|
|
268
|
+
| :--------------------------- | :----------------------------------------------------------------------------------------------- |
|
|
269
|
+
| `OidcInitParameters<Data>` | Parameters for `initAuthorization` (endpoint, client details, scope, expiration, custom data). |
|
|
270
|
+
| `OidcInitResult` | Result of initialization, containing `authorizationEndpoint`, `state`, and PKCE `codeChallenge`. |
|
|
271
|
+
| `OidcToken<Raw>` | Represents the token response, including `accessToken`, `idToken`, `refreshToken`, and `raw` JSON. |
|
|
272
|
+
| `OidcGetTokenParameters` | Union type for token requests. Includes `authType` (`body` \| `basic-auth`). |
|
|
273
|
+
| `OidcRefreshTokenParameters` | Parameters for refreshing a token. |
|
|
274
|
+
| `OidcConfiguration` | Discovered provider endpoints (authorization, token, userInfo, etc.). |
|