Skip to main content

User Context

The User Context represents the identity of the authenticated user of the application. The User Context can be used by Reveal SDK providers such as the IRVDashboardProvider, IRVAuthenticationProvider, IRVDataProvider and others to restrict what permissions the user has.

The user context within the Reveal SDK is represented by the IRVUserContext interface and the RVUserContext object. The RVUserContext is a default implementation of IRVUserContext, which provides the ability to store the user id of the current user. The RVUserContext object also provides the ability to store additional properties related to a request to be used in other areas of the Reveal SDK such as the authentication provider.

Step 1 - Create the user context provider

internal class UserContextProvider : IRVUserContextProvider
{
public IRVUserContext GetUserContext(HttpContext aspnetContext)
{
//when using standard auth mechanisms, the userId can be obtained using aspnetContext.User.Identity.Name.
var userIdentityName = aspnetContext.User.Identity.Name;
var userId = (userIdentityName != null) ? userIdentityName : "guest";

var props = new Dictionary<string, object>() { { "some-property", aspnetContext.Current.Request.Cookies["some-cookie-name"].Value } };

return new RVUserContext(userId, props);
}
}

Step 2 - Register the user context provider with the Reveal SDK.

builder.Services.AddControllers().AddReveal( builder =>
{
builder.AddUserContextProvider<UserContextProvider>();
});