Click here to Skip to main content
15,886,110 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: what is major difference between blazor server app and asp.net mvc razor app? Pin
jkirkerx13-Nov-19 9:56
professionaljkirkerx13-Nov-19 9:56 
Questiongridview with dynamic dropdownlist control null exception Pin
Anand Solomon11-Nov-19 4:41
Anand Solomon11-Nov-19 4:41 
Questionvideo calling in asp.net Pin
Member 146439065-Nov-19 18:37
Member 146439065-Nov-19 18:37 
AnswerRe: video calling in asp.net Pin
F-ES Sitecore6-Nov-19 1:04
professionalF-ES Sitecore6-Nov-19 1:04 
AnswerRe: video calling in asp.net Pin
Blikkies6-Nov-19 1:28
professionalBlikkies6-Nov-19 1: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 20:17
Member 134445211-Nov-19 20: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 22:33
mveRichard Deeming3-Nov-19 22:33 
QuestionASP.Net Core Identity Pin
Mycroft Holmes28-Oct-19 13:11
professionalMycroft Holmes28-Oct-19 13: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 13:10
professionaljkirkerx30-Oct-19 13:10 
GeneralRe: ASP.Net Core Identity Pin
Mycroft Holmes31-Oct-19 11:13
professionalMycroft Holmes31-Oct-19 11:13 
GeneralRe: ASP.Net Core Identity Pin
jkirkerx1-Nov-19 12:23
professionaljkirkerx1-Nov-19 12:23 
QuestionImporting Rows Into a List Pin
ibrahimayhans28-Oct-19 0:37
ibrahimayhans28-Oct-19 0:37 
QuestionASP maker 2018 Pin
Member 1292025327-Oct-19 11:23
Member 1292025327-Oct-19 11:23 
AnswerRe: ASP maker 2018 Pin
Richard MacCutchan27-Oct-19 22:19
mveRichard MacCutchan27-Oct-19 22:19 
QuestionDraw Shape in Canvas Pin
John_Ryder26-Oct-19 1:58
John_Ryder26-Oct-19 1:58 
AnswerRe: Draw Shape in Canvas Pin
Afzaal Ahmad Zeeshan26-Oct-19 9:19
professionalAfzaal Ahmad Zeeshan26-Oct-19 9:19 
GeneralRe: Draw Shape in Canvas Pin
John_Ryder29-Oct-19 19:49
John_Ryder29-Oct-19 19:49 
AnswerRe: Draw Shape in Canvas Pin
jkirkerx28-Oct-19 12:53
professionaljkirkerx28-Oct-19 12:53 
QuestionHow do i make my detailsviewmodel work Pin
Stefaneus22-Oct-19 6:31
Stefaneus22-Oct-19 6:31 
AnswerRe: How do i make my detailsviewmodel work Pin
jkirkerx23-Oct-19 10:54
professionaljkirkerx23-Oct-19 10:54 
QuestionHow do i make a bootstrap carousel work with Asp.net core Razor Pin
Stefaneus21-Oct-19 14:49
Stefaneus21-Oct-19 14:49 
AnswerRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Richard Deeming22-Oct-19 1:00
mveRichard Deeming22-Oct-19 1:00 
GeneralRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Stefaneus22-Oct-19 5:02
Stefaneus22-Oct-19 5:02 
GeneralRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Richard Deeming22-Oct-19 5:14
mveRichard Deeming22-Oct-19 5:14 
GeneralRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Stefaneus22-Oct-19 7:04
Stefaneus22-Oct-19 7: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.