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

查看:78
本文介绍了重定向后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.我没有将应用设置为使用hashbang开头,并且不想这样做.

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>

我有一个肮脏的解决方法,就是在将用户发送到google进行身份验证之前,导航至"/",以便google重定向回该位置.如果有一种方法可以告诉Google重定向回何处,那就太好了.有吗?

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

{"Version":"2012-10-17",陈述":[{"Sid":"PublicReadGetObject",效果":允许",主要的": "*","Action":["s3:GetObject"],资源":["arn:aws:s3 :::您的桶名/*"]}]}

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

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