I am using Flask, flask-jwt-extended, and React-native (with Expo) for a mobile application. When I use web-browser simulation or Postman, all my cookies are setup correctly. However, when I use the ios simulator from Xcode, none of the cookies are stored.
Environment:
Flask Backend: 127.0.0.1:5000
React-Native Front: 127.0.0.1:19006
Here is my Flask config:
JWT_SECRET_KEY = os.getenv("JWT_SECRET_KEY", 'local-secret')
JWT_TOKEN_LOCATION = ['cookies']
JWT_ACCESS_TOKEN_EXPIRES = datetime.timedelta(seconds=1800)
JWT_COOKIE_SECURE = False
CORS_HEADERS = "Content-Type"
JWT_REFRESH_TOKEN_EXPIRES = datetime.timedelta(days=15)
JWT_COOKIE_CSRF_PROTECT = True # set_refresh_cookies() will now also set the non-httponly CSRF cookies
JWT_CSRF_CHECK_FORM = True
JWT_ACCESS_CSRF_HEADER_NAME = "X-CSRF-TOKEN-ACCESS"
JWT_REFRESH_CSRF_HEADER_NAME = "X-CSRF-TOKEN-REFRESH"
SSL_REDIRECT = False
jwt = JWTManager()
app = Flask(__name__)
app.config.from_object(APP_CONFIG[CONFIG_ENV])
cors = CORS(app, resources={r"/*": {"origins": "http://127.0.0.1:19006"}}, supports_credentials=True)
APP_CONFIG[CONFIG_ENV].init_app(app)
jwt.init_app(app)
Here is how I store cookies (classic, and working with postman or normal web browser):
access_token = create_access_token(identity = token_identity)
refresh_token = create_refresh_token(identity = token_identity)
resp = jsonify({"access_token": access_token, "refresh_token": refresh_token})
set_access_cookies(resp, access_token)
set_refresh_cookies(resp, refresh_token)
Here is how I make requests with the Fetch lirbary:
let response = await fetch(URL + "/login", {
body: form_data,
method: "post",
credentials: "include",
})
However, whenever I am using the ios Simulator (127.0.0.1:19006) with react-native to make requests, cookies are never stored. Any ideas where the problem can come from?