# HttpUserPoolAuthorizer

Authorize Http Api routes on whether the requester is registered as part of an AWS Cognito user pool.

Implements: [IHttpRouteAuthorizer](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.IHttpRouteAuthorizer.html)

- Source: [`aws-apigatewayv2-authorizers/lib/http/user-pool.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-apigatewayv2-authorizers/lib/http/user-pool.ts#L42)
- Type last changed: v2.162.0 · 10 Oct 2024

## Example

TypeScript:

```ts
import * as cognito from 'aws-cdk-lib/aws-cognito';
import { HttpUserPoolAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
import { HttpUrlIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';

const userPool = new cognito.UserPool(this, 'UserPool');

const authorizer = new HttpUserPoolAuthorizer('BooksAuthorizer', userPool);

const api = new apigwv2.HttpApi(this, 'HttpApi');

api.addRoutes({
  integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.example.com'),
  path: '/books',
  authorizer,
});
```

Python:

```python
import aws_cdk.aws_cognito as cognito
from aws_cdk.aws_apigatewayv2_authorizers import HttpUserPoolAuthorizer
from aws_cdk.aws_apigatewayv2_integrations import HttpUrlIntegration

user_pool = cognito.UserPool(self, "UserPool")

authorizer = HttpUserPoolAuthorizer("BooksAuthorizer", user_pool)

api = apigwv2.HttpApi(self, "HttpApi")

api.add_routes(
    integration=HttpUrlIntegration("BooksIntegration", "https://get-books-proxy.example.com"),
    path="/books",
    authorizer=authorizer
)
```

Java:

```java
import software.amazon.awscdk.services.cognito.*;
import software.amazon.awscdk.aws_apigatewayv2_authorizers.HttpUserPoolAuthorizer;
import software.amazon.awscdk.aws_apigatewayv2_integrations.HttpUrlIntegration;

UserPool userPool = new UserPool(this, "UserPool");

HttpUserPoolAuthorizer authorizer = new HttpUserPoolAuthorizer("BooksAuthorizer", userPool);

HttpApi api = new HttpApi(this, "HttpApi");

api.addRoutes(AddRoutesOptions.builder()
        .integration(new HttpUrlIntegration("BooksIntegration", "https://get-books-proxy.example.com"))
        .path("/books")
        .authorizer(authorizer)
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Cognito;
using Amazon.CDK.AwsApigatewayv2Authorizers;
using Amazon.CDK.AwsApigatewayv2Integrations;

var userPool = new UserPool(this, "UserPool");

var authorizer = new HttpUserPoolAuthorizer("BooksAuthorizer", userPool);

var api = new HttpApi(this, "HttpApi");

api.AddRoutes(new AddRoutesOptions {
    Integration = new HttpUrlIntegration("BooksIntegration", "https://get-books-proxy.example.com"),
    Path = "/books",
    Authorizer = authorizer
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import cognito "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

userPool := cognito.NewUserPool(this, jsii.String("UserPool"))

authorizer := awscdk.NewHttpUserPoolAuthorizer(jsii.String("BooksAuthorizer"), userPool)

api := apigwv2.NewHttpApi(this, jsii.String("HttpApi"))

api.AddRoutes(&AddRoutesOptions{
	Integration: awscdk.NewHttpUrlIntegration(jsii.String("BooksIntegration"), jsii.String("https://get-books-proxy.example.com")),
	Path: jsii.String("/books"),
	Authorizer: Authorizer,
})
```

## Initializer

TypeScript:

```ts
new HttpUserPoolAuthorizer(id: string, pool: IUserPool, props?: HttpUserPoolAuthorizerProps)
```

Python:

```python
HttpUserPoolAuthorizer(id: str, pool: IUserPool, props: typing.Optional[HttpUserPoolAuthorizerProps] = None)
```

Java:

```java
new HttpUserPoolAuthorizer(String id, IUserPool pool, HttpUserPoolAuthorizerProps props)
```

C# / .NET:

```csharp
new HttpUserPoolAuthorizer(string id, IUserPool pool, HttpUserPoolAuthorizerProps? props = null)
```

Golang:

```go
NewHttpUserPoolAuthorizer(Id *string, Pool IUserPool, Props HttpUserPoolAuthorizerProps)
```

## Properties

- `authorizationType`: string — The authorizationType used for UserPool Authorizer.

- `authorizerId`: string — Return the id of the authorizer if it's been constructed.

## Methods

- `bind(options: HttpRouteAuthorizerBindOptions): HttpRouteAuthorizerConfig` — Bind this authorizer to a specified Http route.
