AWS STS: Create a Restricted Federated User Session
See more AWS Security Token Service Examples
Uses the AWS STS Query API version 2011-06-15 and a verified TLS connection to the commercial-partition regional endpoint sts.us-west-2.amazonaws.com. Change the endpoint and signing region together for your deployment. Assumes Chilkat is unlocked.
Keep qa_data/aws/sts.json private and outside web roots/source control. Signed examples require nonempty access_key and secret_key strings; temporary source credentials also require session_token and ISO 8601 expiration. Federation exchanges load their specific fields without AWS keys. The examples do not print credentials, bearer tokens, full responses or diagnostic dumps. Credential-producing examples build a complete in-memory session object with access_key, secret_key, session_token and expiration; integrate that object into your application before it goes out of scope.
Use a protected IAM user's long-term credentials with sts:GetFederationToken permission, never root credentials. The focused session policy allows s3:ListAllMyBuckets only to the extent allowed by the user and applicable policies. Returned credentials cannot call IAM APIs and have restrictions on STS operations; use GetCallerIdentity to inspect them. Session policy omission is not a way to obtain unrestricted permissions.
AWS references: GetFederationToken
Chilkat C Downloads
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
#include <C_CkDateTime.h>
#include <C_CkAuthAws.h>
#include <C_CkRest.h>
#include <C_CkSocket.h>
#include <C_CkXml.h>
void ChilkatSample(void)
{
BOOL success;
HCkStringBuilder stringCompare;
HCkJsonObject credentials;
BOOL stringMatch1;
BOOL stringMatch2;
HCkDateTime expires;
HCkDateTime now;
const char *region;
HCkJsonObject policy;
HCkStringBuilder endpoint;
HCkAuthAws aws;
HCkRest rest;
HCkSocket connection;
HCkXml xml;
const char *value;
const char *accessKey;
const char *secretKey;
const char *sessionToken;
const char *expiration;
const char *responseXml;
BOOL stringMatch3;
BOOL stringMatch4;
BOOL stringMatch5;
BOOL stringMatch6;
BOOL stringMatch7;
BOOL stringMatch8;
BOOL stringMatch9;
BOOL stringMatch10;
HCkJsonObject session;
success = FALSE;
stringCompare = CkStringBuilder_Create();
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Keep this file private and outside public web content/source control.
credentials = CkJsonObject_Create();
CkJsonObject_putStrict(credentials,TRUE);
success = CkJsonObject_LoadFile(credentials,"qa_data/aws/sts.json");
if (success != TRUE) {
printf("Could not load private STS configuration.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
return;
}
CkStringBuilder_SetString(stringCompare,CkJsonObject_stringOf(credentials,"access_key"));
stringMatch1 = CkStringBuilder_ContentsEqual(stringCompare,"",TRUE);
if ((CkJsonObject_JsonTypeOf(credentials,"access_key") != 1) || (stringMatch1 == TRUE)) {
printf("Missing or invalid access_key.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
return;
}
CkStringBuilder_SetString(stringCompare,CkJsonObject_stringOf(credentials,"secret_key"));
stringMatch2 = CkStringBuilder_ContentsEqual(stringCompare,"",TRUE);
if ((CkJsonObject_JsonTypeOf(credentials,"secret_key") != 1) || (stringMatch2 == TRUE)) {
printf("Missing or invalid secret_key.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
return;
}
expires = CkDateTime_Create();
now = CkDateTime_Create();
region = "us-west-2";
if (CkJsonObject_HasMember(credentials,"session_token") == TRUE) {
printf("GetFederationToken requires long-term IAM user credentials.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
return;
}
policy = CkJsonObject_Create();
success = CkJsonObject_UpdateString(policy,"Version","2012-10-17");
if (success != TRUE) {
printf("Could not construct session policy.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
return;
}
success = CkJsonObject_UpdateString(policy,"Statement[0].Effect","Allow");
if (success != TRUE) {
printf("Could not construct session policy.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
return;
}
success = CkJsonObject_UpdateString(policy,"Statement[0].Action","s3:ListAllMyBuckets");
if (success != TRUE) {
printf("Could not construct session policy.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
return;
}
success = CkJsonObject_UpdateString(policy,"Statement[0].Resource","*");
if (success != TRUE) {
printf("Could not construct session policy.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
return;
}
CkJsonObject_putEmitCompact(policy,TRUE);
endpoint = CkStringBuilder_Create();
CkStringBuilder_Append(endpoint,"sts.");
CkStringBuilder_Append(endpoint,region);
CkStringBuilder_Append(endpoint,".amazonaws.com");
aws = CkAuthAws_Create();
CkAuthAws_putAccessKey(aws,CkJsonObject_stringOf(credentials,"access_key"));
CkAuthAws_putSecretKey(aws,CkJsonObject_stringOf(credentials,"secret_key"));
CkAuthAws_putRegion(aws,region);
CkAuthAws_putServiceName(aws,"sts");
CkAuthAws_putSignatureVersion(aws,4);
rest = CkRest_Create();
CkRest_putConnectTimeoutMs(rest,20000);
CkRest_putIdleTimeoutMs(rest,60000);
CkRest_putVerboseLogging(rest,FALSE);
success = CkRest_SetAuthAws(rest,aws);
if (success != TRUE) {
printf("Could not configure request signing.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
return;
}
// Keep this verified Socket alive while Rest uses its connection.
connection = CkSocket_Create();
CkSocket_putRequireSslCertVerify(connection,TRUE);
CkSocket_putMaxReadIdleMs(connection,60000);
CkSocket_putMaxSendIdleMs(connection,60000);
success = CkSocket_Connect(connection,CkStringBuilder_getAsString(endpoint),443,TRUE,20000);
if (success != TRUE) {
printf("TLS connection failed; inspect diagnostics privately.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
return;
}
success = CkRest_UseConnection(rest,connection,TRUE);
if (success != TRUE) {
printf("Could not attach TLS connection.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
return;
}
xml = CkXml_Create();
CkXml_putStrict(xml,TRUE);
responseXml = "";
success = CkRest_ClearAllQueryParams(rest);
if (success != TRUE) {
printf("Could not reset request parameters.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
success = CkRest_AddQueryParam(rest,"Action","GetFederationToken");
if (success != TRUE) {
printf("Could not set Action.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
success = CkRest_AddQueryParam(rest,"Version","2011-06-15");
if (success != TRUE) {
printf("Could not set Version.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
if (CkJsonObject_HasMember(credentials,"session_token") == TRUE) {
success = CkRest_AddQueryParam(rest,"X-Amz-Security-Token",CkJsonObject_stringOf(credentials,"session_token"));
if (success != TRUE) {
printf("Could not set X-Amz-Security-Token.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
}
success = CkRest_AddQueryParam(rest,"Name","chilkat-federated-user");
if (success != TRUE) {
printf("Could not set Name.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
success = CkRest_AddQueryParam(rest,"DurationSeconds","3600");
if (success != TRUE) {
printf("Could not set DurationSeconds.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
success = CkRest_AddQueryParam(rest,"Policy",CkJsonObject_emit(policy));
if (success != TRUE) {
printf("Could not set Policy.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
responseXml = CkRest_fullRequestFormUrlEncoded(rest,"POST","/");
if (CkRest_getLastMethodSuccess(rest) != TRUE) {
printf("STS transport failed; inspect diagnostics privately.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
if (CkRest_getResponseStatusCode(rest) != 200) {
printf("STS HTTP status: %d\n",CkRest_getResponseStatusCode(rest));
success = CkXml_LoadXml(xml,responseXml);
if (success == TRUE) {
value = CkXml_getChildContent(xml,"Error|Code");
if (CkXml_getLastMethodSuccess(xml) == TRUE) {
printf("AWS error code: %s\n",value);
}
value = CkXml_getChildContent(xml,"RequestId");
if (CkXml_getLastMethodSuccess(xml) == TRUE) {
printf("AWS request ID: %s\n",value);
}
}
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
success = CkXml_LoadXml(xml,responseXml);
if (success != TRUE) {
printf("Invalid STS XML response.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
CkStringBuilder_SetString(stringCompare,CkXml_tag(xml));
stringMatch3 = CkStringBuilder_ContentsEqual(stringCompare,"GetFederationTokenResponse",TRUE);
if (stringMatch3 != TRUE) {
printf("Unexpected STS response root.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
value = CkXml_getChildContent(xml,"ResponseMetadata|RequestId");
CkStringBuilder_SetString(stringCompare,value);
stringMatch4 = CkStringBuilder_ContentsEqual(stringCompare,"",TRUE);
if ((CkXml_getLastMethodSuccess(xml) != TRUE) || (stringMatch4 == TRUE)) {
printf("Missing or empty ResponseMetadata|RequestId.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
if (CkXml_HasChildWithTag(xml,"GetFederationTokenResult") != TRUE) {
printf("Missing STS result.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
accessKey = CkXml_getChildContent(xml,"GetFederationTokenResult|Credentials|AccessKeyId");
CkStringBuilder_SetString(stringCompare,accessKey);
stringMatch5 = CkStringBuilder_ContentsEqual(stringCompare,"",TRUE);
if ((CkXml_getLastMethodSuccess(xml) != TRUE) || (stringMatch5 == TRUE)) {
printf("Missing or empty GetFederationTokenResult|Credentials|AccessKeyId.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
secretKey = CkXml_getChildContent(xml,"GetFederationTokenResult|Credentials|SecretAccessKey");
CkStringBuilder_SetString(stringCompare,secretKey);
stringMatch6 = CkStringBuilder_ContentsEqual(stringCompare,"",TRUE);
if ((CkXml_getLastMethodSuccess(xml) != TRUE) || (stringMatch6 == TRUE)) {
printf("Missing or empty GetFederationTokenResult|Credentials|SecretAccessKey.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
sessionToken = CkXml_getChildContent(xml,"GetFederationTokenResult|Credentials|SessionToken");
CkStringBuilder_SetString(stringCompare,sessionToken);
stringMatch7 = CkStringBuilder_ContentsEqual(stringCompare,"",TRUE);
if ((CkXml_getLastMethodSuccess(xml) != TRUE) || (stringMatch7 == TRUE)) {
printf("Missing or empty GetFederationTokenResult|Credentials|SessionToken.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
expiration = CkXml_getChildContent(xml,"GetFederationTokenResult|Credentials|Expiration");
CkStringBuilder_SetString(stringCompare,expiration);
stringMatch8 = CkStringBuilder_ContentsEqual(stringCompare,"",TRUE);
if ((CkXml_getLastMethodSuccess(xml) != TRUE) || (stringMatch8 == TRUE)) {
printf("Missing or empty GetFederationTokenResult|Credentials|Expiration.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
success = CkDateTime_SetFromTimestamp(expires,expiration);
if (success != TRUE) {
printf("Returned expiration is invalid.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
success = CkDateTime_SetFromCurrentSystemTime(now);
if (success != TRUE) {
printf("Could not read current time.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
if (CkDateTime_DiffSeconds(expires,now) <= 60) {
printf("Returned credentials are expired or expire within 60 seconds; obtain fresh credentials.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
value = CkXml_getChildContent(xml,"GetFederationTokenResult|FederatedUser|Arn");
CkStringBuilder_SetString(stringCompare,value);
stringMatch9 = CkStringBuilder_ContentsEqual(stringCompare,"",TRUE);
if ((CkXml_getLastMethodSuccess(xml) != TRUE) || (stringMatch9 == TRUE)) {
printf("Missing or empty GetFederationTokenResult|FederatedUser|Arn.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
value = CkXml_getChildContent(xml,"GetFederationTokenResult|FederatedUser|FederatedUserId");
CkStringBuilder_SetString(stringCompare,value);
stringMatch10 = CkStringBuilder_ContentsEqual(stringCompare,"",TRUE);
if ((CkXml_getLastMethodSuccess(xml) != TRUE) || (stringMatch10 == TRUE)) {
printf("Missing or empty GetFederationTokenResult|FederatedUser|FederatedUserId.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
return;
}
session = CkJsonObject_Create();
success = CkJsonObject_UpdateString(session,"access_key",accessKey);
if (success != TRUE) {
printf("Could not build complete session.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
CkJsonObject_Dispose(session);
return;
}
success = CkJsonObject_UpdateString(session,"secret_key",secretKey);
if (success != TRUE) {
printf("Could not build complete session.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
CkJsonObject_Dispose(session);
return;
}
success = CkJsonObject_UpdateString(session,"session_token",sessionToken);
if (success != TRUE) {
printf("Could not build complete session.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
CkJsonObject_Dispose(session);
return;
}
success = CkJsonObject_UpdateString(session,"expiration",expiration);
if (success != TRUE) {
printf("Could not build complete session.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
CkJsonObject_Dispose(session);
return;
}
// Use session in memory; do not print or log session.Emit().
printf("Session validated; expiration: %s\n",expiration);
printf("Example completed.\n");
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkDateTime_Dispose(expires);
CkDateTime_Dispose(now);
CkJsonObject_Dispose(policy);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkXml_Dispose(xml);
CkJsonObject_Dispose(session);
}