1

I see below error when trying to access Jenkins API(https://jenkinsbox:3000/api/json) using angular service with Basic authentication providing in headers.

Error:

Failed to load http://jenkinsbox:30000/api/json?&tree=jobs[name]: Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

httpOptions = {
headers: new HttpHeaders({
'Content-Type':  'application/json',
'Authorization': 'Basic ' + btoa('username:password')
})

getjobslists(): Observable<jobs[]>{
   this.url = "https://jenkinsbox:3000/api/json"
   console.log("getting data..")
   return this.http.get<jobs[]>(this.url + "/api/json?&tree=jobs[name]",this.httpOptions)

    .pipe(map(function(res){
       //console.log(res);
       return res;
    }))
 }

And configured CORS in Jenkins using CORS Support plugin - enter image description here

I think I'm missing something in "Access-Control-Allow-Headers" from Jenkins end. please assist

Suraj Nerati
  • 99
  • 1
  • 8

1 Answers1

3

I think you need to allow Authorization header also. So add Authorization into Access-control-Allow-Headers

Kushan Sameera
  • 169
  • 1
  • 1
  • 9