Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

User.Identity.IsAuthenticated always false

$
0
0

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


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>