-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(apigateway): improve docs and default value settings for identity source in authorizer #28214
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Construct } from 'constructs'; | ||
import { IdentitySource } from './identity-source'; | ||
import * as cognito from '../../../aws-cognito'; | ||
import { Duration, FeatureFlags, Lazy, Names, Stack } from '../../../core'; | ||
import { APIGATEWAY_AUTHORIZER_CHANGE_DEPLOYMENT_LOGICAL_ID } from '../../../cx-api'; | ||
|
@@ -33,8 +34,9 @@ export interface CognitoUserPoolsAuthorizerProps { | |
|
||
/** | ||
* 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. | ||
* @see https://docs.aws.amazon.com/apigateway/api-reference/link-relation/authorizer-create/#identitySource | ||
* this should be `method.request.header.Authorizer` where `Authorizer` is the header containing the bearer token. | ||
* | ||
* @see https://docs.aws.amazon.com/apigateway/latest/api/API_CreateAuthorizer.html#apigw-CreateAuthorizer-request-identitySource | ||
* @default `IdentitySource.header('Authorization')` | ||
*/ | ||
readonly identitySource?: string; | ||
|
@@ -78,7 +80,7 @@ export class CognitoUserPoolsAuthorizer extends Authorizer implements IAuthorize | |
type: 'COGNITO_USER_POOLS', | ||
providerArns: props.cognitoUserPools.map(userPool => userPool.userPoolArn), | ||
authorizerResultTtlInSeconds: props.resultsCacheTtl?.toSeconds(), | ||
identitySource: props.identitySource || 'method.request.header.Authorization', | ||
identitySource: props.identitySource || IdentitySource.header('Authorization'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change caused by this is guaranteed by this test. |
||
}; | ||
|
||
this.authorizerProps = authorizerProps; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Construct } from 'constructs'; | ||
import { IdentitySource } from './identity-source'; | ||
import * as iam from '../../../aws-iam'; | ||
import * as lambda from '../../../aws-lambda'; | ||
import { Arn, ArnFormat, Duration, FeatureFlags, Lazy, Names, Stack } from '../../../core'; | ||
|
@@ -182,8 +183,9 @@ export interface TokenAuthorizerProps extends LambdaAuthorizerProps { | |
|
||
/** | ||
* 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. | ||
* @see https://docs.aws.amazon.com/apigateway/api-reference/link-relation/authorizer-create/#identitySource | ||
* this should be `method.request.header.Authorizer` where `Authorizer` is the header containing the bearer token. | ||
* | ||
* @see https://docs.aws.amazon.com/apigateway/latest/api/API_CreateAuthorizer.html#apigw-CreateAuthorizer-request-identitySource | ||
* @default `IdentitySource.header('Authorization')` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default value setting process has been changed to fit here. |
||
*/ | ||
readonly identitySource?: string; | ||
|
@@ -216,7 +218,7 @@ export class TokenAuthorizer extends LambdaAuthorizer { | |
authorizerUri: lambdaAuthorizerArn(props.handler), | ||
authorizerCredentials: props.assumeRole?.roleArn, | ||
authorizerResultTtlInSeconds: props.resultsCacheTtl?.toSeconds() ?? Duration.minutes(5).toSeconds(), | ||
identitySource: props.identitySource || 'method.request.header.Authorization', | ||
identitySource: props.identitySource || IdentitySource.header('Authorization'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change caused by this is guaranteed by this test. |
||
identityValidationExpression: props.validationRegex, | ||
}; | ||
|
||
|
@@ -242,14 +244,14 @@ export interface RequestAuthorizerProps extends LambdaAuthorizerProps { | |
/** | ||
* An array of request header mapping expressions for identities. Supported parameter types are | ||
* Header, Query String, Stage Variable, and Context. For instance, extracting an authorization | ||
* token from a header would use the identity source `IdentitySource.header('Authorizer')`. | ||
* token from a header would use the identity source `IdentitySource.header('Authorization')`. | ||
* | ||
* Note: API Gateway uses the specified identity sources as the request authorizer caching key. When caching is | ||
* enabled, API Gateway calls the authorizer's Lambda function only after successfully verifying that all the | ||
* specified identity sources are present at runtime. If a specified identify source is missing, null, or empty, | ||
* API Gateway returns a 401 Unauthorized response without calling the authorizer Lambda function. | ||
* | ||
* @see https://docs.aws.amazon.com/apigateway/api-reference/link-relation/authorizer-create/#identitySource | ||
* @see https://docs.aws.amazon.com/apigateway/latest/api/API_CreateAuthorizer.html#apigw-CreateAuthorizer-request-identitySource | ||
*/ | ||
readonly identitySources: string[]; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value setting process has been changed to fit here.