@aws-amplify/auth-construct-alpha

中文文档
0.6.1发布于 2024/04/23Apache-2.0TypeScriptESM + CJS近 30 天下载 7.9万

This package vends an L3 CDK Construct that enables faster, easier and secure app authentication and authorization powered by Amazon Cognito. Amplify Auth lets you quickly set up secure authentication flows with a fully-managed user directory. Control wha

原始使用文档
文档目录5 节
  1. Examples
  2. Simple email login with default settings
  3. Email login with customized multifactor settings
  4. Customized email and phone login with external login provid…
  5. Custom user attributes

AmplifyAuth Construct

This package vends an L3 CDK Construct that enables faster, easier and secure app authentication and authorization powered by Amazon Cognito. Amplify Auth lets you quickly set up secure authentication flows with a fully-managed user directory. Control what users have access to in your mobile and web apps with Amplify Auth's built-in authorization capabilities.

The primary way to use this construct is to invoke it with a configuration object. You can declare the individual settings for your authentication by passing them as properties to the AmplifyAuth construct.

Note: only a single instance of the AmplifyAuth construct can be invoked within a CDK synthesis at this point in time.

Examples

Simple email login with default settings

In this example, you will create a simple stack with email login enabled (by default). Deploying this will create a UserPool, UserPoolClient, IdentityPool, and Authenticated/Unauthenticated IAM Roles.

import { App, Stack } from 'aws-cdk-lib';
import { AmplifyAuth } from '@aws-amplify/auth-construct-alpha';

const app = new App();
const stack = new Stack(app, 'AuthStack');

new AmplifyAuth(stack, 'Auth');

Email login with customized multifactor settings

In this example, you will create a simple stack with email login enabled and with customized multi factor authentication (MFA) settings.

import { App, Stack } from 'aws-cdk-lib';
import { AmplifyAuth } from '@aws-amplify/auth-construct-alpha';

const app = new App();
const stack = new Stack(app, 'AuthStack');

new AmplifyAuth(stack, 'Auth', {
  loginWith: {
    email: true,
  },
  multifactor: {
    mode: 'OPTIONAL',
    sms: {
      smsMessage: (code: string) => `Your verification code is ${code}`,
    },
    totp: false,
  },
});

Customized email and phone login with external login providers

In this example, you will create a stack with email, phone, and external login providers. Additionally, you can customize the email and phone verification messages.

import { App, Stack, SecretValue } from 'aws-cdk-lib';
import { AmplifyAuth } from '@aws-amplify/auth-construct-alpha';

const app = new App();
const stack = new Stack(app, 'AuthStack');

new AmplifyAuth(stack, 'Auth', {
  loginWith: {
    email: {
      verificationEmailStyle: 'CODE',
      verificationEmailBody: (code: string) =>
        `Your verification code is ${code}.`,
      verificationEmailSubject: 'My custom email subject',
    },
    phone: {
      verificationMessage: (code: string) =>
        `Your verification code is ${code}.`,
    },
    externalProviders: {
      google: {
        clientId: 'googleClientId',
        // see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.SecretValue.html
        clientSecret: SecretValue.unsafePlainText('googleClientSecret'),
      },
      facebook: {
        clientId: 'facebookClientId',
        clientSecret: 'facebookClientSecret',
      },
      signInWithApple: {
        clientId: 'appleClientId',
        keyId: 'appleKeyId',
        privateKey: 'applePrivateKey',
        teamId: 'appleTeamId',
      },
      loginWithAmazon: {
        clientId: 'amazonClientId',
        clientSecret: 'amazonClientSecret',
      },
      oidc: {
        clientId: 'oidcClientId',
        clientSecret: 'oidcClientSecret',
        issuerUrl: 'oidcIssuerUrl',
        name: 'oidcProviderName',
      },
      saml: {
        name: 'samlProviderName',
        metadata: {
          metadataContent: 'samlMetadataContent',
          metadataType: 'FILE',
        },
      },
    },
  },
});

Custom user attributes

In this example, you will customize the set of attributes that are required for every user in the UserPool.

import { App, Stack } from 'aws-cdk-lib';
import { AmplifyAuth } from '@aws-amplify/auth-construct-alpha';

const app = new App();
const stack = new Stack(app, 'AuthStack');

new AmplifyAuth(stack, 'Auth', {
  loginWith: { email: true },
  userAttributes: {
    address: {
      mutable: false,
    },
    familyName: {
      required: true,
    },
  },
});

版本与发布记录

@aws-amplify/auth-construct-alpha 共发布 57 个版本,首次发布于 2023/08/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.6.1latest2024/04/232 年前
0.6.02024/04/202 年前
0.6.0-beta.13beta2024/04/192 年前
0.6.0-beta.122024/04/172 年前
0.6.0-beta.112024/04/162 年前
0.6.0-beta.102024/04/122 年前

其他发布通道:alpha → 0.1.1-alpha.0,test → 0.0.0-test-20240327212405,beta → 0.6.0-beta.13。

关于 @aws-amplify/auth-construct-alpha 的常见问题

@aws-amplify/auth-construct-alpha 是什么?

This package vends an L3 CDK Construct that enables faster, easier and secure app authentication and authorization powered by Amazon Cognito. Amplify Auth lets you quickly set up secure authentication flows with a fully-managed user directory. Control wha

如何安装 @aws-amplify/auth-construct-alpha?

在项目目录运行 npm install @aws-amplify/auth-construct-alpha,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:constructs(^10.0.0)、aws-cdk-lib(^2.127.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aws-amplify/auth-construct-alpha 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aws-amplify/auth-construct-alpha 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aws-amplify/auth-construct-alpha 可以商用吗?

@aws-amplify/auth-construct-alpha 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aws-amplify/auth-construct-alpha 的下载量有多少?

根据 npm 官方下载统计,@aws-amplify/auth-construct-alpha 在 2026/10/07 – 2026/11/05 这 30 天内被下载 78,506 次,日均约 2,617 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aws-amplify/auth-construct-alpha 还在维护吗?

最新版本 0.6.1 发布于 2024/04/23(2 年前);至今共发布 57 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/08/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。