I have an angulat http interceptor that is trying to add Authorization headers to a request but when the code run the resulting request is not what I expect, the method is changed from POST to OPTIONS and I get an error like this :
Access to XMLHttpRequest at 'http://localhost/authorization/oauth/token' 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.
@Injectable()
export class DlkmInterceptor implements HttpInterceptor {
constructor() {
}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (request.url === authConfig.tokenEndpoint && request.method === 'POST') {
let authData = window.btoa(authConfig.clientId + ':' + authConfig.dummyClientSecret);
request = request.clone({
setHeaders: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + authData
}
});
return next.handle(request);
} else {
request = request.clone({});
return next.handle(request)
}
}
}