From 625e0499cde02164bb80c92851681b93201175a4 Mon Sep 17 00:00:00 2001 From: Igor Abdrakhimov Date: Thu, 15 Feb 2024 10:20:04 -0800 Subject: [PATCH] Make similar to java samples --- samples/node/websocket_connect/README.md | 85 +++++++----------------- 1 file changed, 25 insertions(+), 60 deletions(-) diff --git a/samples/node/websocket_connect/README.md b/samples/node/websocket_connect/README.md index 54ffe1b4..715d87dd 100644 --- a/samples/node/websocket_connect/README.md +++ b/samples/node/websocket_connect/README.md @@ -48,20 +48,19 @@ node dist/index.js --endpoint --ca_file --signing_region ", credentials_provider: auth.AwsCredentialsProvider.newStatic("", "", "") }); - config_builder.with_clean_session(false); - config_builder.with_client_id(argv.client_id || "test-" + Math.floor(Math.random() * 100000000)); - config_builder.with_endpoint(argv.endpoint); + let client_endpoint : string = "-ats.iot..amazonaws.com"; + config_builder.with_endpoint(client_endpoint); const config = config_builder.build(); const client = new mqtt.MqttClient(); @@ -72,7 +71,7 @@ function build_connection(argv: Args): mqtt.MqttClientConnection { ### MQTT over WebSockets with Custom Authorizer An MQTT3 direct connection can be made using a [Custom Authorizer](https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html). -When making a connection to a Custom Authorizer, the MQTT3 client can optionally passing username, password, and/or token +When making a connection using a Custom Authorizer, the MQTT3 client can optionally passing username, password, and/or token signature arguments based on the configuration of the Custom Authorizer on AWS IoT Core. You will need to setup your Custom Authorizer so that the lambda function returns a policy document to properly connect. @@ -83,22 +82,18 @@ If your Custom Authorizer does not use signing, you don't specify anything relat the following code: ```typescript -function build_connection(argv: Args): mqtt.MqttClientConnection { +function build_connection(): mqtt.MqttClientConnection { let config_builder = iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets({ - region: argv.signing_region + region: "" }); - with_custom_authorizer(username : string, authorizer_name : string, authorizer_signature : string, password : string, token_key_name? : string, token_value? : string) { - config_builder.with_custom_authorizer( - argv.custom_auth_username, - argv.custom_auth_authorizer_name, - undefined, - argv.custom_auth_password); - - config_builder.with_clean_session(false); - config_builder.with_client_id(argv.client_id || "test-" + Math.floor(Math.random() * 100000000)); - config_builder.with_endpoint(argv.endpoint); + authorizer_name: "", + username: "", + password: ); + + let client_endpoint : string = "-ats.iot..amazonaws.com"; + config_builder.with_endpoint(client_endpoint); const config = config_builder.build(); const client = new mqtt.MqttClient(); @@ -106,58 +101,28 @@ function build_connection(argv: Args): mqtt.MqttClientConnection { } ``` -To run the websocket connect with custom authorizer use the following command: - -```sh -npm install -node dist/index.js --endpoint \ ---ca_file \ ---signing_region \ ---custom_auth_username \ ---custom_auth_authorizer_name \ ---custom_auth_password \ -``` - If your custom authorizer uses signing, you must specify the three signed token properties as well. It is your responsibility to URI-encode the username, authorizerName, and tokenKeyName parameters. ```typescript -function build_connection(argv: Args): mqtt.MqttClientConnection { +function build_connection(): mqtt.MqttClientConnection { let config_builder = iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets({ - region: argv.signing_region + region: "" }); - with_custom_authorizer(username : string, authorizer_name : string, authorizer_signature : string, password : string, token_key_name? : string, token_value? : string) { - config_builder.with_custom_authorizer( - argv.custom_auth_username, - argv.custom_auth_authorizer_name, - argv.custom_auth_authorizer_signature, - argv.custom_auth_password, - argv.custom_auth_token_key_name, - argv.custom_auth_token_value); - - config_builder.with_clean_session(false); - config_builder.with_client_id(argv.client_id || "test-" + Math.floor(Math.random() * 100000000)); - config_builder.with_endpoint(argv.endpoint); + authorizer_name: "", + username: "", + password: , + token_key_name: "", + token_value: "", + authorizer_signature: ""); + + let client_endpoint : string = "-ats.iot..amazonaws.com"; + config_builder.with_endpoint(client_endpoint); const config = config_builder.build(); const client = new mqtt.MqttClient(); return client.new_connection(config); } ``` - -To run the websocket connect with custom authorizer using signing use the following command: - -```sh -npm install -node dist/index.js --endpoint \ ---ca_file \ ---signing_region \ ---custom_auth_username \ ---custom_auth_authorizer_name \ ---custom_auth_authorizer_signature \ ---custom_auth_password \ ---custom_auth_token_key_name \ ---custom_auth_token_key_value -```