Click here to Skip to main content
14,364,399 members
   

ASP.NET

 
GeneralRe: what is major difference between blazor server app and asp.net mvc razor app? Pin
jkirkerx13-Nov-19 10:56
professionaljkirkerx13-Nov-19 10:56 
Questiongridview with dynamic dropdownlist control null exception Pin
Anand Solomon11-Nov-19 5:41
memberAnand Solomon11-Nov-19 5:41 
Questionvideo calling in asp.net Pin
Member 146439065-Nov-19 19:37
memberMember 146439065-Nov-19 19:37 
AnswerRe: video calling in asp.net Pin
F-ES Sitecore6-Nov-19 2:04
mveF-ES Sitecore6-Nov-19 2:04 
AnswerRe: video calling in asp.net Pin
Blikkies6-Nov-19 2:28
professionalBlikkies6-Nov-19 2:28 
Questioni want show page numbers in bottom of the page like <1 2 3 4 5.......10 11 12> but it shows <1 2 3 4 5 6 to total> Pin
Member 134445211-Nov-19 21:17
memberMember 134445211-Nov-19 21:17 
AnswerRe: i want show page numbers in bottom of the page like <1 2 3 4 5.......10 11 12> but it shows <1 2 3 4 5 6 to total> Pin
Richard Deeming3-Nov-19 23:33
mveRichard Deeming3-Nov-19 23:33 
QuestionASP.Net Core Identity Pin
Mycroft Holmes28-Oct-19 14:11
memberMycroft Holmes28-Oct-19 14:11 
Using VS2019 with Core 3 I am attempting to secure a web project. Web API does the validation and returns a JWT token with the user authorisation details, role only. Tihs works fine as the JWT decodes with all the correct info in it.

My problem is to get that information into MS Identity (or have I got it completely wrong).

I am NOT using EntityFrameworkCore just to service the user validation.

My login partial has the following.
@if (User.Identity.IsAuthenticated)
{
	<form asp-controller="Account" asp-action="Logout" method="post" id="logoutForm">
		<ul>
			<li>
				<button type="submit">Log out</button>
			</li>
		</ul>
	</form>
}
else
{
	<ul>
		<li><a asp-page="/Login">Log in</a></li>
	</ul>
}


The .cs code
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
    CSDUtil.PWDUtil oUtil = new CSDUtil.PWDUtil();
    try
    {
        ReturnUrl = returnUrl;
        // Verification.
        if (ModelState.IsValid)
        {
            UserDetailsDB data = UserDetails;
            UserDetailsDB oUser = await dsUserDetails.AutenticateAsync(data);
            if (oUser == null)
            {
                ModelState.AddModelError(string.Empty, "Invalid user details.");
                return Page();
            }
            JwtSecurityTokenHandler oHandler = new JwtSecurityTokenHandler();
            var key = Code.MainUI.Key;
            var handler = new JwtSecurityTokenHandler();
            var jwtToken = new JwtSecurityToken(oUser.Token);
            var validations = new TokenValidationParameters
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey = new SymmetricSecurityKey(key),
                ValidateIssuer = false,
                ValidateAudience = false
            };
            ClaimsPrincipal oPrincipal = handler.ValidateToken(oUser.Token, validations, out SecurityToken oToken);
            int i = oPrincipal.Claims.Count();
            var authProperties = new AuthenticationProperties
            {
                AllowRefresh = true,
                ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(60),
                IsPersistent = true,
                IssuedUtc = DateTimeOffset.Now,
                RedirectUri = "/Index"
            };
            await HttpContext.SignInAsync(
                                CookieAuthenticationDefaults.AuthenticationScheme,
                                new ClaimsPrincipal(oPrincipal),
                                authProperties);
            var B = User.Identity.IsAuthenticated;///////this is always false
            return LocalRedirect(Url.GetLocalUrl(returnUrl));
        }
    }


The ClaimsPricipal populates correctly with the details of the user in identities[0] of that collection.

How do I move the user details from the ClaimsPrincipal to the User.Identity?

[Edit]
I have the claims added to User.Identity but IsAuthenticated is still false

ClaimsPrincipal oPrincipal = handler.ValidateToken(oUser.Token, validations, out SecurityToken oToken);

					returnUrl = "/Index";
					ClaimsIdentity identity = User.Identity as ClaimsIdentity;
					foreach (Claim oClaim in oPrincipal.Claims)
					{
						identity.AddClaim(oClaim);
					}					
					var B = User.Identity.IsAuthenticated;//this is always false
					return LocalRedirect(Url.GetLocalUrl(returnUrl));

[/Edit]
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP


modified 28-Oct-19 19:42pm.

AnswerRe: ASP.Net Core Identity Pin
jkirkerx30-Oct-19 14:10
professionaljkirkerx30-Oct-19 14:10 
GeneralRe: ASP.Net Core Identity Pin
Mycroft Holmes31-Oct-19 12:13
memberMycroft Holmes31-Oct-19 12:13 
GeneralRe: ASP.Net Core Identity Pin
jkirkerx1-Nov-19 13:23
professionaljkirkerx1-Nov-19 13:23 
QuestionImporting Rows Into a List Pin
ibrahimayhans28-Oct-19 1:37
memberibrahimayhans28-Oct-19 1:37 
QuestionASP maker 2018 Pin
Member 1292025327-Oct-19 12:23
memberMember 1292025327-Oct-19 12:23 
AnswerRe: ASP maker 2018 Pin
Richard MacCutchan27-Oct-19 23:19
protectorRichard MacCutchan27-Oct-19 23:19 
QuestionDraw Shape in Canvas Pin
John_Ryder26-Oct-19 2:58
memberJohn_Ryder26-Oct-19 2:58 
AnswerRe: Draw Shape in Canvas Pin
Afzaal Ahmad Zeeshan26-Oct-19 10:19
mveAfzaal Ahmad Zeeshan26-Oct-19 10:19 
GeneralRe: Draw Shape in Canvas Pin
John_Ryder29-Oct-19 20:49
memberJohn_Ryder29-Oct-19 20:49 
AnswerRe: Draw Shape in Canvas Pin
jkirkerx28-Oct-19 13:53
professionaljkirkerx28-Oct-19 13:53 
QuestionHow do i make my detailsviewmodel work Pin
Stefaneus22-Oct-19 7:31
memberStefaneus22-Oct-19 7:31 
AnswerRe: How do i make my detailsviewmodel work Pin
jkirkerx23-Oct-19 11:54
professionaljkirkerx23-Oct-19 11:54 
QuestionHow do i make a bootstrap carousel work with Asp.net core Razor Pin
Stefaneus21-Oct-19 15:49
memberStefaneus21-Oct-19 15:49 
AnswerRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Richard Deeming22-Oct-19 2:00
mveRichard Deeming22-Oct-19 2:00 
GeneralRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Stefaneus22-Oct-19 6:02
memberStefaneus22-Oct-19 6:02 
GeneralRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Richard Deeming22-Oct-19 6:14
mveRichard Deeming22-Oct-19 6:14 
GeneralRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Stefaneus22-Oct-19 8:04
memberStefaneus22-Oct-19 8:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.