What is the difference between UsersContext and AuthenticationContext?

In Dss.Api.Examples.Authentication.AuthorizationExamples both are used to get session token. Are there any recommendations when to use which?

Best Answer

  • Hello @ihor.fedoryshyn ,

    If you require to authenticate, both AuthenticationContext and UsersContext work, and you can:

    var authenticationContext = ContextHelper.CreateAuthenticationContext(false);
    Status.Notify(authenticationContext, null, "RequestToken", MethodType.Operation, Publish.Secondary
    var sessionToken = authenticationContext.SessionToken;

    UsersContext additionally it includes User preferences handling capabilities:

       [GeneratedCode("Microsoft.OData.Client.Design.T4", "1.0.0")]
    public IDssQueryable<UserClaim> UserClaims { get; }
    [GeneratedCode("Microsoft.OData.Client.Design.T4", "1.0.0")]
    public IDssQueryable<UserPreference> UserPreferences { get; }
    [GeneratedCode("Microsoft.OData.Client.Design.T4", "1.0.0")]
    public IDssQueryable<User> Users { get; }
    public IUserClaimOperations UserClaimOperations { get; }
    public IUserClaimOperationsAsync UserClaimOperationsAsync { get; }
    public IUserPreferenceOperations UserPreferenceOperations { get; }
    public IUserPreferenceOperationsAsync UserPreferenceOperationsAsync { get; }
    public IUserOperations UserOperations { get; }
    public IUserOperationsAsync UserOperationsAsync { get; }

    For example:

    var UsersContext = new UsersContext(new Uri("https://selectapi.datascope.refinitiv.com/RestApi/v1/"), "<your user id>", "<your password>");

    //Fetch the user preferences
    var userPreferences = UsersContext.UserPreferenceOperations.GetAll().First();

    //Make changes
    userPreferences.ContentSettings.PartialEmbargoedReportsEnabled = false;
    UsersContext.UserPreferenceOperations.Update(userPreferences);

    For illustrative examples of usage, see Refinitiv DSS C# Example Application -> section "User Examples",