# AuthFlow

Types of authentication flow.

- Source: [`aws-cognito/lib/user-pool-client.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-cognito/lib/user-pool-client.ts#L22)
- Type last changed: v2.172.0 · 7 Dec 2024

## Example

TypeScript:

```ts
const userPool = new cognito.UserPool(this, 'myuserpool', {
  signInPolicy: {
    allowedFirstAuthFactors: {
      password: true, // password authentication must be enabled
      emailOtp: true, // enables email message one-time password
      smsOtp: true,   // enables SMS message one-time password
      passkey: true,  // enables passkey sign-in
    },
  },
});

// You should also configure the user pool client with USER_AUTH authentication flow allowed
userPool.addClient('myclient', {
  authFlows: { user: true },
});
```

Python:

```python
user_pool = cognito.UserPool(self, "myuserpool",
    sign_in_policy=cognito.SignInPolicy(
        allowed_first_auth_factors=cognito.AllowedFirstAuthFactors(
            password=True,  # password authentication must be enabled
            email_otp=True,  # enables email message one-time password
            sms_otp=True,  # enables SMS message one-time password
            passkey=True
        )
    )
)

# You should also configure the user pool client with USER_AUTH authentication flow allowed
user_pool.add_client("myclient",
    auth_flows=cognito.AuthFlow(user=True)
)
```

Java:

```java
UserPool userPool = UserPool.Builder.create(this, "myuserpool")
        .signInPolicy(SignInPolicy.builder()
                .allowedFirstAuthFactors(AllowedFirstAuthFactors.builder()
                        .password(true) // password authentication must be enabled
                        .emailOtp(true) // enables email message one-time password
                        .smsOtp(true) // enables SMS message one-time password
                        .passkey(true)
                        .build())
                .build())
        .build();

// You should also configure the user pool client with USER_AUTH authentication flow allowed
userPool.addClient("myclient", UserPoolClientOptions.builder()
        .authFlows(AuthFlow.builder().user(true).build())
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var userPool = new UserPool(this, "myuserpool", new UserPoolProps {
    SignInPolicy = new SignInPolicy {
        AllowedFirstAuthFactors = new AllowedFirstAuthFactors {
            Password = true,  // password authentication must be enabled
            EmailOtp = true,  // enables email message one-time password
            SmsOtp = true,  // enables SMS message one-time password
            Passkey = true
        }
    }
});

// You should also configure the user pool client with USER_AUTH authentication flow allowed
userPool.AddClient("myclient", new UserPoolClientOptions {
    AuthFlows = new AuthFlow { User = true }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
userPool := cognito.NewUserPool(this, jsii.String("myuserpool"), &UserPoolProps{
	SignInPolicy: &SignInPolicy{
		AllowedFirstAuthFactors: &AllowedFirstAuthFactors{
			Password: jsii.Boolean(true),
			 // password authentication must be enabled
			EmailOtp: jsii.Boolean(true),
			 // enables email message one-time password
			SmsOtp: jsii.Boolean(true),
			 // enables SMS message one-time password
			Passkey: jsii.Boolean(true),
		},
	},
})

// You should also configure the user pool client with USER_AUTH authentication flow allowed
userPool.addClient(jsii.String("myclient"), &UserPoolClientOptions{
	AuthFlows: &AuthFlow{
		User: jsii.Boolean(true),
	},
})
```

## Properties

- `adminUserPassword`: boolean = false — Enable admin based user password authentication flow.

- `custom`: boolean = false — Enable custom authentication flow.

- `user`: boolean = false — Enable Choice-based authentication.

- `userPassword`: boolean = false — Enable auth using username & password.

- `userSrp`: boolean = false — Enable SRP based authentication.
