

# Auth configuration

The settings for Amplify backend auth are the `auth` object in the `backend` block of `amplify.jsonc`. `aws amplifygen3 local run` applies them to the local backend. Each deployment sends them to the environment’s backend. This page lists every setting, in groups: app name, trusted origins, email and password, email verification, social providers, plugins, user, session, account, rate limit, advanced (cookies), and platform (your SMTP server and the managed sign-in page). Every sign-in method other than email and password is off until you turn it on. After the settings, the page covers per-environment settings, secrets and how to check the settings that an environment runs with.

## The auth block
<a name="backend-auth-config-block"></a>

 `aws amplifygen3 local run` and a new environment use the default settings when `amplify.jsonc` has no `auth` block, or has `"auth": {}`: email and password sign-in on, and `App` as the app name. A deployment with no `auth` block uses the settings stored with `aws amplifygen3 env edit`, if any. Otherwise the environment keeps the settings that it runs with.

An `auth` block that you write replaces the defaults whole. Keep `"emailAndPassword": { "enabled": true }` in every block, and set `appName`. A setting that you leave out still gets its own default, such as `8` for `minPasswordLength`.

```jsonc
{
  "backend": {
    "auth": {
      "appName": "Acme Notes",
      "emailAndPassword": { "enabled": true, "minPasswordLength": 12 },
      "session": { "expiresIn": 86400 } // seconds
    }
  }
}
```

Run `aws amplifygen3 local run` again after you edit the block, and then deploy. Running `local run` again keeps your local data. Both commands check the root `backend.auth` block first, and stop with an error on any key that isn’t listed on this page, such as a misspelled key. `aws amplifygen3 deploy` doesn’t check an `env.<name>.backend.auth` block, and a problem in that block fails the deployment with `CONFIG_RETRIEVAL_FAILED`. For how the local backend applies these settings, see [Local auth and emails](backend-local-auth.md).

**Note**  
You can write `//` and `/* */` comments in `amplify.jsonc`. `aws amplifygen3 local run` refuses a file with a trailing comma anywhere in it.

## App name
<a name="backend-auth-config-app-name"></a>

 `appName` is the name your users see: on the managed sign-in page, in auth emails and as a passkey’s site name.


| Setting | Values | Default | 
| --- | --- | --- | 
|  `appName`  | 3 to 64 printable ASCII characters, with no `:` and no leading or trailing space |  `App`  | 

 `aws amplifygen3 local run`, `aws amplifygen3 deploy` and `aws amplifygen3 env edit` warn when `backend.auth` has settings but no `appName`.

## Trusted origins
<a name="backend-auth-config-origins"></a>

A deployed backend accepts calls from its own origin and from these origins: the Amplify console, the environment’s URL, its custom domains and the URLs of its recent successful deployments, up to 100 hosts in all. `trustedOrigins` adds other origins, such as a dev server that you start yourself, a site hosted elsewhere or a mobile app’s scheme.

```jsonc
"trustedOrigins": ["http://localhost:5173", "https://admin.example.com", "myapp://callback"]
```

Each browser call to `/auth` must come from a trusted origin. Each `callbackURL`, `redirectTo` and `redirectUri` that you pass must be on a trusted origin too.
+ Each entry needs a scheme. The list holds up to 100 entries of up to 512 characters.
+  `"*"` is refused.
+ A mobile deep link entry, such as `myapp://callback`, also matches the paths below it. A bare `myapp://` is refused.
+  `https://*.example.com` trusts every subdomain of a domain that you own.
+ In token mode, the default for a deployed app, the backend sends the user back after a redirect sign-in, such as on the managed sign-in page, only to an origin that matches an entry exactly.
+ A deployment fails with `CONFIG_RETRIEVAL_FAILED` when `trustedOrigins` or `passkey.origins` has a wildcard over hosts that others own, such as `https://*.vercel.app`, `https://*.amplify.app`, `https://*.com`, a public suffix such as `https://*.co.uk`, an IP address or the backend’s own domain. List each of those origins exactly. For one Amplify app, `https://*--<app-id>.amplify.app` is allowed.
+ A deployed backend doesn’t accept calls from another environment’s site. The local backend accepts calls from the dev server that `aws amplifygen3 local run` starts.

## Email and password
<a name="backend-auth-config-email-password"></a>

 `emailAndPassword` turns email and password sign-in on and sets its rules. For the sign-up, sign-in and reset calls, see [Email and password](backend-auth-password.md).


| Setting | Values | Default | 
| --- | --- | --- | 
|  `enabled`  | Boolean |  `true` without an `auth` block or with `"auth": {}`, `false` in a block that sets other keys | 
|  `requireEmailVerification`: users verify their address before they can sign in | Boolean |  `false`  | 
|  `minPasswordLength`  | 6 to 20, and no more than `maxPasswordLength`  |  `8`  | 
|  `maxPasswordLength`  | 8 to 128 |  `128`  | 
|  `resetPasswordTokenExpiresIn`: how long a reset link works, in seconds | 300 to 86400 |  `3600`  | 
|  `autoSignIn`: signs a user in at sign-up. Has no effect when `requireEmailVerification` is `true`  | Boolean |  `true`  | 
|  `disableSignUp`: stops new sign-ups; existing users still sign in | Boolean |  `false`  | 

## Email verification
<a name="backend-auth-config-email-verification"></a>

 `emailVerification` sets when the backend sends a verification link.


| Setting | Values | Default | 
| --- | --- | --- | 
|  `sendOnSignUp`  | Boolean | The value of `requireEmailVerification`  | 
|  `sendOnSignIn`: sends the link again when an unverified user’s sign-in is refused | Boolean. `true` needs `enabled` and `requireEmailVerification`  |  `true` when verification is required | 
|  `expiresIn`: how long a link works, in seconds | 300 to 86400 |  `3600`  | 

When `emailAndPassword.enabled` and `requireEmailVerification` are both `true`, at least one of `sendOnSignUp` and `sendOnSignIn` must be `true`.

## Social providers
<a name="backend-auth-config-social"></a>

Each provider block in `socialProviders` adds that sign-in option. The providers are `apple`, `cognito`, `discord`, `facebook`, `github`, `google`, `linkedin`, `microsoft`, `slack`, `spotify` and `twitter` (X). For setup, see [Social sign-in and OAuth](backend-auth-social.md).

```jsonc
"socialProviders": {
  "google": {
    "clientId": "123-abc.apps.googleusercontent.com",   // required, 1 to 256 characters
    "clientSecret": "${env:GOOGLE_CLIENT_SECRET}"       // required, an ${env:NAME} reference
  }
}
```


| Setting | Values | Default | 
| --- | --- | --- | 
|  `apple.appBundleIdentifier`: your iOS or macOS app’s bundle ID, for native sign-in | 1 to 256 characters | None | 
|  `microsoft.tenantId`: a tenant ID, `common`, `organizations` or `consumers`  | 1 to 128 characters |  `common`  | 
|  `cognito.domain`, `region`, `userPoolId`: your Amazon Cognito user pool | Required | None | 

## Plugins
<a name="backend-auth-config-plugins"></a>

Each plugin in `plugins` adds a sign-in method. `twoFactor` adds a second step to sign-in.

```jsonc
"plugins": {
  "magicLink": { "enabled": true },
  "emailOtp": { "enabled": true, "otpLength": 6 },
  "passkey": { "enabled": true },
  "twoFactor": { "enabled": true, "otp": { "enabled": true } }
}
```


| Setting | Values | Default | 
| --- | --- | --- | 
|  `magicLink.enabled`: sign-in with an emailed link | Boolean |  `false`  | 
|  `magicLink.expiresIn`, in seconds | 300 to 86400 |  `300`  | 
|  `magicLink.disableSignUp`: specifies whether an email link can create an account. When `true`, the backend sends no link to an address with no account. Its answer is the same either way, so it doesn’t reveal which addresses have an account. The backend also refuses a link opened for an address with no account | Boolean |  `false`  | 
|  `emailOtp.enabled`: sign-in with an emailed code | Boolean |  `false`  | 
|  `emailOtp.expiresIn`, in seconds | 60 to 3600 |  `300`  | 
|  `emailOtp.otpLength`  | 4 to 10 digits |  `6`  | 
|  `emailOtp.disableSignUp`: specifies whether an email code can create an account. When `true`, the backend sends no code to an address with no account, and refuses its sign-in | Boolean |  `false`  | 
|  `passkey.enabled`  | Boolean |  `false`  | 
|  `passkey.origins`: exact origins where users create and use passkeys | Up to 5 | Your `trustedOrigins` entries without a `*`, or the backend’s origin | 
|  `passkey.rpId`: the passkeys' domain, a host with no scheme or port. Required when the origins span more than one host | 1 to 253 characters | The host of the one origin | 
|  `twoFactor.enabled`: two-step verification with authenticator app codes and backup codes | Boolean |  `false`  | 
|  `twoFactor.otp.enabled`: a code sent by email as the second step. Takes effect only when `twoFactor.enabled` is `true`  | Boolean |  `false`  | 
|  `genericOAuth.providers`: your own OAuth 2.0 or OpenID Connect providers | 1 to 10. Required in a `genericOAuth` block | None | 

Each `genericOAuth` provider takes a `providerId` (required: letters, digits, `-` and `_`), a `name`, a `clientId` and `clientSecret` as for a social provider, and `scopes`. It also takes either a `discoveryUrl`, or an `authorizationUrl` and a `tokenUrl`. A provider that isn’t OpenID Connect also needs a `userInfoUrl`. Each URL must start with `https://`. A deployment fails with `CONFIG_RETRIEVAL_FAILED` when two providers have the same `providerId`. It also fails when a provider has neither a `discoveryUrl` nor both an `authorizationUrl` and a `tokenUrl`.

## User
<a name="backend-auth-config-user"></a>

 `user` turns on account changes that a signed-in user makes themselves.


| Setting | Values | Default | 
| --- | --- | --- | 
|  `changeEmail.enabled`  | Boolean |  `false`  | 
|  `deleteUser.enabled`  | Boolean |  `false`  | 
|  `deleteUser.deleteTokenExpiresIn`: how long a deletion link works, in seconds | 300 to 86400 |  `86400`  | 

With `changeEmail.enabled`, the confirmation link sent to the new address signs the user in when it’s opened in a browser with no session, such as on another device. The sign-up verification link doesn’t sign anyone in.

## Session
<a name="backend-auth-config-session"></a>

 `session` sets how long users stay signed in. Times are in seconds. For how sessions work, see [User sessions](backend-auth-sessions.md).


| Setting | Values | Default | 
| --- | --- | --- | 
|  `expiresIn`  | 300 to 31536000 |  `604800` (7 days) | 
|  `updateAge`: how often the backend extends a session that’s in use. `0` extends it on every request | 0 to 31536000 |  `86400` (1 day) | 
|  `freshAge`: how recent a sign-in must be for sensitive actions. `0` turns the check off | 0 to 31536000 |  `86400` (1 day) | 

## Account
<a name="backend-auth-config-account"></a>

 `account.accountLinking` links a sign-in through a new provider to an existing account with the same verified email address.


| Setting | Values | Default | 
| --- | --- | --- | 
|  `accountLinking.enabled`  | Boolean |  `false`  | 
|  `accountLinking.trustedProviders`: a social provider such as `google`, `email-password`, or a `providerId`  | Up to 20 | None | 

## Rate limit
<a name="backend-auth-config-rate-limit"></a>

 `rateLimit` limits `/auth` requests from each client IP address, and auth email requests for each email address. It’s on by default in a deployed backend and off in the local backend. To turn it off for a test or CI backend, set `enabled` to `false` and deploy. The one-minute gap between emails to one address and the lockout after repeated wrong two-factor codes stay on. Keep it on for an app that real users sign in to.

```jsonc
"rateLimit": { "enabled": false }
```

 `rateLimit` counts requests from each client address in 60-second windows. Each window allows 100 requests that send email with the shared sender, or 300 with your own SMTP server. It also allows 600 credential checks and 6,000 other requests. The client address is the one that connected to CloudFront, so all of your server’s own requests share one count.

For auth emails, your app can also make at most 5 requests to one address a minute. Password reset, `resendVerificationEmail`, email change, sign-in link, and sign-in code requests count together. The verification email that sign-up or sign-in sends, and the account deletion email, don’t count. Addresses that differ only by a `+tag` count as one, and a request counts even when no email goes out. For more information about other limits, see [Quotas](quotas-chapter.md).

## Advanced
<a name="backend-auth-config-advanced"></a>

 `advanced` sets the auth cookies.


| Setting | Values | Default | 
| --- | --- | --- | 
|  `crossSubDomainCookies.enabled`: shares the cookies across subdomains of one parent domain | Boolean |  `false`  | 
|  `crossSubDomainCookies.domain`: the parent domain that shares the cookies, such as `.example.com`. Use the backend’s own host, another host that your backend answers on, or a parent of that host. A custom domain is one such host. A deployment fails with `CONFIG_RETRIEVAL_FAILED` for any other domain. It also fails for a parent of the backend’s own host, a public suffix, or a zone that other customers' apps share, such as `amplify.app`. For an Amplify-hosted app, use its own `<branch>--<app-id>.amplify.app` host or a domain that you own. Takes effect only when `enabled` is `true`  | 1 to 253 characters | The host that the request was sent to, such as the backend URL’s host | 
|  `defaultCookieAttributes.sameSite`. Set `None` for a browser app on another site that uses the cookie session on a deployed backend |  `Lax`, `Strict` or `None`  |  `Lax`  | 
|  `defaultCookieAttributes.partitioned`. Some browsers need it with `None`  | Boolean |  `false`  | 

## Platform
<a name="backend-auth-config-platform"></a>

 `platform` holds two Amplify settings: your own SMTP server and the managed sign-in page. For SMTP and email templates, see [Auth emails](backend-auth-email.md). For the page, see [Managed sign-in page](backend-auth-managed-sign-in.md).

```jsonc
"platform": {
  "customEmail": {
    "smtp": {
      "host": "email-smtp.us-east-1.amazonaws.com",  // required
      "port": 587,                                   // required
      "username": "${env:SMTP_USERNAME}",            // required
      "password": "${env:SMTP_PASSWORD}",            // required
      "from": "Acme <no-reply@example.com>",         // required, 3 to 320 characters
      "replyTo": "support@example.com"               // optional
    }
  },
  "hostedUi": { "enabled": true }                    // serves the managed sign-in page; default false
}
```

When you set `smtp`, the backend sends every auth email through your server.

## Per-environment settings
<a name="backend-auth-config-per-env"></a>

An `env.<name>.backend.auth` block replaces the root block for that environment. Like the root block, it replaces the defaults whole, so give it its own `emailAndPassword` and `appName`. The local backend reads only the root block. This example keeps the dev server out of `production`:

```jsonc
{
  "backend": {
    "auth": {
      "appName": "Acme Notes",
      "emailAndPassword": { "enabled": true },
      "trustedOrigins": ["http://localhost:5173", "https://admin.example.com"]
    }
  },
  "env": {
    "production": {
      "backend": {
        "auth": {
          "appName": "Acme Notes",
          "emailAndPassword": { "enabled": true },
          "trustedOrigins": ["https://admin.example.com"]
        }
      }
    }
  }
}
```

You can also store an environment’s auth settings with `aws amplifygen3 env edit --env preview --auth-config auth.json`. A deployment uses those settings only when `amplify.jsonc` has no `auth` block for that environment, in `env.<name>.backend.auth` or at the root. An empty `"auth": {}` counts as a block. The path must be a regular file. To go back to the defaults, deploy `"auth": {}`, or store an empty file and deploy.

## Secrets
<a name="backend-auth-config-secrets"></a>

Client secrets, the SMTP user name and the SMTP password must each be a `${env:NAME}` reference.

For the local backend, put `NAME=value` lines in `.secrets/client_secrets.env`. Git ignores that file. For a deployed environment, store each value as a secret `BACKEND` variable, with `--secret`, before you deploy. A deployment fails with `CONFIG_RETRIEVAL_FAILED` when a referenced name has no value or isn’t a secret.

```bash
printf %s "$GOOGLE_CLIENT_SECRET" | aws amplifygen3 var set GOOGLE_CLIENT_SECRET --secret --scope BACKEND --env production
aws amplifygen3 var upload .secrets/client_secrets.env --scope BACKEND --secrets GOOGLE_CLIENT_SECRET,GITHUB_CLIENT_SECRET --env preview
```

 `aws amplifygen3 var download` writes each secret with an empty value, so copy a secret into your local file by hand.

## Check what an environment runs with
<a name="backend-auth-config-check"></a>

Run the following command:

```bash
aws amplifygen3 env get --env production
```

The `Applied backend config (branch '<name>')` block shows the auth settings that the live deployment sent, including your `trustedOrigins` list. The list leaves out the origins that Amplify trusts without an entry. The block shows `(not reported)` when the deployment sent no auth settings. With `--output json`, they’re in `AppliedBackendConfig.Auth` as a JSON string, so parse it before you read a setting. The `Stored backend config` block shows what `aws amplifygen3 env edit` stored.

## Errors
<a name="backend-auth-config-errors"></a>


| Error | When | Fix | 
| --- | --- | --- | 
|  `invalid_config`  |  `aws amplifygen3 local run` can’t parse `amplify.jsonc`, such as for a trailing comma | Fix the JSON | 
|  `invalid_auth_config`  |  `aws amplifygen3 local run` finds a key or value that breaks a rule. The error names the key | Fix the key, then run `aws amplifygen3 local run`  | 
|  `backend.auth in amplify.jsonc is not valid, so nothing was deployed:`  |  `aws amplifygen3 deploy` finds problems in the block, one line each | Fix each line, then deploy | 
|  `config_not_applied`  | The running local backend refused the edited block, and kept the previous settings | Fix the block, then run `aws amplifygen3 local run`  | 
|  `missing_client_secret`  | A `${env:NAME}` reference has no value in `.secrets/client_secrets.env`  | Add the line | 
|  `CONFIG_RETRIEVAL_FAILED`  | A deployment fails for one of these reasons. An `env.<name>.backend.auth` block breaks a rule. A wildcard covers hosts that others own. A generic OAuth provider repeats a `providerId` or has no endpoints. The `crossSubDomainCookies.domain` value is refused. A `${env:NAME}` reference names a `BACKEND` variable that’s missing, empty or not a secret | Fix the block, list each origin exactly, or store the value with `--secret`  | 
|  `EMAIL_PASSWORD_SIGN_UP_DISABLED`  | Sign-up with a block that leaves out `emailAndPassword`, or with `disableSignUp` on | Add `"emailAndPassword": { "enabled": true }`, or turn off `disableSignUp`  | 
|  `EMAIL_PASSWORD_DISABLED`  | Sign-in with a block that leaves out `emailAndPassword`  | Add `"emailAndPassword": { "enabled": true }`  | 
|  `INVALID_ORIGIN`, `INVALID_CALLBACK_URL`  | A browser call, or a `callbackURL`, from an origin that isn’t trusted | Add the origin to `trustedOrigins`  | 
|  `SESSION_NOT_FRESH`  | A sensitive action with a session older than `freshAge`  | Ask the user to sign in again | 
|  `account_not_linked`  | A provider sign-in for an email address that has an account, with linking off | Turn on `accountLinking`, or ask the user to sign in the way they signed up | 
|  `over_request_rate_limit` (`429`) | A rate limit was reached | Wait the seconds in `error.retryAfter`, or in the `X-Retry-After` header without the client SDK | 