Skip to content

Instantly share code, notes, and snippets.

@stomita
Last active January 28, 2023 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stomita/8110073 to your computer and use it in GitHub Desktop.
Save stomita/8110073 to your computer and use it in GitHub Desktop.
List S3 files in a bucket, using AWS JavaScript SDK with SAML assertion
<apex:page showHeader="false"
standardStylesheets="false"
sidebar="false"
contentType="text/html"
applyBodyTag="false"
applyHtmlTag="false"
cache="true"
docType="html-5.0">
<html>
<head>
<script src="//sdk.amazonaws.com/js/aws-sdk-2.0.0-rc4.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var bucketName = 'salesforce-bucket';
var bucket;
$(function() {
var assertion = $('#samlResponse').val();
if (!assertion) {
throw Error("No assertion is given to this page. Please access from app menu.");
}
AWS.config.credentials = new AWS.SAMLCredentials({
RoleArn: 'arn:aws:iam::119301928242:role/SalesforceUserRole',
PrincipalArn: 'arn:aws:iam::119301928242:saml-provider/SalesforceIdP',
SAMLAssertion: assertion
});
bucket = new AWS.S3({ params: { Bucket: bucketName } });
bucket.listObjects({}, function(err, resp) {
if (err) { throw err; }
$('#fileList').empty();
$.each(resp.Contents, function(i, content) {
$('<li>').text(content.Key).appendTo($('#fileList'));
});
});
});
</script>
</head>
<body>
<input type="hidden" id="samlResponse" value="{!$CurrentPage.parameters.SAMLResponse}" />
<ul id="fileList"></ul>
</body>
</html>
</apex:page>
@cybergavin
Copy link

Thank you. This code helped me fix an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment