Getting the user in code
Server-side code
In server-side code, the IUserInfoAccessor
interface must be injected :
/// <summary>
/// Represents the implementation of the <see cref="IMyServerMethod"/> interface.
/// </summary>
public class MyServerMethod : IMyServerMethod
{
private readonly IUserInfoAccessor _userInfoAccessor;
/// <summary>
/// Initializes a new instance of the <see cref="MyServerMethod"/> interface.
/// </summary>
/// <param name="userInfoAccessor">User info accessor.</param>
public MyServerMethod(IUserInfoAccessor userInfoAccessor)
{
_userInfoAccessor = userInfoAccessor;
}
/// <inheritdoc/>
public void Execute()
{
string userIdentifier = _userInfoAccessor.User!.Identifier;
string? userEmail = _userInfoAccessor.User!.Email;
// ...
}
}
Client-side code
In client-side code, the identifier and the email of the user are accessible from the application context :
string userIdentifier = ApplicationContext.GetValue<string>("UserIdentifier");
string userEmail = ApplicationContext.GetValue<string>("UserEmail");