When doing server-to-server API integrations, you may want to make API calls on behalf of another user. In Higher Logic Vanilla (Vanilla), you can achieve this by spoofing another user. In this article, you'll learn how.
What API calls can you spoof?
You can spoof any APIv2 call you want, as long as the user you're spoofing has access to the endpoint.
Pitfalls of spoofing
Before you decide to use the spoofing functionality, make sure you understand the pitfalls.
- Spoofing is a very powerful tool, but can be dangerous too because you're allowing access to other user accounts. Make sure you really need to spoof.
- Don't use spoofing as a workaround for SSO. Think of spoofing as a tool for administrators or server integrations such as automated posts on behalf of users.
- When you spoof as another user, the call will be as that user. This is especially important when it comes to that user's permissions. In other words, you can only make API calls that the spoofed user can make, based on their permissions.
Enable API spoofing
API spoofing requires the Spoof addon to be enabled. You can enable it in the Dashboard, on the Settings > Addons > Addons page.
In order to spoof, you must make API calls with an access token that has admin access (
Garden > Settings > Manage). Make sure you have an access token associated with a user that has the proper permissions.
Make spoof calls
In order to spoof when making an API call, you pass the user ID of the user you want to spoof in the
Auhorization: Bearer <Access Token>
These headers will make the API call as user "123" rather than the user who owns the access token.
Spoofing With Smart IDs
The example above shows an integer user ID. While this works, it can sometimes be difficult to develop with because you have to look up users before spoofing as them. To get around this, you can use Vanilla's Smart IDs to spoof users by name, email address, or SSO ID.
// Spoof as username "frank"
// Spoof with SAML SSOID
You can look up a user when spoofing with any valid smart ID. For more information on smart IDs, check out the Smart ID documentation.