# TokenAuthorizerProps

Properties for TokenAuthorizer.

Extends: [LambdaAuthorizerProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.LambdaAuthorizerProps.html)
Used as props by: [TokenAuthorizer](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.TokenAuthorizer.html)

- Source: [`aws-apigateway/lib/authorizers/lambda.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-apigateway/lib/authorizers/lambda.ts#L180)

## Example

TypeScript:

```ts
declare const authFn: lambda.Function;
declare const books: apigateway.Resource;

const auth = new apigateway.TokenAuthorizer(this, 'booksAuthorizer', {
  handler: authFn
});

books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
  authorizer: auth
});
```

Python:

```python
# auth_fn: lambda.Function
# books: apigateway.Resource

auth = apigateway.TokenAuthorizer(self, "booksAuthorizer",
    handler=auth_fn
)

books.add_method("GET", apigateway.HttpIntegration("http://amazon.com"),
    authorizer=auth
)
```

Java:

```java
Function authFn;
Resource books;

TokenAuthorizer auth = TokenAuthorizer.Builder.create(this, "booksAuthorizer")
        .handler(authFn)
        .build();

books.addMethod("GET", new HttpIntegration("http://amazon.com"), MethodOptions.builder()
        .authorizer(auth)
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Function authFn;
Resource books;

var auth = new TokenAuthorizer(this, "booksAuthorizer", new TokenAuthorizerProps {
    Handler = authFn
});

books.AddMethod("GET", new HttpIntegration("http://amazon.com"), new MethodOptions {
    Authorizer = auth
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var authFn Function
var books Resource

auth := apigateway.NewTokenAuthorizer(this, jsii.String("booksAuthorizer"), &TokenAuthorizerProps{
	Handler: authFn,
})

books.AddMethod(jsii.String("GET"), apigateway.NewHttpIntegration(jsii.String("http://amazon.com")), &MethodOptions{
	Authorizer: auth,
})
```

## Properties

- `assumeRole`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — An optional IAM role for APIGateway to assume before calling the Lambda-based authorizer.

  **Default:** A resource policy is added to the Lambda function allowing apigateway.amazonaws.com to invoke the function.

  The IAM role must be
  assumable by 'apigateway.amazonaws.com'.

- `authorizerName`: string — An optional human friendly name for the authorizer.

  **Default:** the unique construct ID

  Note that, this is not the primary identifier of the authorizer.

- `handler`: [IFunction](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IFunction.html) (required) — The handler for the authorizer lambda function.

  The handler must follow a very specific protocol on the input it receives
  and the output it needs to produce.  API Gateway has documented the
  handler's [input specification](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html)
  and [output specification](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html).

- `identitySource`: string — The request header mapping expression for the bearer token.

  **Default:** `IdentitySource.header('Authorization')`

  This is typically passed as part of the header, in which case
  this should be `method.request.header.Authorizer` where `Authorizer` is the header containing the bearer token.

- `resultsCacheTtl`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.minutes(5) — How long APIGateway should cache the results.

  Max 1 hour.
  Disable caching by setting this to 0.

- `validationRegex`: string — An optional regex to be matched against the authorization token.

  **Default:** no regex filter will be applied.

  When matched the authorizer lambda is invoked,
  otherwise a 401 Unauthorized is returned to the client.
