Class: AWSCDK::APIGateway::TokenAuthorizerProps

Inherits:
LambdaAuthorizerProps
  • Object
show all
Defined in:
api_gateway/token_authorizer_props.rb

Overview

Properties for TokenAuthorizer.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler:, assume_role: nil, authorizer_name: nil, results_cache_ttl: nil, identity_source: nil, validation_regex: nil) ⇒ TokenAuthorizerProps

Returns a new instance of TokenAuthorizerProps.

Parameters:

  • handler (AWSCDK::Lambda::IFunction)

    The handler for the authorizer lambda function.

  • assume_role (AWSCDK::IAM::IRole, nil) (defaults to: nil)

    An optional IAM role for APIGateway to assume before calling the Lambda-based authorizer.

  • authorizer_name (String, nil) (defaults to: nil)

    An optional human friendly name for the authorizer.

  • results_cache_ttl (AWSCDK::Duration, nil) (defaults to: nil)

    How long APIGateway should cache the results.

  • identity_source (String, nil) (defaults to: nil)

    The request header mapping expression for the bearer token.

  • validation_regex (String, nil) (defaults to: nil)

    An optional regex to be matched against the authorization token.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'api_gateway/token_authorizer_props.rb', line 13

def initialize(handler:, assume_role: nil, authorizer_name: nil, results_cache_ttl: nil, identity_source: nil, validation_regex: nil)
  @handler = handler
  Jsii::Type.check_type(@handler, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLklGdW5jdGlvbiJ9")), "handler")
  @assume_role = assume_role
  Jsii::Type.check_type(@assume_role, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLklSb2xlIn0=")), "assumeRole") unless @assume_role.nil?
  @authorizer_name = authorizer_name
  Jsii::Type.check_type(@authorizer_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "authorizerName") unless @authorizer_name.nil?
  @results_cache_ttl = results_cache_ttl
  Jsii::Type.check_type(@results_cache_ttl, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5EdXJhdGlvbiJ9")), "resultsCacheTtl") unless @results_cache_ttl.nil?
  @identity_source = identity_source
  Jsii::Type.check_type(@identity_source, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "identitySource") unless @identity_source.nil?
  @validation_regex = validation_regex
  Jsii::Type.check_type(@validation_regex, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "validationRegex") unless @validation_regex.nil?
end

Instance Attribute Details

#assume_roleAWSCDK::IAM::IRole? (readonly)

Note:

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

An optional IAM role for APIGateway to assume before calling the Lambda-based authorizer.

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

Returns:



44
45
46
# File 'api_gateway/token_authorizer_props.rb', line 44

def assume_role
  @assume_role
end

#authorizer_nameString? (readonly)

Note:

Default: - the unique construct ID

An optional human friendly name for the authorizer.

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

Returns:

  • (String, nil)


51
52
53
# File 'api_gateway/token_authorizer_props.rb', line 51

def authorizer_name
  @authorizer_name
end

#handlerAWSCDK::Lambda::IFunction (readonly)

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 and output specification.



36
37
38
# File 'api_gateway/token_authorizer_props.rb', line 36

def handler
  @handler
end

#identity_sourceString? (readonly)

Note:

Default: IdentitySource.header('Authorization')

The request header mapping expression for the bearer token.

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.



68
69
70
# File 'api_gateway/token_authorizer_props.rb', line 68

def identity_source
  @identity_source
end

#results_cache_ttlAWSCDK::Duration? (readonly)

Note:

Default: - Duration.minutes(5)

How long APIGateway should cache the results.

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

Returns:



59
60
61
# File 'api_gateway/token_authorizer_props.rb', line 59

def results_cache_ttl
  @results_cache_ttl
end

#validation_regexString? (readonly)

Note:

Default: - no regex filter will be applied.

An optional regex to be matched against the authorization token.

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

Returns:

  • (String, nil)


76
77
78
# File 'api_gateway/token_authorizer_props.rb', line 76

def validation_regex
  @validation_regex
end

Class Method Details

.jsii_propertiesObject



78
79
80
81
82
83
84
85
86
87
# File 'api_gateway/token_authorizer_props.rb', line 78

def self.jsii_properties
  {
    :handler => "handler",
    :assume_role => "assumeRole",
    :authorizer_name => "authorizerName",
    :results_cache_ttl => "resultsCacheTtl",
    :identity_source => "identitySource",
    :validation_regex => "validationRegex",
  }
end

Instance Method Details

#to_jsiiObject



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'api_gateway/token_authorizer_props.rb', line 89

def to_jsii
  result = {}
  result.merge!(super)
  result.merge!({
    "handler" => @handler,
    "assumeRole" => @assume_role,
    "authorizerName" => @authorizer_name,
    "resultsCacheTtl" => @results_cache_ttl,
    "identitySource" => @identity_source,
    "validationRegex" => @validation_regex,
  })
  result.compact
end