GatewayCustomClaim Class
Represents a custom claim validation configuration for Gateway JWT authorizers.
Custom claims allow you to validate additional fields in JWT tokens beyond the standard audience, client, and scope validations.
| Source | aws-bedrockagentcore/lib/gateway/inbound-auth/custom-claim.ts |
|---|---|
| Type last changed |
Example
ts
// Optional: Create custom claims (CustomClaimOperator and GatewayCustomClaim from agentcore)
const customClaims = [
agentcore.GatewayCustomClaim.withStringValue('department', 'engineering'),
agentcore.GatewayCustomClaim.withStringArrayValue('roles', ['admin'], agentcore.CustomClaimOperator.CONTAINS),
agentcore.GatewayCustomClaim.withStringArrayValue('permissions', ['read', 'write'], agentcore.CustomClaimOperator.CONTAINS_ANY),
];
const gateway = new agentcore.Gateway(this, "MyGateway", {
gatewayName: "my-gateway",
authorizerConfiguration: agentcore.GatewayAuthorizer.usingCustomJwt({
discoveryUrl: "https://auth.example.com/.well-known/openid-configuration",
allowedAudience: ["my-app"],
allowedClients: ["my-client-id"],
allowedScopes: ["read", "write"],
customClaims: customClaims, // Optional custom claims
}),
});
python
# Optional: Create custom claims (CustomClaimOperator and GatewayCustomClaim from agentcore)
custom_claims = [
agentcore.GatewayCustomClaim.with_string_value("department", "engineering"),
agentcore.GatewayCustomClaim.with_string_array_value("roles", ["admin"], agentcore.CustomClaimOperator.CONTAINS),
agentcore.GatewayCustomClaim.with_string_array_value("permissions", ["read", "write"], agentcore.CustomClaimOperator.CONTAINS_ANY)
]
gateway = agentcore.Gateway(self, "MyGateway",
gateway_name="my-gateway",
authorizer_configuration=agentcore.GatewayAuthorizer.using_custom_jwt(
discovery_url="https://auth.example.com/.well-known/openid-configuration",
allowed_audience=["my-app"],
allowed_clients=["my-client-id"],
allowed_scopes=["read", "write"],
custom_claims=custom_claims
)
)
java
// Optional: Create custom claims (CustomClaimOperator and GatewayCustomClaim from agentcore)
GatewayCustomClaim[] customClaims = List.of(GatewayCustomClaim.withStringValue("department", "engineering"), GatewayCustomClaim.withStringArrayValue("roles", List.of("admin"), CustomClaimOperator.CONTAINS), GatewayCustomClaim.withStringArrayValue("permissions", List.of("read", "write"), CustomClaimOperator.CONTAINS_ANY));
Gateway gateway = Gateway.Builder.create(this, "MyGateway")
.gatewayName("my-gateway")
.authorizerConfiguration(GatewayAuthorizer.usingCustomJwt(CustomJwtConfiguration.builder()
.discoveryUrl("https://auth.example.com/.well-known/openid-configuration")
.allowedAudience(List.of("my-app"))
.allowedClients(List.of("my-client-id"))
.allowedScopes(List.of("read", "write"))
.customClaims(customClaims)
.build()))
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Optional: Create custom claims (CustomClaimOperator and GatewayCustomClaim from agentcore)
var customClaims = new [] { GatewayCustomClaim.WithStringValue("department", "engineering"), GatewayCustomClaim.WithStringArrayValue("roles", new [] { "admin" }, CustomClaimOperator.CONTAINS), GatewayCustomClaim.WithStringArrayValue("permissions", new [] { "read", "write" }, CustomClaimOperator.CONTAINS_ANY) };
var gateway = new Gateway(this, "MyGateway", new GatewayProps {
GatewayName = "my-gateway",
AuthorizerConfiguration = GatewayAuthorizer.UsingCustomJwt(new CustomJwtConfiguration {
DiscoveryUrl = "https://auth.example.com/.well-known/openid-configuration",
AllowedAudience = new [] { "my-app" },
AllowedClients = new [] { "my-client-id" },
AllowedScopes = new [] { "read", "write" },
CustomClaims = customClaims
})
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Optional: Create custom claims (CustomClaimOperator and GatewayCustomClaim from agentcore)
customClaims := []GatewayCustomClaim{
agentcore.GatewayCustomClaim_WithStringValue(jsii.String("department"), jsii.String("engineering")),
agentcore.GatewayCustomClaim_WithStringArrayValue(jsii.String("roles"), []*string{
jsii.String("admin"),
}, agentcore.CustomClaimOperator_CONTAINS),
agentcore.GatewayCustomClaim_WithStringArrayValue(jsii.String("permissions"), []*string{
jsii.String("read"),
jsii.String("write"),
}, agentcore.CustomClaimOperator_CONTAINS_ANY),
}
gateway := agentcore.NewGateway(this, jsii.String("MyGateway"), &GatewayProps{
GatewayName: jsii.String("my-gateway"),
AuthorizerConfiguration: agentcore.GatewayAuthorizer_UsingCustomJwt(&CustomJwtConfiguration{
DiscoveryUrl: jsii.String("https://auth.example.com/.well-known/openid-configuration"),
AllowedAudience: []*string{
jsii.String("my-app"),
},
AllowedClients: []*string{
jsii.String("my-client-id"),
},
AllowedScopes: []*string{
jsii.String("read"),
jsii.String("write"),
},
CustomClaims: customClaims,
}),
})
Methods
withStringArrayValue(name: string, values: string[], operator?: CustomClaimOperator): GatewayCustomClaim // chainable@staticmethod def with_string_array_value(name: str, values: typing.List[str], operator: typing.Optional[CustomClaimOperator] = None) -> GatewayCustomClaimpublic static GatewayCustomClaim withStringArrayValue(String name, List<String> values, CustomClaimOperator operator)public static GatewayCustomClaim WithStringArrayValue(string name, string[] values, CustomClaimOperator? operator = null)func WithStringArrayValue(Name *string, Values *[]*string, Operator CustomClaimOperator) GatewayCustomClaim static #Create a custom claim with a string array value.
String array claims can use CONTAINS (default) or CONTAINS_ANY operator.
3 parameters · returns
Parameters
namenamenamenameName— The name of the claim in the JWT token.valuesvaluesvaluesvaluesValues— The array of string values to match.operatoroperatoroperatoroperatorOperator— The match operator (defaults to CONTAINS).
Returns: A GatewayCustomClaim configured for string array validation
withStringValue(name: string, value: string): GatewayCustomClaim // chainable@staticmethod def with_string_value(name: str, value: str) -> GatewayCustomClaimpublic static GatewayCustomClaim withStringValue(String name, String value)public static GatewayCustomClaim WithStringValue(string name, string value)func WithStringValue(Name *string, Value *string) GatewayCustomClaim static #Create a custom claim with a string value.
String claims must use the EQUALS operator.
2 parameters · returns
Parameters
namenamenamenameName— The name of the claim in the JWT token.valuevaluevaluevalueValue— The string value to match (must exactly equal).
Returns: A GatewayCustomClaim configured for string validation