Getting Data In

How do I enable CORS in Splunk Enterprise ?

Nagarajv
Explorer

I was trying to build application outside the Splunk web interface using Splunk REST APIs and Angular 6 I Got**CORS rejection error

REST API ( I used 😞 https://localhost:8089/services/auth/login

result:
alt text
*angular Code : *

  login(data) {
    const body = new URLSearchParams();
    body.set('username', data.username);
    body.set('password', data.password);
    body.set('output_mode', 'json');
    const options = {
      headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
  };
  console.log(body.toString());

      this.http.post('https://localhost:8089/services/auth/login', body.toString(), options).subscribe(
        (resData) => {
          console.log(resData);
        },
        (err) => {
          console.log(err);
        }
      );
    console.log(data);
    }

but it is working fine with Post man

Then I tried Changing server.conf
alt text

0 Karma

rmjharris
Path Finder

If you have admin access to the Splunk server that will receive the requests there is a setting for this in server.conf.

[httpServer]
crossOriginSharingPolicy =

If the intent here is to build an application that will connect to any Splunk instance with a username and password then it is a matter of following the CORS protocol and using an API container.

kamlesh_vaghela
SplunkTrust
SplunkTrust

@Nagarajv

Have you tried to connect Splunk using SplunkJavascript SDK?

http://dev.splunk.com/view/javascript-sdk/SP-CAAAEDD

0 Karma

Nagarajv
Explorer

ya @kamlesh_vaghela , i tried with splunk-sdk(JS) in node Js and it is working good.

but now i'm using ReST API's of Splunk and i'm getting CORSS rejection Error

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...