S3 上的 Angular 4 应用程序在重定向后拒绝访问 [英] Angular 4 app on S3 denied access after redirect

查看:17
本文介绍了S3 上的 Angular 4 应用程序在重定向后拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个简单的 angular 4 应用程序,它使用 firebase 作为我的身份验证.我使用 loginWithRedirect 因为 loginWithPopup 在我的手机上并没有真正工作.

I've built a simple angular 4 app that uses firebase as my authentication. And I use loginWithRedirect because loginWithPopup didn't work really on my cell phone.

但我遇到的问题是重定向离开页面,显然,进行身份验证,然后返回到 mysite.com/login 但因为它是 SPA /login 不存在于我猜的桶中.

But the problem I'm running into is the redirect leaves the page, obviously, to authenticate, and then comes back to mysite.com/login but because its a SPA /login doesn't exist to the bucket I'm guessing.

我已经添加了这个重定向规则,但它似乎没有做任何事情

I've added this redirection rule, but it doesn't seem to be doing anything

<RoutingRules>
  <RoutingRule>
    <Condition>
      <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>
      <HostName>mysite.cloudfront.net</HostName>
      <ReplaceKeyPrefixWith>#!/</ReplaceKeyPrefixWith>
    </Redirect>
  </RoutingRule>
  <RoutingRule>
    <Condition>
      <HttpErrorCodeReturnedEquals>403</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>
      <HostName>mysite.cloudfront.net</HostName>
      <ReplaceKeyPrefixWith>#!/</ReplaceKeyPrefixWith>
    </Redirect>
  </RoutingRule>
</RoutingRules>

我在 403 上重定向也是因为那是我不断收到的错误.然后我添加了 <script>history.pushState({}, "进入页面", location.hash.substring(1));</script> 到我的 index.html 文件的顶部(来自另一个 stackoverflow 问题的解决方案).

I'm redirecting on 403 also because thats the error I keep getting. Then I've added <script> history.pushState({}, "entry page", location.hash.substring(1)); </script> to the top of my index.html file (solution from another stackoverflow question).

但仍然收到 403.我没有将应用设置为使用 hashbangs 开始,我不想这样做.

But still getting the 403. I don't have the app set up to use hashbangs to begin with and would like to not have to.

我收到的错误信息:

<Error>
    <Code>AccessDenied</Code>
    <Message>Access Denied</Message>
    <RequestId>0D98B2536B28C06D</RequestId>
    <HostId>8nhnAtzaLxPvWcV3f8zqc=</HostId>
</Error>

我有一个肮脏的修复是在将用户发送到谷歌进行身份验证之前,导航到/",以便谷歌重定向回.如果有办法告诉谷歌重定向回哪里就好了.有吗?

A dirty fix I have is to just right before sending the user to google to authenticate, navigate to '/' so thats where google redirects back to. It'd be nice if there was a way to tell google where to redirect back to. Is there?

推荐答案

我们需要在本文档中提到的权限 > 存储桶策略中添加读取访问策略.试试看

We need add the read access policy in the permissions > bucket policy as mentioned in this documentation. Give it a try

http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html

<代码>{"版本":"2012-10-17",陈述":[{"Sid":"PublicReadGetObject","Effect":"允许",主要的": "*","动作":["s3:GetObject"],"资源":["arn:aws:s3:::YOUR-BUCKET-NAME/*"]}]}

这篇关于S3 上的 Angular 4 应用程序在重定向后拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆