At least for the attributes of the currently logged in user there is an approach that does not require Graph API. When you configure your sign_in and sign_up policies you can configure what claims are returned back via the token after a successful authentication.
Note that this approach applies only for the currently logged in user. If you need information about other users you should use the graphAPI.
Essentially in your application you could retrieve those claims/attributes from the current ClaimsPrincipal
object.
For example, here is a class, which I use in a current application and allows me to access all required information for the user. There is even a custom user attribute (phone_number):
public class ApplicationUser : IApplicationUser
{
private readonly IHttpContextAccessor contextAccessor;
public ApplicationUser(IHttpContextAccessor contextAccessor)
{
this.contextAccessor = contextAccessor;
}
public virtual bool IsAuthenticated => contextAccessor.HttpContext?.User?.Identity.IsAuthenticated ?? false;
public string Id => GetAttribute(ClaimTypes.NameIdentifier);
public string GivenName => GetAttribute(ClaimTypes.GivenName);
public string Surname => GetAttribute(ClaimTypes.Surname);
public string DisplayName => GetAttribute("name");
public bool IsNewUser => GetBoolAttribute("newUser");
public string Email => GetAttribute("emails");
public string PhoneNumber => GetAttribute("extension_PhoneNumber");
public bool IsCurrentUser(string userId)
{
return userId != null && Id != null && userId.Equals(Id, StringComparison.CurrentCultureIgnoreCase);
}
private string GetAttribute(string claim)
{
return IsAuthenticated ? contextAccessor.HttpContext.User.GetClaim(claim) : null;
}
public bool GetBoolAttribute(string claim)
{
bool output;
bool.TryParse(GetAttribute(claim), out output);
return output;
}
}
public static class ClaimsPrincipalExtensions
{
public static string GetClaim(this ClaimsPrincipal principal, string claim)
{
if (principal == null)
{
throw new ArgumentNullException(nameof(principal));
}
if (string.IsNullOrWhiteSpace(claim))
{
throw new ArgumentNullException(nameof(claim));
}
return principal.FindFirst(claim)?.Value;
}
}
The interface allows me to inject it wherever I need it:
public interface IApplicationUser
{
string Id { get; }
string GivenName { get; }
string Surname { get; }
string DisplayName { get; }
bool IsNewUser { get; }
string Email { get; }
string PhoneNumber { get; }
bool IsCurrentUser(string userId);
}
Edit: You could easily transfer this information to the client by creating a rest api endpoint and call it with ajax. Or pass it with data attributes in html.