Skip to content

Commit

Permalink
Move and strengthen custom auth validity check
Browse files Browse the repository at this point in the history
  • Loading branch information
bretambrose committed Dec 13, 2023
1 parent 248ce26 commit 8e41233
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/common/aws_iot_shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,19 @@ export function populate_username_string_with_custom_authorizer(
if (is_string_and_not_empty(input_authorizer) && input_authorizer) {
username_string = add_to_username_parameter(username_string, input_authorizer, "x-amz-customauthorizer-name=");
}
if (is_string_and_not_empty(input_signature) && input_signature) {
username_string = add_to_username_parameter(username_string, input_signature, "x-amz-customauthorizer-signature=");
}

if (is_string_and_not_empty(input_signature) || is_string_and_not_empty(input_token_value) || is_string_and_not_empty(input_token_key_name)) {
if (!input_token_value || !input_token_key_name) {
if (!input_token_value || !input_token_key_name || !input_signature) {
throw new Error("Signing-based custom authentication requires all token-related properties to be set");
}
}

if (is_string_and_not_empty(input_signature) && input_signature) {
username_string = add_to_username_parameter(username_string, input_signature, "x-amz-customauthorizer-signature=");
}

if (is_string_and_not_empty(input_token_value) && is_string_and_not_empty(input_token_key_name)) {
// @ts-ignore
username_string = add_to_username_parameter(username_string, input_token_value, input_token_key_name + "=");
}

Expand Down

0 comments on commit 8e41233

Please sign in to comment.