HttpUserPoolAuthorizer Class
Authorize Http Api routes on whether the requester is registered as part of an AWS Cognito user pool.
- Source
aws-apigatewayv2-authorizers/lib/http/user-pool.ts- Type last changed
- v2.162.0 · 10 Oct 2024
Example
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
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
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());
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
});
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
ts
new HttpUserPoolAuthorizer(id: string, pool: IUserPool, props?: HttpUserPoolAuthorizerProps)
python
HttpUserPoolAuthorizer(id: str, pool: IUserPool, props: typing.Optional[HttpUserPoolAuthorizerProps] = None)
java
new HttpUserPoolAuthorizer(String id, IUserPool pool, HttpUserPoolAuthorizerProps props)
csharp
new HttpUserPoolAuthorizer(string id, IUserPool pool, HttpUserPoolAuthorizerProps? props = null)
go
NewHttpUserPoolAuthorizer(Id *string, Pool IUserPool, Props HttpUserPoolAuthorizerProps)
Properties
authorizationTypestringauthorization_typestrauthorizationTypeStringAuthorizationTypestringAuthorizationType*stringrequired#The authorizationType used for UserPool Authorizer.
Return the id of the authorizer if it's been constructed.
Methods
bind(options: HttpRouteAuthorizerBindOptions): HttpRouteAuthorizerConfigdef bind(self, options: HttpRouteAuthorizerBindOptions) -> HttpRouteAuthorizerConfigpublic HttpRouteAuthorizerConfig bind(HttpRouteAuthorizerBindOptions options)public HttpRouteAuthorizerConfig Bind(HttpRouteAuthorizerBindOptions options)func Bind(Options HttpRouteAuthorizerBindOptions) HttpRouteAuthorizerConfig#Bind this authorizer to a specified Http route.