@yielded/auth 0.1.0-beta.2 → 0.1.0-beta.3
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/dist/DrizzleD1.d.mts +12 -12
- package/dist/DrizzleMysql2.d.mts +2 -2
- package/dist/DrizzlePglite.d.mts +2 -2
- package/dist/DrizzlePostgres.d.mts +14 -14
- package/dist/DrizzleSqliteBun.d.mts +8 -8
- package/dist/DrizzleSqliteNode.d.mts +2 -2
- package/dist/DrizzleSqliteWasm.d.mts +14 -14
- package/dist/GitHub.d.mts +2 -2
- package/dist/GitHub.mjs +2 -2
- package/dist/OpenIdClientConnected.d.mts +1 -1
- package/dist/drizzle/d1-oauth.d.mts +4 -4
- package/dist/oauth/github/protocol.d.mts +7 -3
- package/dist/oauth/github/protocol.mjs +22 -9
- package/dist/oauth/github/protocol.mjs.map +1 -1
- package/dist/oauth/openid-client/compatibility.d.mts +22 -1
- package/dist/oauth/openid-client/compatibility.mjs +6 -1
- package/dist/oauth/openid-client/compatibility.mjs.map +1 -1
- package/dist/oauth/openid-client/configuration.mjs +2 -0
- package/dist/oauth/openid-client/configuration.mjs.map +1 -1
- package/dist/oauth/openid-client/connected/protocol.d.mts +1 -1
- package/dist/oauth/openid-client/models.d.mts +3 -0
- package/dist/oauth/openid-client/models.mjs.map +1 -1
- package/dist/oauth/openid-client/protocol.d.mts +0 -1
- package/dist/oauth/openid-client/protocol.mjs +7 -7
- package/dist/oauth/openid-client/protocol.mjs.map +1 -1
- package/package.json +1 -1
- package/src/GitHub.ts +1 -0
- package/src/oauth/github/protocol.ts +27 -8
- package/src/oauth/openid-client/compatibility.ts +13 -0
- package/src/oauth/openid-client/configuration.ts +2 -0
- package/src/oauth/openid-client/models.ts +3 -0
- package/src/oauth/openid-client/protocol.ts +6 -22
package/src/GitHub.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { OpenIdClientConfigurationError } from "./oauth/openid-client/models";
|
|
|
9
9
|
export {
|
|
10
10
|
gitHubOAuthAppConnectedProtocolLayer,
|
|
11
11
|
gitHubOAuthAppProtocolLayer,
|
|
12
|
+
gitHubOAuthAppProvider,
|
|
12
13
|
makeGitHubOAuthAppConnectedProtocol,
|
|
13
14
|
makeGitHubOAuthAppProtocol,
|
|
14
15
|
} from "./oauth/github/protocol";
|
|
@@ -6,6 +6,7 @@ import { OAuthConnectedProtocol } from "../OAuthConnectedProtocol";
|
|
|
6
6
|
import { OAuthProtocol } from "../OAuthProtocol";
|
|
7
7
|
import {
|
|
8
8
|
DefiniteTokenRejection,
|
|
9
|
+
tokenCompatibility,
|
|
9
10
|
type ConnectedCompatibility,
|
|
10
11
|
} from "../openid-client/compatibility";
|
|
11
12
|
import { makeConnectedProtocolWithCompatibility } from "../openid-client/connected/protocol";
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
OpenIdClientConfigurationError,
|
|
14
15
|
type OpenIdClientOAuthProvider,
|
|
15
16
|
} from "../openid-client/models";
|
|
16
|
-
import {
|
|
17
|
+
import { makeOpenIdClientOAuthProtocol } from "../openid-client/protocol";
|
|
17
18
|
import { ProviderRevocation } from "../openid-client/ProviderRevocation";
|
|
18
19
|
import { boundedFetch } from "../openid-client/transport";
|
|
19
20
|
import { OAuthUnavailable } from "../signInErrors";
|
|
@@ -265,6 +266,27 @@ const revocationLayer = (
|
|
|
265
266
|
);
|
|
266
267
|
};
|
|
267
268
|
|
|
269
|
+
/** A GitHub.com OAuth App generation for the same provider list as generic OIDC.
|
|
270
|
+
* Retains GitHub receipt/error rules and requests read:user, with no repository access.
|
|
271
|
+
* Construction performs no I/O; invalid configuration throws the typed configuration error. */
|
|
272
|
+
export const gitHubOAuthAppProvider = (
|
|
273
|
+
registration: GitHubOAuthAppGeneration,
|
|
274
|
+
): OpenIdClientOAuthProvider => {
|
|
275
|
+
let saved: GitHubOAuthAppGeneration;
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
saved = snapshotOAuthSync(generation, registration);
|
|
279
|
+
} catch {
|
|
280
|
+
throw invalid();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
...provider(saved),
|
|
285
|
+
scopes: ["read:user"],
|
|
286
|
+
[tokenCompatibility]: compatibility,
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
|
|
268
290
|
export const makeGitHubOAuthAppProtocol = Effect.fn("makeGitHubOAuthAppProtocol")(function* (
|
|
269
291
|
options: GitHubOAuthAppProtocolOptions,
|
|
270
292
|
) {
|
|
@@ -273,13 +295,10 @@ export const makeGitHubOAuthAppProtocol = Effect.fn("makeGitHubOAuthAppProtocol"
|
|
|
273
295
|
if (saved.registrations.filter((item) => item.issuance === "active").length !== 1)
|
|
274
296
|
return yield* invalid();
|
|
275
297
|
|
|
276
|
-
return yield*
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
},
|
|
281
|
-
compatibility,
|
|
282
|
-
);
|
|
298
|
+
return yield* makeOpenIdClientOAuthProtocol({
|
|
299
|
+
...saved,
|
|
300
|
+
providers: saved.registrations.map(gitHubOAuthAppProvider),
|
|
301
|
+
});
|
|
283
302
|
});
|
|
284
303
|
|
|
285
304
|
export const makeGitHubOAuthAppConnectedProtocol = Effect.fn("makeGitHubOAuthAppConnectedProtocol")(
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Predicate, Schema } from "effect";
|
|
2
|
+
|
|
1
3
|
import type {
|
|
2
4
|
OpenIdClientConnectedOAuthProvider,
|
|
3
5
|
OpenIdClientConnectedProtocolOptions,
|
|
@@ -19,6 +21,17 @@ export interface TokenCompatibility {
|
|
|
19
21
|
) => void;
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
/** First-party rules travel with the exact provider generation. The symbol stays
|
|
25
|
+
* private so generic provider options do not expose grant-bearing hooks. */
|
|
26
|
+
export const tokenCompatibility = Symbol("effect-auth/OpenIdClient/tokenCompatibility");
|
|
27
|
+
|
|
28
|
+
export const TokenCompatibility = Schema.declare<TokenCompatibility>(
|
|
29
|
+
(input): input is TokenCompatibility =>
|
|
30
|
+
Predicate.isObject(input) &&
|
|
31
|
+
"inspectReceipt" in input &&
|
|
32
|
+
Predicate.isFunction(input.inspectReceipt),
|
|
33
|
+
);
|
|
34
|
+
|
|
22
35
|
export class DefiniteTokenRejection extends Error {}
|
|
23
36
|
|
|
24
37
|
export interface ConnectedCompatibility extends TokenCompatibility {
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
OAuthRedirectUri,
|
|
12
12
|
} from "../signInModels";
|
|
13
13
|
import { freezeOAuth } from "../signInSnapshot";
|
|
14
|
+
import { TokenCompatibility, tokenCompatibility } from "./compatibility";
|
|
14
15
|
import {
|
|
15
16
|
OpenIdClientConfigurationError,
|
|
16
17
|
type OpenIdClientAuthentication,
|
|
@@ -70,6 +71,7 @@ const optionsSchema = <R>() =>
|
|
|
70
71
|
Schema.Struct({
|
|
71
72
|
...common,
|
|
72
73
|
protocol: Schema.Literal("oauth"),
|
|
74
|
+
[tokenCompatibility]: Schema.optionalKey(TokenCompatibility),
|
|
73
75
|
authorizationEndpoint: boundedString(2048),
|
|
74
76
|
tokenEndpoint: boundedString(2048),
|
|
75
77
|
pkceS256: Schema.Literal(true),
|
|
@@ -3,6 +3,7 @@ import type { CustomFetch } from "openid-client";
|
|
|
3
3
|
|
|
4
4
|
import type { OAuthProtocolRejected } from "../signInErrors";
|
|
5
5
|
import type { OAuthProtocolConfiguration, OAuthVerifiedExternalIdentity } from "../signInModels";
|
|
6
|
+
import type { TokenCompatibility, tokenCompatibility } from "./compatibility";
|
|
6
7
|
|
|
7
8
|
export class OpenIdClientConfigurationError extends Schema.TaggedError<OpenIdClientConfigurationError>()(
|
|
8
9
|
"OpenIdClientConfigurationError",
|
|
@@ -55,6 +56,8 @@ export interface OpenIdClientOidcProvider extends ProviderGeneration {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
export interface OpenIdClientOAuthProvider<R = never> extends ProviderGeneration {
|
|
59
|
+
/** @internal First-party provider behavior, retained by the configuration codec. */
|
|
60
|
+
readonly [tokenCompatibility]?: TokenCompatibility;
|
|
58
61
|
readonly protocol: "oauth";
|
|
59
62
|
readonly authorizationEndpoint: string;
|
|
60
63
|
readonly tokenEndpoint: string;
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
OAuthVerifiedExternalIdentity,
|
|
17
17
|
} from "../signInModels";
|
|
18
18
|
import { snapshotOAuth } from "../signInSnapshot";
|
|
19
|
-
import { DefiniteTokenRejection,
|
|
19
|
+
import { DefiniteTokenRejection, tokenCompatibility } from "./compatibility";
|
|
20
20
|
import {
|
|
21
21
|
clientAuthentication,
|
|
22
22
|
installConfigurations,
|
|
@@ -110,9 +110,9 @@ const privateConfiguration = <R>(
|
|
|
110
110
|
timeout: number,
|
|
111
111
|
fetch: client.CustomFetch,
|
|
112
112
|
signal: AbortSignal,
|
|
113
|
-
compatibility?: TokenCompatibility,
|
|
114
113
|
) => {
|
|
115
114
|
const provider = entry.provider;
|
|
115
|
+
const compatibility = provider.protocol === "oauth" ? provider[tokenCompatibility] : undefined;
|
|
116
116
|
|
|
117
117
|
const configuration = new client.Configuration(
|
|
118
118
|
entry.metadata,
|
|
@@ -158,10 +158,10 @@ const privateConfiguration = <R>(
|
|
|
158
158
|
return configuration;
|
|
159
159
|
};
|
|
160
160
|
|
|
161
|
-
export const
|
|
161
|
+
export const makeOpenIdClientOAuthProtocol = Effect.fn("makeOpenIdClientOAuthProtocol")(
|
|
162
|
+
// Capture one provider table; each generation retains its own receipt rules.
|
|
162
163
|
function* <R = never>(
|
|
163
164
|
options: OpenIdClientOAuthProtocolOptions<R>,
|
|
164
|
-
compatibility?: TokenCompatibility,
|
|
165
165
|
): Effect.fn.Return<
|
|
166
166
|
OAuthProtocol["Service"],
|
|
167
167
|
OpenIdClientConfigurationError | OAuthUnavailable,
|
|
@@ -192,13 +192,7 @@ export const makeOAuthProtocolWithCompatibility = Effect.fn("makeOpenIdClientOAu
|
|
|
192
192
|
|
|
193
193
|
const result = yield* Effect.tryPromise({
|
|
194
194
|
try: async (signal) => {
|
|
195
|
-
const configuration = privateConfiguration(
|
|
196
|
-
entry,
|
|
197
|
-
timeoutSeconds,
|
|
198
|
-
fetch,
|
|
199
|
-
signal,
|
|
200
|
-
compatibility,
|
|
201
|
-
);
|
|
195
|
+
const configuration = privateConfiguration(entry, timeoutSeconds, fetch, signal);
|
|
202
196
|
|
|
203
197
|
const state = client.randomState();
|
|
204
198
|
const verifier = client.randomPKCECodeVerifier();
|
|
@@ -281,13 +275,7 @@ export const makeOAuthProtocolWithCompatibility = Effect.fn("makeOpenIdClientOAu
|
|
|
281
275
|
|
|
282
276
|
const exchanged = yield* Effect.tryPromise({
|
|
283
277
|
try: async (signal) => {
|
|
284
|
-
const configuration = privateConfiguration(
|
|
285
|
-
entry,
|
|
286
|
-
timeoutSeconds,
|
|
287
|
-
fetch,
|
|
288
|
-
signal,
|
|
289
|
-
compatibility,
|
|
290
|
-
);
|
|
278
|
+
const configuration = privateConfiguration(entry, timeoutSeconds, fetch, signal);
|
|
291
279
|
|
|
292
280
|
const currentUrl = new URL(saved.redirectUri);
|
|
293
281
|
|
|
@@ -428,10 +416,6 @@ export const makeOAuthProtocolWithCompatibility = Effect.fn("makeOpenIdClientOAu
|
|
|
428
416
|
unavailableOnDefect,
|
|
429
417
|
);
|
|
430
418
|
|
|
431
|
-
export const makeOpenIdClientOAuthProtocol = <R = never>(
|
|
432
|
-
options: OpenIdClientOAuthProtocolOptions<R>,
|
|
433
|
-
) => makeOAuthProtocolWithCompatibility(options);
|
|
434
|
-
|
|
435
419
|
export const openIdClientOAuthProtocolLayer = <R = never>(
|
|
436
420
|
options: OpenIdClientOAuthProtocolOptions<R>,
|
|
437
421
|
) => Layer.effect(OAuthProtocol, makeOpenIdClientOAuthProtocol(options));
|