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!
... View more