> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.itential.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server.

# Run as another user

> How to use the pronghorn.sudo function to execute methods under the permissions of a different user.

The Pronghorn class has a function called `sudo` that provides the ability to run a given method using the permissions of a different user. This is an asynchronous function and can only be used to call asynchronous functions.

## Access the Pronghorn class

Itential Platform instantiates the Pronghorn class on startup and exposes it as the global `pronghorn` object. Applications and adapters may reference it directly.

## `sudo` arguments

The `sudo` method takes three arguments:

| Argument   | Description                                                                                                                                                                                                                                                                                                              |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `userData` | A JavaScript object that varies based on the implementation of your installed AAA adapter. This value should match the object passed to the login API.                                                                                                                                                                   |
| `action`   | A JavaScript object representing the method to be called. It contains three keys: `service` (a string — the unique name of the application or adapter where the method resides), `method` (a string — the name of the method), and `parameters` (an array of parameters passed to the function, excluding the callback). |
| `callback` | A callback method called with the result of the executed method.                                                                                                                                                                                                                                                         |

## Example implementation

```javascript
// Standard user object used for authentication
// We will become the user named test
const user = {
    "username": "test",
    "password": "test"
}

// Call to getDevice on an adapter named 'myDeviceAdapter' to get a device named 'ATL0'
// Note: even though getDevice expects a callback, it is omitted here
const action = {
  service: 'myDeviceAdapter',
  method: 'getDevice',
  parameters: [
    'ATL0'
  ]
}

// Call the sudo function and provide the callback here
pronghorn.sudo(user, action, (result, err) => {
  if (err) {
    return console.error(null, err)
  }
  return console.log(result);
});
```

## Auditing

When `sudo` is used, a new session is created in addition to the one calling `sudo`. The executed method runs under that new session. Since there are two different sessions, there are two separate audit trails. Both the session that called `sudo` and the `sudo` session itself are automatically flagged for audit serialization.