Skip to content

Commit

Permalink
Rework websocket config to always create a credentials provider manua…
Browse files Browse the repository at this point in the history
…lly; fixes x509 bug and makes sample config less confusing (#134)
  • Loading branch information
bretambrose authored Jul 23, 2020
1 parent fb229ce commit 38f166a
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions samples/mqtt/basic_pub_sub/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,14 @@ int main(int argc, char *argv[])
}
else if (useWebSocket)
{
Aws::Iot::WebsocketConfig config(signingRegion, &bootstrap);
std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> provider = nullptr;

Aws::Crt::Http::HttpClientConnectionProxyOptions proxyOptions;
if (!proxyHost.empty())
{
proxyOptions.HostName = proxyHost;
proxyOptions.Port = proxyPort;
proxyOptions.AuthType = Aws::Crt::Http::AwsHttpProxyAuthenticationType::None;
config.ProxyOptions = proxyOptions;
}

if (useX509)
Expand Down Expand Up @@ -333,12 +332,26 @@ int main(int argc, char *argv[])
x509Config.ProxyOptions = proxyOptions;
}

config.CredentialsProvider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderX509(x509Config);
if (!config.CredentialsProvider)
{
fprintf(stderr, "Failure to create X509 credentials provider!\n");
return -1;
}
provider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderX509(x509Config);
}
else
{
Aws::Crt::Auth::CredentialsProviderChainDefaultConfig defaultConfig;
defaultConfig.Bootstrap = &bootstrap;

provider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderChainDefault(defaultConfig);
}

if (!provider)
{
fprintf(stderr, "Failure to create credentials provider!\n");
return -1;
}

Aws::Iot::WebsocketConfig config(signingRegion, provider);
if (!proxyHost.empty())
{
config.ProxyOptions = proxyOptions;
}

builder = Aws::Iot::MqttClientConnectionConfigBuilder(config);
Expand Down

0 comments on commit 38f166a

Please sign in to comment.