Last active
January 28, 2023 05:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. This code helped me fix an issue.