public async Task <ActionResult> Login(string userName) { var account = await _db.FindByUserNameAsync(userName); if (account != null) { //TODO 1: Generate auth cookie for user 'userName' with external id var claims = new List <Claim> { new Claim(ClaimTypes.Name, account.ExternalId), new Claim(ClaimTypes.Role, account.Role), }; var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)); return(Ok()); } //TODO 2: return 404 if user not found return(NotFound()); }
public async Task <ActionResult> Login(string userName) { var account = await _db.FindByUserNameAsync(userName); if (account != null) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, account.ExternalId), new Claim(ClaimTypes.Role, account.Role) }; ClaimsIdentity id = new ClaimsIdentity(claims, "Cookie"); await HttpContext.SignInAsync("Cookie", new ClaimsPrincipal(id)); return(Ok()); //TODO 1: Solved //Generate auth cookie for user 'userName' with external id } else { return(NotFound()); //TODO 2: Solved //return 404 if user not found } }
public async Task Login(string userName) { var account = await _db.FindByUserNameAsync(userName); if (account != null) { //TODO 1: Generate auth cookie for user 'userName' with external id var claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, account.ExternalId), new Claim("Role", account.Role) }; ClaimsIdentity id = new ClaimsIdentity(claims, "ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, "Role"); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(id)); } //TODO 2: return 404 if user not found else { HttpContext.Response.StatusCode = 404; } return; }
public async Task Login(string userName) { var account = await _db.FindByUserNameAsync(userName); if (account != null) { //TODO 1: Generate cookie for user 'userName' with external id } //TODO 2: return 404 not found if user not found }
public async Task Login(string userName) { var account = await _db.FindByUserNameAsync(userName); if (account != null) { //TODO 1: Generate auth cookie for user 'userName' with external id Response.Cookies.Append("externalId", account.InternalId.ToString()); } else { //TODO 2: return 404 if user not found HttpContext.Response.StatusCode = 404; } }
public async Task Login([FromBody] UserName userName) { var account = await _db.FindByUserNameAsync(userName.userName); if (account != null) { //TODO 1: Generate auth cookie for user 'userName' with external id HttpContext.User.AddIdentity(new ClaimsIdentity("userNa", userName.userName, account.Role)); HttpContextCookieProvider HttpCookie = new HttpContextCookieProvider(HttpContext); HttpCookie.SetCookie(account.UserName, account.ExternalId); } //TODO 2: return 404 if user not found else { Response.StatusCode = (int)HttpStatusCode.NotFound; } }
public async Task Login(string userName) { var account = await _db.FindByUserNameAsync(userName); if (account != null) { var claims = new List <Claim>(); claims.Add(new Claim(ClaimsIdentity.DefaultNameClaimType, account.ExternalId)); ClaimsIdentity id = new ClaimsIdentity(claims, "ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, account.Role); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(id)); Response.Redirect("/api/account"); //TODO 1 (completed): Generate auth cookie for user 'userName' with external id } else { Response.StatusCode = 404; } //TODO 2 (completed): return 404 not found if user not found }
public async Task Login(string userName) { var account = await _db.FindByUserNameAsync(userName); if (account != null) { //TODO 1: Generate auth cookie for user 'userName' with external id HttpContext.Response.Cookies.Append("ExternalId", account.ExternalId.ToString()); var claims = new List <Claim> { new Claim(ClaimTypes.Name, account.UserName), // new Claim("ExternalId", account.ExternalId), new Claim(ClaimTypes.Role, account.Role), }; var userIdentity = new ClaimsIdentity(claims, "login"); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(userIdentity)); } //TODO 2: return 404 if user not found else { HttpContext.Response.StatusCode = 404; } }
public async Task Login(string userName) { var account = await _db.FindByUserNameAsync(userName); if (account != null) { //TODO 1: Generate auth cookie for user 'userName' with external id HttpContext.Response.Cookies.Append("ExternalId", account.ExternalId); ///i dunno how to do all of it. But i want to learn ASP.NET ~^~ ///Please, teach me! ///I really tried solve it in the last two days, but as you can see it was needlesly ///Hope, my solved first part was at least of some value. ///Anyway, Thanks for the interesting tasks with the console. :3 } else { //TODO 2: return 404 if user not found Response.StatusCode = 404; View("Not Found"); } }