Open marvin-w opened 4 years ago
@marvin-w
Please add Access-Control-Allow-Credentials: true
to your ingress configuration. I assume this is the reason why CORS is not working for you as expected.
@Jotschi Thanks for the fast response. I added the header but unfortunately it still does not work. I do get the same error. I added the frontend code that triggers the login below. I had that exact same code for another project and it was working there (but both projects were hosted on the same host).
login(): Promise<any> {
this.jwtToken = null;
this.apollo.create({
link: this.httpLink.create({uri: `${this.getAPiUrlWithProjectName()}/graphql`}),
cache: new InMemoryCache()
});
return this.http.post(API_URL + 'auth/login', {
username: this.username,
password: this.password
}).toPromise().then((data: any) => this.jwtToken = data.token,
() => Promise.resolve());
}
/**
* Sends a graphQL request to the CMS
*/
graphRequest(data: any): Observable<any> {
return this.apollo.query({
query: data,
context: {
headers: {
Authorization: 'Bearer ' + this.jwtToken
}
}
}).pipe(
map(response => {
return response.data;
})
);
}
Gentics Mesh Version, operating system, or hardware.
Operating System
JVM
Problem
When I try to log in via my angular frontend in order to obtain data via the graphql API I find the following log in my console:
OPTIONS https://cms.xxxxx.de/api/v2/auth/login 404 Access to XMLHttpRequest at 'https://cms.xxxxx.de/api/v2/auth/login' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
When I try to reproduce it locally via curl it also returns the following 404 error:
Expected behaviour and actual behaviour
Expected: OPTIONS request to /v2/api/auth/login returns status code 200 Observed: OPTIONS request to /v2/api/auth/login returns status code 404 Not Found