AWS STS: Chain Roles with SourceIdentity
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.
Supply fresh temporary credentials from the first role (including expiration), role_arn for the next role, role_session_name and source_identity. If source identity was already set, use that same immutable value; otherwise set a value allowed by policy. Both sides must authorize sts:SetSourceIdentity as applicable, in addition to AssumeRole. Requests one hour and checks the returned identity. A source identity cannot be changed during a chain.
AWS references: AssumeRole
Chilkat Go Downloads
success := false
stringCompare := chilkat.NewStringBuilder()
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Keep this file private and outside public web content/source control.
credentials := chilkat.NewJsonObject()
credentials.SetStrict(true)
success = credentials.LoadFile("qa_data/aws/sts.json")
if success != true {
fmt.Println("Could not load private STS configuration.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
return
}
stringCompare.SetString(*credentials.StringOf("access_key"))
stringMatch1 := stringCompare.ContentsEqual("",true)
if (credentials.JsonTypeOf("access_key") != 1) || (stringMatch1 == true) {
fmt.Println("Missing or invalid access_key.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
return
}
stringCompare.SetString(*credentials.StringOf("secret_key"))
stringMatch2 := stringCompare.ContentsEqual("",true)
if (credentials.JsonTypeOf("secret_key") != 1) || (stringMatch2 == true) {
fmt.Println("Missing or invalid secret_key.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
return
}
expires := chilkat.NewCkDateTime()
now := chilkat.NewCkDateTime()
region := "us-west-2"
if credentials.HasMember("session_token") == true {
stringCompare.SetString(*credentials.StringOf("session_token"))
stringMatch3 := stringCompare.ContentsEqual("",true)
if (credentials.JsonTypeOf("session_token") != 1) || (stringMatch3 == true) {
fmt.Println("Missing or invalid session_token.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
return
}
stringCompare.SetString(*credentials.StringOf("expiration"))
stringMatch4 := stringCompare.ContentsEqual("",true)
if (credentials.JsonTypeOf("expiration") != 1) || (stringMatch4 == true) {
fmt.Println("Missing or invalid expiration.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
return
}
success = expires.SetFromTimestamp(*credentials.StringOf("expiration"))
if success != true {
fmt.Println("Source expiration is invalid.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
return
}
success = now.SetFromCurrentSystemTime()
if success != true {
fmt.Println("Could not read current time.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
return
}
if expires.DiffSeconds(now) <= 60 {
fmt.Println("Source credentials are expired or expire within 60 seconds; obtain fresh credentials.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
return
}
}
stringCompare.SetString(*credentials.StringOf("role_arn"))
stringMatch5 := stringCompare.ContentsEqual("",true)
if (credentials.JsonTypeOf("role_arn") != 1) || (stringMatch5 == true) {
fmt.Println("Missing or invalid role_arn.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
return
}
stringCompare.SetString(*credentials.StringOf("role_session_name"))
stringMatch6 := stringCompare.ContentsEqual("",true)
if (credentials.JsonTypeOf("role_session_name") != 1) || (stringMatch6 == true) {
fmt.Println("Missing or invalid role_session_name.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
return
}
identifier := chilkat.NewStringBuilder()
identifier.Append(*credentials.StringOf("role_session_name"))
if (identifier.Length() < 2) || (identifier.Length() > 64) {
fmt.Println("role_session_name must have 2-64 characters.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
return
}
allowed := chilkat.NewStringBuilder()
allowed.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_+=,.@-")
charIndex := 0
for (charIndex < identifier.Length()) {
if allowed.Contains(*identifier.GetRange(charIndex,1,false),true) != true {
fmt.Println("Invalid character in role_session_name.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
return
}
charIndex = charIndex + 1
}
stringCompare.SetString(*credentials.StringOf("session_token"))
stringMatch7 := stringCompare.ContentsEqual("",true)
if (credentials.JsonTypeOf("session_token") != 1) || (stringMatch7 == true) {
fmt.Println("Missing or invalid session_token.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
return
}
stringCompare.SetString(*credentials.StringOf("source_identity"))
stringMatch8 := stringCompare.ContentsEqual("",true)
if (credentials.JsonTypeOf("source_identity") != 1) || (stringMatch8 == true) {
fmt.Println("Missing or invalid source_identity.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
return
}
endpoint := chilkat.NewStringBuilder()
endpoint.Append("sts.")
endpoint.Append(region)
endpoint.Append(".amazonaws.com")
aws := chilkat.NewAuthAws()
aws.SetAccessKey(credentials.StringOf("access_key"))
aws.SetSecretKey(credentials.StringOf("secret_key"))
aws.SetRegion(region)
aws.SetServiceName("sts")
aws.SetSignatureVersion(4)
rest := chilkat.NewRest()
rest.SetConnectTimeoutMs(20000)
rest.SetIdleTimeoutMs(60000)
rest.SetVerboseLogging(false)
success = rest.SetAuthAws(aws)
if success != true {
fmt.Println("Could not configure request signing.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
return
}
// Keep this verified Socket alive while Rest uses its connection.
connection := chilkat.NewSocket()
connection.SetRequireSslCertVerify(true)
connection.SetMaxReadIdleMs(60000)
connection.SetMaxSendIdleMs(60000)
success = connection.Connect(*endpoint.GetAsString(),443,true,20000)
if success != true {
fmt.Println("TLS connection failed; inspect diagnostics privately.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
return
}
success = rest.UseConnection(connection,true)
if success != true {
fmt.Println("Could not attach TLS connection.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
return
}
xml := chilkat.NewXml()
xml.SetStrict(true)
var value *string = new(string)
var accessKey *string = new(string)
var secretKey *string = new(string)
var sessionToken *string = new(string)
var expiration *string = new(string)
var responseXml *string = new(string)
*responseXml = ""
success = rest.ClearAllQueryParams()
if success != true {
fmt.Println("Could not reset request parameters.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
success = rest.AddQueryParam("Action","AssumeRole")
if success != true {
fmt.Println("Could not set Action.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
success = rest.AddQueryParam("Version","2011-06-15")
if success != true {
fmt.Println("Could not set Version.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
if credentials.HasMember("session_token") == true {
success = rest.AddQueryParam("X-Amz-Security-Token",*credentials.StringOf("session_token"))
if success != true {
fmt.Println("Could not set X-Amz-Security-Token.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
}
success = rest.AddQueryParam("RoleArn",*credentials.StringOf("role_arn"))
if success != true {
fmt.Println("Could not set RoleArn.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
success = rest.AddQueryParam("RoleSessionName",*credentials.StringOf("role_session_name"))
if success != true {
fmt.Println("Could not set RoleSessionName.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
success = rest.AddQueryParam("DurationSeconds","3600")
if success != true {
fmt.Println("Could not set DurationSeconds.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
success = rest.AddQueryParam("SourceIdentity",*credentials.StringOf("source_identity"))
if success != true {
fmt.Println("Could not set SourceIdentity.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
responseXml = rest.FullRequestFormUrlEncoded("POST","/")
if rest.LastMethodSuccess() != true {
fmt.Println("STS transport failed; inspect diagnostics privately.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
if rest.ResponseStatusCode() != 200 {
fmt.Println("STS HTTP status: ", rest.ResponseStatusCode())
success = xml.LoadXml(*responseXml)
if success == true {
value = xml.GetChildContent("Error|Code")
if xml.LastMethodSuccess() == true {
fmt.Println("AWS error code: ", *value)
}
value = xml.GetChildContent("RequestId")
if xml.LastMethodSuccess() == true {
fmt.Println("AWS request ID: ", *value)
}
}
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
success = xml.LoadXml(*responseXml)
if success != true {
fmt.Println("Invalid STS XML response.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
stringCompare.SetString(xml.Tag())
stringMatch9 := stringCompare.ContentsEqual("AssumeRoleResponse",true)
if stringMatch9 != true {
fmt.Println("Unexpected STS response root.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
value = xml.GetChildContent("ResponseMetadata|RequestId")
stringCompare.SetString(*value)
stringMatch10 := stringCompare.ContentsEqual("",true)
if (xml.LastMethodSuccess() != true) || (stringMatch10 == true) {
fmt.Println("Missing or empty ResponseMetadata|RequestId.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
if xml.HasChildWithTag("AssumeRoleResult") != true {
fmt.Println("Missing STS result.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
accessKey = xml.GetChildContent("AssumeRoleResult|Credentials|AccessKeyId")
stringCompare.SetString(*accessKey)
stringMatch11 := stringCompare.ContentsEqual("",true)
if (xml.LastMethodSuccess() != true) || (stringMatch11 == true) {
fmt.Println("Missing or empty AssumeRoleResult|Credentials|AccessKeyId.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
secretKey = xml.GetChildContent("AssumeRoleResult|Credentials|SecretAccessKey")
stringCompare.SetString(*secretKey)
stringMatch12 := stringCompare.ContentsEqual("",true)
if (xml.LastMethodSuccess() != true) || (stringMatch12 == true) {
fmt.Println("Missing or empty AssumeRoleResult|Credentials|SecretAccessKey.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
sessionToken = xml.GetChildContent("AssumeRoleResult|Credentials|SessionToken")
stringCompare.SetString(*sessionToken)
stringMatch13 := stringCompare.ContentsEqual("",true)
if (xml.LastMethodSuccess() != true) || (stringMatch13 == true) {
fmt.Println("Missing or empty AssumeRoleResult|Credentials|SessionToken.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
expiration = xml.GetChildContent("AssumeRoleResult|Credentials|Expiration")
stringCompare.SetString(*expiration)
stringMatch14 := stringCompare.ContentsEqual("",true)
if (xml.LastMethodSuccess() != true) || (stringMatch14 == true) {
fmt.Println("Missing or empty AssumeRoleResult|Credentials|Expiration.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
success = expires.SetFromTimestamp(*expiration)
if success != true {
fmt.Println("Returned expiration is invalid.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
success = now.SetFromCurrentSystemTime()
if success != true {
fmt.Println("Could not read current time.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
if expires.DiffSeconds(now) <= 60 {
fmt.Println("Returned credentials are expired or expire within 60 seconds; obtain fresh credentials.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
value = xml.GetChildContent("AssumeRoleResult|AssumedRoleUser|Arn")
stringCompare.SetString(*value)
stringMatch15 := stringCompare.ContentsEqual("",true)
if (xml.LastMethodSuccess() != true) || (stringMatch15 == true) {
fmt.Println("Missing or empty AssumeRoleResult|AssumedRoleUser|Arn.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
value = xml.GetChildContent("AssumeRoleResult|AssumedRoleUser|AssumedRoleId")
stringCompare.SetString(*value)
stringMatch16 := stringCompare.ContentsEqual("",true)
if (xml.LastMethodSuccess() != true) || (stringMatch16 == true) {
fmt.Println("Missing or empty AssumeRoleResult|AssumedRoleUser|AssumedRoleId.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
return
}
session := chilkat.NewJsonObject()
success = session.UpdateString("access_key",*accessKey)
if success != true {
fmt.Println("Could not build complete session.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
session.DisposeJsonObject()
return
}
success = session.UpdateString("secret_key",*secretKey)
if success != true {
fmt.Println("Could not build complete session.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
session.DisposeJsonObject()
return
}
success = session.UpdateString("session_token",*sessionToken)
if success != true {
fmt.Println("Could not build complete session.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
session.DisposeJsonObject()
return
}
success = session.UpdateString("expiration",*expiration)
if success != true {
fmt.Println("Could not build complete session.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
session.DisposeJsonObject()
return
}
// Use session in memory; do not print or log session.Emit().
fmt.Println("Session validated; expiration: ", *expiration)
value = xml.GetChildContent("AssumeRoleResult|SourceIdentity")
stringCompare.SetString(*value)
stringMatch17 := stringCompare.ContentsEqual("",true)
if (xml.LastMethodSuccess() != true) || (stringMatch17 == true) {
fmt.Println("Missing or empty AssumeRoleResult|SourceIdentity.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
session.DisposeJsonObject()
return
}
stringCompare.SetString(*value)
stringMatch18 := stringCompare.ContentsEqual(*credentials.StringOf("source_identity"),true)
if stringMatch18 != true {
fmt.Println("Unexpected returned source identity.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
session.DisposeJsonObject()
return
}
fmt.Println("Example completed.")
stringCompare.DisposeStringBuilder()
credentials.DisposeJsonObject()
expires.DisposeCkDateTime()
now.DisposeCkDateTime()
identifier.DisposeStringBuilder()
allowed.DisposeStringBuilder()
endpoint.DisposeStringBuilder()
aws.DisposeAuthAws()
rest.DisposeRest()
connection.DisposeSocket()
xml.DisposeXml()
session.DisposeJsonObject()