Sync user profile (incl. picture) from token claims on validation
This commit is contained in:
@@ -25,16 +25,17 @@ public sealed class JwtBearerEventsHandler(IMediator mediator, ILogger<JwtBearer
|
|||||||
|
|
||||||
var firstName = principal.FindFirstValue(ClaimTypes.GivenName);
|
var firstName = principal.FindFirstValue(ClaimTypes.GivenName);
|
||||||
var lastName = principal.FindFirstValue(ClaimTypes.Surname);
|
var lastName = principal.FindFirstValue(ClaimTypes.Surname);
|
||||||
|
var profilePictureUrl = principal.FindFirstValue("picture");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await mediator.Send(
|
await mediator.Send(
|
||||||
new CreateUserCommand(userId, username, firstName, lastName),
|
new SyncUserCommand(userId, username, firstName, lastName, profilePictureUrl),
|
||||||
tokenValidatedContext.HttpContext.RequestAborted);
|
tokenValidatedContext.HttpContext.RequestAborted);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
logger.LogError(exception, "Failed to provision user {UserId} during token validation", userId);
|
logger.LogError(exception, "Failed to sync user {UserId} during token validation", userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user