Return Email in AuthenticateResponse

I’ve got a custom auth provider, and currently it returns a standard AuthenticateResponse. However I need it to return Email as well, the e-mail that’s stored in UserAuth, because I need this in the UI (a SPA).

I’ve looked at Authentication and Authorization but can’t really figure out how to do it. For one there’s no Email field in AuthenticateResponse, I could use UserId for it, but I’d prefer a new field for this.

image

I’ve already set the e-mail in the session but I need to get it in the response somehow.

I think I’ve found a way:

// Intercept successful Authenticate Request DTO requests
public Task ExecuteAsync(AuthFilterContext authContext)
{
    var authRepo = authContext.AuthService.TryResolve<IAuthRepository>();
    var userAuth = authRepo.GetUserAuthByUserName(authContext.AuthResponse.UserName);

    authContext.AuthResponse.Meta ??= [];
    authContext.AuthResponse.Meta.Add("Email", userAuth.Email);
    return Task.CompletedTask;
}
2 Likes