Postman set-cookie not working with the domain
Asked Answered
S

4

8

I want to controll authentication with cookies. And In my browser working successfully. But When I tried to test with postman, Postman doesn't add cookie to new request.

  1. step - I login and response header like that:

enter image description here

But the response cookies tab like that:

enter image description here

And manage cookies window like that:

enter image description here

  1. step - I send a request to unprotected router and I get unauthorized error.

This error started today. I don't remember making any changes to the settings. Why Im getting this type error. How can I solve this?

Santoyo answered 29/7, 2021 at 10:8 Comment(2)
did you get any solution for this issue?Patrilineage
Same question here. My server try to set cookies with "set-cookie" header. I turned on nginx to "xxx.lan" but the problem still here. Hope someone write a solution here.Berhley
G
3

I also had this problem, the fix is to remove the secure flag in the cookie when sending cookies from localhost as cookies set as secure can only be sent over HTTPS.

Glennaglennie answered 10/6, 2022 at 13:8 Comment(0)
T
1

I had this issue when testing a local Laravel Sanctum request to /login.

I had the following .env values set

SESSION_DOMAIN=docker-api-service-name
SANCTUM_STATEFUL_DOMAINS=docker-api-service-name

However these needed to be set to localhost to match the domain of the APP_URL. After this, everything was working fine.

SESSION_DOMAIN=localhost
SANCTUM_STATEFUL_DOMAINS=localhost
Tyne answered 7/10, 2022 at 7:58 Comment(0)
T
0

Someone mentioned that setting the secure flag to false will solve it, and it will. The explanation however was not entirely correct.

Secure will indeed only work over secure connections (HTTPS). However, it will also work over HTTP if it's done in localhost: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies

Tweedsmuir answered 19/2, 2023 at 14:42 Comment(1)
Can you edit the existing Answer, or provide a comment on it?Binny
Q
0

Setup your domain name inside the .env file

if you are on localhost add below

SESSION_DOMAIN=localhost

for custom domain (my domain name is qa_app.test)

SESSION_DOMAIN=qa_app.test

Note: if you are sending a request on an authenticated route where you are using Sanctum or passport middleware using Postman you need to use pass Referer.

Referer=localhost

it's identical for localhost or custom domain, in both conditions you need to pass localhost in the referer.

When you are in the web browser you don't need to pass the referer, it will be passed by web browser.

Quirita answered 18/5, 2023 at 2:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.