User Context
The User Context represents the identity of the authenticated user of the application. The User Context can be used by Analytics SDK providers such as the IRVDashboardProvider
, IRVAuthenticationProvider
, IRVDataProvider
and others to restrict what permissions the user has.
The user context within the Analytics 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 Analytics 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.
string userIdentityName = aspnetContext.User.Identity.Name;
string userId = (userIdentityName != null) ? userIdentityName : "guest";
return new RVUserContext(
userId,
new Dictionary<string, object>() { { "some-property", aspnetContext.Current.Request.Cookies["some-cookie-name"].Value } });
}
}
Step 2 - Register the user context provider with the Analytics SDK.