简体   繁体   English

使用AWS S3 Javascript SDK加载新网页

[英]Loading New Webpage Using AWS S3 Javascript SDK

I'm new to webdev so forgive me if this is an obvious one, but I can't wrap my head around a solution. 我是webdev的新手,所以如果这是显而易见的事情,请原谅我,但是我无法解决问题。

I'm currently hosting a static website on AWS S3. 我目前在AWS S3上托管一个静态网站。 The login page is available for public access, but all other pages are only available to a specific IAM role that an authorized user will assume. 登录页面可用于公共访问,但是所有其他页面仅可用于授权用户将承担的特定IAM角色。 Once a user enters their login credentials they will receive temporary AWS credentials that grant them access to restricted pages. 用户输入登录凭证后,他们将收到临时的AWS凭证,这些凭证将授予他们对受限页面的访问权限。

My question is: how do I programmatically load a restricted webpage? 我的问题是:如何以编程方式加载受限制的网页? Normally I would do something like: 通常我会做类似的事情:

$('body').load(/path/to/index.html);

But the /path/to/index.html is only accessible to users with the IAM role. 但是/path/to/index.html仅具有IAM角色的用户可以访问。 So do I need to use the S3 sdk to access that file? 那我需要使用S3 SDK来访问该文件吗? In my head I would need to do something like: 在我的脑海中,我需要做一些类似的事情:

$('body').load(s3.getObject(/path/to/index.html));

But that wouldn't actually work. 但这实际上是行不通的。

Thanks for the help! 谢谢您的帮助!

Do not put the page (HTML) itself as secret. 不要将页面(HTML)本身作为机密。 Instead, put your essential data into a json file, and do a XHR to it. 相反,将您的基本数据放入json文件,并对它执行XHR。

Using a frontend framework with router, you can check if the user is authenticated and render a 403 if not. 使用带有路由器的前端框架,您可以检查用户是否已通过身份验证,如果未通过,则呈现403。

The method depends on your framework, and I'm not going to describe it. 该方法取决于您的框架,在此不再赘述。 You can use AWS SDK to fetch from S3 with authentication. 您可以使用AWS开发工具包从S3进行身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用AWS SDK for JavaScript访问AWS S3 - Accessing AWS S3 using AWS SDK for JavaScript 使用纯 Javascript(无 SDK)对 AWS S3 进行 REST 调用 - Making REST calls to AWS S3 using Pure Javascript (No SDK) 使用浏览器JavaScript SDK检查AWS S3上是否存在文件? - Check if File Exists on AWS S3 Using Browser JavaScript SDK? 使用JavaScript SDK的AWS S3:未经身份验证的公共用户的listObjects - AWS S3 using JavaScript SDK: listObjects for unauthenticated, public users 使用Javascript AWS开发工具包将使用Cordova Media Capture插件捕获的视频上传到S3 - Uploading to S3 a video captured using Cordova Media Capture plugin using Javascript AWS SDK 使用nodejs aws sdk 将生成的pdf上传到AWS S3 - Upload pdf generated to AWS S3 using nodejs aws sdk 如何使用amazon-javascript-sdk列出AWS S3存储桶? - How to list AWS S3 buckets using amazon-javascript-sdk? 使用JavaScript SDK从AWS s3存储桶中获取getObject:“缺少凭证”错误 - getObject from AWS s3 bucket using Javascript SDK: “missing credential” error AWS javascript SDK无法使用STS凭证上传到s3 - AWS javascript sdk can't upload to s3 using STS credentials 使用 AWS-SDK-JS 使用普通 Javascript 将大文件作为流上传到 s3 - Upload large files as a stream to s3 with Plain Javascript using AWS-SDK-JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM