expressappframework-403358-data-security-and-safety-security-system-security-object-model-assign-an-image-to-a-user.md
This topic describes how to assign an avatar or icon to an application user. ASP.NET Core Blazor applications display this image in the top right corner of an application page.
You can pass the name of a property that stores a user image to the CurrentUserDisplayImage attribute to display this image in the application toolbar.
Follow the steps below to extend a user class with a property that stores a user image:
MediaDataObject (XPO/EF Core), Image, or byte[] type.CurrentUserDisplayImageAttribute to the user class and pass the new property name as its parameter.In ASP.NET Core Blazor applications with OAuth authentication, you can add a claim of the XafClaimTypes.UserImageUrl type to read a user image on sign in. The following example configures the Google authentication provider and creates the XafClaimTypes.UserImageUrl claim from the picture key in Google user data:
File : MySolution.Blazor.Server\Startup.cs.
using DevExpress.ExpressApp.Security;
using Microsoft.AspNetCore.Authentication.OAuth;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.DependencyInjection;
// ...
public class Startup {
// ...
public void ConfigureServices(IServiceCollection services) {
// ...
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options => options.LoginPath = "/LoginPage")
.AddGoogle(options => {
// ...
options.ClaimActions.MapJsonKey(XafClaimTypes.UserImageUrl, "picture");
});
}
}
You can register a service that implements the IUserProfileInfoProviderAsync interface to specify a custom user image and name. Follow the steps below to implement this technique in your application:
In the ASP.NET Core Blazor application project, create a new class that implements the IUserProfileInfoProviderAsync interface:
Add this scoped service to your ASP.NET Core Blazor application service collection: