Hi,
I start to test Identity with web api in .net core. I done a method that get the current user, but I obtain a bad request because this User.Identity.IsAuthenticated is always false.
I don't undestand because. The token hascorrectlybeencreated.
I call the web api with Angular 2 .
public async Task<string> GetCurrentUserId()
{
// if the user is not authenticated, throw an exception
if (!User.Identity.IsAuthenticated)
throw new NotSupportedException();
var info = await SignInManager.GetExternalLoginInfoAsync();
if (info == null)
// internal provider
return User.FindFirst(ClaimTypes.NameIdentifier).Value;
else
{
// external provider
var user = await UserManager.FindByLoginAsync(
info.LoginProvider,
info.ProviderKey);
if (user == null) throw new NotSupportedException();
return user.Id;
}
}
someone can help me?
BR