@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 96 lines 5.39 KB
Raw
1 import * as cip from "@distilled.cloud/aws/cognito-identity-provider";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as AWSBindings from "../AWSBindings.ts";
5 import { cognitoMethods } from "./BindingHttp.ts";
6 import { UserPoolAuth, type UserPoolAuthClient } from "./UserPoolAuth.ts";
7 import type { UserPoolClient } from "./UserPoolClient.ts";
8
9 /** The injected identifier field, in the distilled wire type (Cognito marks
10 * `ClientId` sensitive, so the field accepts `string | Redacted<string>`). */
11 type ClientIdField = Pick<cip.SignUpRequest, "ClientId">;
12
13 /**
14 * HTTP implementation of {@link UserPoolAuth}. The token-based auth-flow
15 * operations are unauthenticated (Cognito does not evaluate IAM for them),
16 * so the deploy-time half only records the binding — no policy statements
17 * are attached.
18 */
19 export const UserPoolAuthHttp = Layer.effect(
20 UserPoolAuth,
21 Effect.gen(function* () {
22 const bind = yield* AWSBindings.Bind;
23 const signUp = yield* AWSBindings.withCredentials(cip.signUp);
24 const confirmSignUp = yield* AWSBindings.withCredentials(cip.confirmSignUp);
25 const resendConfirmationCode = yield* AWSBindings.withCredentials(cip.resendConfirmationCode);
26 const initiateAuth = yield* AWSBindings.withCredentials(cip.initiateAuth);
27 const respondToAuthChallenge = yield* AWSBindings.withCredentials(cip.respondToAuthChallenge);
28 const forgotPassword = yield* AWSBindings.withCredentials(cip.forgotPassword);
29 const confirmForgotPassword = yield* AWSBindings.withCredentials(cip.confirmForgotPassword);
30 const getUser = yield* AWSBindings.withCredentials(cip.getUser);
31 const globalSignOut = yield* AWSBindings.withCredentials(cip.globalSignOut);
32 const revokeToken = yield* AWSBindings.withCredentials(cip.revokeToken);
33 const getTokensFromRefreshToken = yield* AWSBindings.withCredentials(
34 cip.getTokensFromRefreshToken,
35 );
36 const changePassword = yield* AWSBindings.withCredentials(cip.changePassword);
37 const updateUserAttributes = yield* AWSBindings.withCredentials(cip.updateUserAttributes);
38 const deleteUserAttributes = yield* AWSBindings.withCredentials(cip.deleteUserAttributes);
39 const getUserAttributeVerificationCode = yield* AWSBindings.withCredentials(
40 cip.getUserAttributeVerificationCode,
41 );
42 const verifyUserAttribute = yield* AWSBindings.withCredentials(cip.verifyUserAttribute);
43 const setUserMFAPreference = yield* AWSBindings.withCredentials(cip.setUserMFAPreference);
44 const associateSoftwareToken = yield* AWSBindings.withCredentials(cip.associateSoftwareToken);
45 const verifySoftwareToken = yield* AWSBindings.withCredentials(cip.verifySoftwareToken);
46 const getUserAuthFactors = yield* AWSBindings.withCredentials(cip.getUserAuthFactors);
47 const deleteUser = yield* AWSBindings.withCredentials(cip.deleteUser);
48
49 return Effect.fn(function* <C extends UserPoolClient>(client: C) {
50 const ClientId = yield* client.clientId;
51 if (!globalThis.__ALCHEMY_RUNTIME__) {
52 // No IAM is required for the public auth flows; the binding is
53 // recorded so the app client deploys before the function.
54 yield* bind`AWS.Cognito.UserPoolAuth(${client})`({
55 policyStatements: [],
56 });
57 }
58 const methods = cognitoMethods("AWS.Cognito.UserPoolAuth", client.LogicalId);
59 const withClient = methods.injecting(
60 Effect.map(ClientId, (id): ClientIdField => ({ ClientId: id })),
61 );
62 const authClient: UserPoolAuthClient = {
63 // client-scoped flows — the app client ID is injected
64 signUp: withClient("signUp", signUp),
65 confirmSignUp: withClient("confirmSignUp", confirmSignUp),
66 resendConfirmationCode: withClient("resendConfirmationCode", resendConfirmationCode),
67 initiateAuth: withClient("initiateAuth", initiateAuth),
68 respondToAuthChallenge: withClient("respondToAuthChallenge", respondToAuthChallenge),
69 forgotPassword: withClient("forgotPassword", forgotPassword),
70 confirmForgotPassword: withClient("confirmForgotPassword", confirmForgotPassword),
71 revokeToken: withClient("revokeToken", revokeToken),
72 getTokensFromRefreshToken: withClient(
73 "getTokensFromRefreshToken",
74 getTokensFromRefreshToken,
75 ),
76 // token-scoped self-service — authorized by the access token itself
77 getUser: methods.plain("getUser", getUser),
78 globalSignOut: methods.plain("globalSignOut", globalSignOut),
79 changePassword: methods.plain("changePassword", changePassword),
80 updateUserAttributes: methods.plain("updateUserAttributes", updateUserAttributes),
81 deleteUserAttributes: methods.plain("deleteUserAttributes", deleteUserAttributes),
82 getUserAttributeVerificationCode: methods.plain(
83 "getUserAttributeVerificationCode",
84 getUserAttributeVerificationCode,
85 ),
86 verifyUserAttribute: methods.plain("verifyUserAttribute", verifyUserAttribute),
87 setUserMFAPreference: methods.plain("setUserMFAPreference", setUserMFAPreference),
88 associateSoftwareToken: methods.plain("associateSoftwareToken", associateSoftwareToken),
89 verifySoftwareToken: methods.plain("verifySoftwareToken", verifySoftwareToken),
90 getUserAuthFactors: methods.plain("getUserAuthFactors", getUserAuthFactors),
91 deleteUser: methods.plain("deleteUser", deleteUser),
92 };
93 return authClient;
94 });
95 }),
96 );