[英]AWS Cognito JS how to allow access to s3 object (a specific html page)
I have 3 html files in an s3 hosted website, a register.html, login.html and a dashboard.html 我在s3托管网站中有3个html文件,一个register.html,login.html和dashboard.html
The registration and logging in work and I end up with an an access token. 注册和登录工作最终得到一个访问令牌。
How do I restrict access to the dashboard.html then somehow use the access token to allow access to it? 如何限制对dashboard.html的访问,然后以某种方式使用访问令牌来允许对其进行访问?
Using JavaScript without Restricting Access 使用JavaScript而不限制访问
For this kind of a problem, a straight forward approach is to load the dashboard.html and have a JavaScript in dashboard.html body to toggle the display of content by verifying if the user is already logged in or not (eg, Checking a Cognito JWT token in LocalStorage) and redirect to login.html for unauthenticated users. 对于此类问题,直接的方法是加载dashboard.html,并在dashboard.html主体中具有JavaScript,以通过验证用户是否已经登录(例如,检查Cognito)来切换内容的显示。本地存储中的JWT令牌),并重定向到未经身份验证的用户登录到login.html。
Note: This approach will be also useful if you plan to use AWS Cognito UserPools Hosted UI. 注意:如果您计划使用AWS Cognito UserPools托管UI,此方法也将很有用。
Restricting Access 限制访问
If you plan to go ahead with restricting access to dashboard.html you can use CloudFront Signed Cookies to achieve it as follows. 如果您打算继续限制对dashboard.html的访问,则可以使用CloudFront Signed Cookies来实现它,如下所示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.