This issue is similar to a question about setting cookies as well as various other questions on the Internet, but none of them actually have solutions.
Cordova CLI: 6.5.0
Ionic Framework Version: 2.3.0
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.1.4
ios-deploy version: 1.9.1
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v7.9.0
Xcode version: Xcode 8.2.1 Build version 8C1002
I am logging into an API that I have no control over. This responds with session cookies using the set-cookie
header. Preflight options respond appropriately and this works when using ionic serve
.
However, when running the app in an emulator, it seems like the http service makes no attempt to use cookies from the response. I have tried various things, including:
login(credentials: any) {
this.http.post("http://api.com/login", credentials, {withCredentials: true});
}
getProfile() {
this.http.get("http://api.com/profile", {withCredentials: true});
}
The login request responds with Set-Cookie
headers and these do seem to work properly in the browser, but they are not sent for http requests when running the app on a simulator or device even when I try to use withCredentials
.