Skip to content

UserPoolClient

Source: src/AWS/Cognito/UserPoolClient.ts

An app client of an Amazon Cognito user pool. Applications authenticate against the pool through a client, which controls the allowed auth flows, token lifetimes, and OAuth settings.

Public Client with Password Auth

import * as Cognito from "alchemy/AWS/Cognito";
const pool = yield* Cognito.UserPool("Users", {});
const client = yield* Cognito.UserPoolClient("Web", {
userPoolId: pool.userPoolId,
explicitAuthFlows: ["ALLOW_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"],
});

Confidential Client with a Secret

const server = yield* Cognito.UserPoolClient("Server", {
userPoolId: pool.userPoolId,
generateSecret: true,
explicitAuthFlows: ["ALLOW_ADMIN_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"],
});
const client = yield* Cognito.UserPoolClient("Web", {
userPoolId: pool.userPoolId,
accessTokenValidity: 30,
idTokenValidity: 30,
refreshTokenValidity: 7,
tokenValidityUnits: {
accessToken: "minutes",
idToken: "minutes",
refreshToken: "days",
},
});
const client = yield* Cognito.UserPoolClient("Web", {
userPoolId: pool.userPoolId,
allowedOAuthFlowsUserPoolClient: true,
allowedOAuthFlows: ["code"],
allowedOAuthScopes: ["openid", "email"],
callbackUrls: ["https://example.com/callback"],
supportedIdentityProviders: ["COGNITO"],
});