The userName claim is not set through steam. Fallback to id as username for now

This commit is contained in:
Mark Ettema 2021-05-13 12:05:27 +07:00
parent f14bf5e6e2
commit 425d7d1d85

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -63,6 +64,16 @@ namespace SteamOpenIdConnectProvider.Controllers
var userName = info.Principal.FindFirstValue(ClaimTypes.Name); var userName = info.Principal.FindFirstValue(ClaimTypes.Name);
var userId = info.Principal.FindFirstValue(ClaimTypes.NameIdentifier); var userId = info.Principal.FindFirstValue(ClaimTypes.NameIdentifier);
if (string.IsNullOrEmpty(userId))
{
throw new ArgumentNullException(nameof(userId), $"No claim found for {ClaimTypes.NameIdentifier}");
}
if (string.IsNullOrEmpty(userName))
{
userName = userId.Split('/').Last();
}
var user = new IdentityUser { UserName = userName, Id = userId }; var user = new IdentityUser { UserName = userName, Id = userId };
_userManager.UserValidators.Clear(); _userManager.UserValidators.Clear();