varssoCreds = this.LoadSsoCredentials("Profile1");
vartoken = newAmazonSecurityTokenServiceClient(ssoCreds);
varcaller = await token.GetCallerIdentityAsync(newGetCallerIdentityRequest());
this.userId = caller?.UserId.Substring(caller.UserId.IndexOf(":") + 1) ?? string.Empty;
varuserNames = awaitthis.GetIamUserNamesAsync(ssoCreds);
varbucketNames = awaitthis.GetS3BucketNames(ssoCreds);
privateAWSCredentialsLoadSsoCredentials(stringprofile)
{
varchain = newCredentialProfileStoreChain();
if (!chain.TryGetAWSCredentials(profile, outvarcredentials))
{
errors.Add($"Failed to find the {profile} profile");
}
// set ClientName and launch a browser window that prompts the SSO user to complete an SSO login// if the session doesn't already have a valid SSO token.if (credentials is SSOAWSCredentials ssoCredentials)
{
ssoCredentials.Options.ClientName = "Example-SSO-App";
ssoCredentials.Options.SsoVerificationCallback = args =>
{
Process.Start(newProcessStartInfo
{
FileName = args.VerificationUriComplete,
UseShellExecute = true
});
};
}
return credentials;
}
privateasyncTask<IReadOnlyCollection<string>> GetIamUserNamesAsync(AWSCredentialsssoCreds)
{
variamClient = newAmazonIdentityManagementServiceClient(ssoCreds);
varlistResponse = await iamClient.ListUsersAsync();
return listResponse.Users.Select(x => x.UserName).ToList();
}
privateasyncTask<IReadOnlyCollection<string>> GetS3BucketNames(AWSCredentialsssoCreds)
{
vars3Client = newAmazonS3Client(ssoCreds);
// Amazon.Runtime.AmazonClientException: 'No RegionEndpoint or ServiceURL configured// define a default profile in config with a regionvarlistResponse = await s3Client.ListBucketsAsync();
return listResponse.Buckets.Select(x => x.BucketName).ToList();
}
Install the following nuget packages: AWSSDK.CoreAWSSDK.SecurityTokenAWSSDK.SSOAWSSDK.SSOOIDC
For IAM users: AWSSDK.IdentityManagement
For S3 buckets: AWSSDK.S3