简体   繁体   中英

AWS CloudFront set cookie for different hosts (frontend and backend)

I am create CI/CD using bitbucket and AWS. On the AWS frontend stored in the S3 bucket, backend - EC2 + ElasticBeanstalk. I want to use free SSL, that is why I wrapped them using CloudFront. Right now I can see all content which displayed for non-auth users. I made auth using COOKIE, I mean I set COOKIE attribute and check it on backend and frontend for give an access to the user dashboard. Frontend and backend using different CF routes. That is why I am trying configure CORS. For S3 bucket I set next CORS configuration:

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": []
    }
]

my backend is using next CORS configuration (this is an example from express app)

{
            allowedHeaders: [
                'Origin',
                'X-Requested-With',
                'Content-Type',
                'Accept',
                'X-Access-Token',
                'Access-Control-Allow-Methods'
            ],
            credentials: true,
            methods: 'GET,HEAD,OPTIONS,PUT,PATCH,POST,DELETE',
            origin: true,
            preflightContinue: false,
        }

The question is, when I try to make auth COOKIE is not set for frontend. I see request to backend with correct COOKIES, but browser doesn't set COOKIE that is why frontend part close access to user dashboard. How to set COOKIE for browser? UI host and backend host is different.

PS If I missed any useful information - let me know and I will update this question.

我找到了解决方案 - 前端和后端使用一台主机,现在它对我有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM