@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 71 lines 2.9 KB
Raw
1 import type * as ci from "@distilled.cloud/aws/cognito-identity";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { IdentityPool } from "./IdentityPool.ts";
5
6 export interface GetIdRequest extends Omit<ci.GetIdInput, "IdentityPoolId"> {}
7
8 /**
9 * The typed client returned by binding {@link IdentityPoolAuth} to an
10 * `IdentityPool`. `getId` automatically injects the identity pool ID; the
11 * remaining calls operate on the returned identity ID.
12 */
13 export interface IdentityPoolAuthClient {
14 /** Mint (or look up) an identity ID for a set of logins — or for a guest
15 * when the pool allows unauthenticated identities. */
16 getId: (request?: GetIdRequest) => Effect.Effect<ci.GetIdResponse, ci.GetIdError>;
17 /** Exchange an identity ID (+ logins) for temporary AWS credentials. */
18 getCredentialsForIdentity: (
19 request: ci.GetCredentialsForIdentityInput,
20 ) => Effect.Effect<ci.GetCredentialsForIdentityResponse, ci.GetCredentialsForIdentityError>;
21 /** Exchange an identity ID (+ logins) for an OpenID Connect token
22 * (basic/classic flow — requires `allowClassicFlow`). */
23 getOpenIdToken: (
24 request: ci.GetOpenIdTokenInput,
25 ) => Effect.Effect<ci.GetOpenIdTokenResponse, ci.GetOpenIdTokenError>;
26 /** Unlink a federated login from an identity. */
27 unlinkIdentity: (
28 request: ci.UnlinkIdentityInput,
29 ) => Effect.Effect<ci.UnlinkIdentityResponse, ci.UnlinkIdentityError>;
30 }
31
32 /**
33 * Runtime binding for the public (token-based) Cognito identity pool flows —
34 * the credentials-vending data plane.
35 *
36 * Bind this to an `IdentityPool` inside a function runtime to exchange user
37 * pool / social / OIDC tokens (or nothing, for guest access) for an identity
38 * ID and temporary AWS credentials. These operations are unauthenticated
39 * (Cognito does not evaluate IAM for them), so the binding grants no IAM
40 * policy — it injects the identity pool ID into `getId`.
41 * ### Vending AWS Credentials
42 * **Example:** Guest (Unauthenticated) Credentials
43 * ```typescript
44 * const identity = yield* Cognito.IdentityPoolAuth(identityPool);
45 *
46 * const { IdentityId } = yield* identity.getId();
47 * const creds = yield* identity.getCredentialsForIdentity({
48 * IdentityId: IdentityId!,
49 * });
50 * ```
51 *
52 * **Example:** Credentials for a User Pool Sign-In
53 * ```typescript
54 * const provider = `cognito-idp.${region}.amazonaws.com/${userPoolId}`;
55 * const { IdentityId } = yield* identity.getId({
56 * Logins: { [provider]: idToken },
57 * });
58 * const creds = yield* identity.getCredentialsForIdentity({
59 * IdentityId: IdentityId!,
60 * Logins: { [provider]: idToken },
61 * });
62 * ```
63 *
64 * @binding
65 */
66 export interface IdentityPoolAuth extends Binding.Service<
67 IdentityPoolAuth,
68 "AWS.Cognito.IdentityPoolAuth",
69 <P extends IdentityPool>(pool: P) => Effect.Effect<IdentityPoolAuthClient>
70 > {}
71 export const IdentityPoolAuth = Binding.Service<IdentityPoolAuth>("AWS.Cognito.IdentityPoolAuth");