Splunk Dev

Using Session Credentials in a Splunk React App

sanjai
Path Finder

Hi Splunkers,

I’m new to React development and currently working on a React app that handles creating, updating, cloning, and deleting users for a specific Splunk app. The app is working well, but for development purposes, I’ve hardcoded the REST API URL, username, and password. Now, I want to enhance the app so it dynamically uses the current session’s user authentication rather than relying on hardcoded credentials.

Here’s the idea I’m aiming for:

When a user (e.g., "user1" with admin roles) logs into Splunk, their session credentials (like session key or authentication token) are stored somewhere, right? I need to capture those credentials in my React app. Does this approach make sense?

I’m looking for advice on how to retrieve and use the session credentials, token, or session key for the logged-in user in my "User Management" React app.

Here’s the current code I’m using to fetch all users (with hardcoded credentials):

 

// Fetch user data from the API
const fetchAllUsers = async () => {
try {
const response = await axios.get('https://localhost:8089/services/authentication/users', {
auth: { username: 'admin', password: 'changeme' },
headers: { 'Content-Type': 'application/xml' }
});
// Handle response
} catch (error) {
console.error('Error fetching users:', error);
}
};

I also tried retrieving the session key using this cURL command:


curl -k https://localhost:8089/services/auth/login --data-urlencode username=admin --data-urlencode password=changeme

However, I’m still hardcoding the username and password, which isn’t ideal.

My goal is for the React app to automatically use the logged-in user’s session credentials (session key or authentication token) and retrieve the hostname of the deployed environment.

Additionally, I’m interested in understanding how core Splunk user management operates and handles authorizations. My current approach might be off, so I’m open to learning the right way to do this.

Can anyone guide me on how to achieve this in the "User Management" React app? Any advice or best practices would be greatly appreciated!

Thanks in advance!

Labels (1)
0 Karma

LukeMurphey
Champion

I have done many Splunk React apps (Enterprise Security, Mission Control, etc.). In my experience, the easiest way is to embed your React code in an app. One of the clearest ways to do this is to follow the instructions provided in the Splunk UI library.

It can be somewhat daunting at first to use Splunk UI and it's build scripting, but so many things will just work once you have your React code packaged in app. Authentication won't be an issue at all for you anymore and you can easily call Splunk endpoints and they will just work.

Get Updates on the Splunk Community!

New This Month - Splunk Observability updates and improvements for faster ...

What’s New? This month, we’re delivering several enhancements across Splunk Observability Cloud for faster and ...

What's New in Splunk Cloud Platform 9.3.2411?

Hey Splunky People! We are excited to share the latest updates in Splunk Cloud Platform 9.3.2411. This release ...

Buttercup Games: Further Dashboarding Techniques (Part 6)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...