protected void Session_Start(object sender, EventArgs e) { var principal = (ClaimsPrincipal)HttpContext.Current.User; var identity = principal.Identity; var bootstrapContext = (BootstrapContext)principal.Identities.First().BootstrapContext; SecurityTokenHelper.StoreSecurityToken(SecurityTokenHelper.GetTokenFromBootstrapContext(bootstrapContext)); Debug.WriteLine($"Session_Start. Identity name: {identity.Name}"); }
public IActionResult Verify(string key, string hashtoken) { try { if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(hashtoken)) { var arrayVakue = SecurityTokenHelper.SplitToken(key); if (arrayVakue != null) { // arrayVakue[1] "UserId" var userId = Convert.ToInt64(arrayVakue[1]); var rvModel = _verificationQueries.GetResetGeneratedToken(userId); if (rvModel != null) { var result = SecurityTokenHelper.IsTokenValid(arrayVakue, hashtoken, rvModel.GeneratedToken); if (result == 1) { TempData["TokenMessage"] = "Sorry Verification Link Expired Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } if (result == 2) { TempData["TokenMessage"] = "Sorry Verification Link Expired Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } if (result == 0) { HttpContext.Session.SetString("VerificationUserId", arrayVakue[1]); HttpContext.Session.SetString("ActiveVerification", "1"); return(RedirectToAction("Reset", "ResetPassword")); } } } } } catch (Exception) { TempData["TokenMessage"] = "Sorry Verification Failed Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } TempData["TokenMessage"] = "Sorry Verification Failed Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); }
public override Task OnAuthorizationAsync(HttpActionContext actionContext, System.Threading.CancellationToken cancellationToken) { ErrorCode? errorCode; SecurityToken token = SecurityTokenHelper.GetTokenFromRequest(actionContext.Request, out errorCode); if (null != errorCode) { actionContext.Response = actionContext.Request.CreateResponse(errorCode.GetStatusCode(), new Error(errorCode)); return(Task.FromResult <object>(null)); } var controller = actionContext.ControllerContext.Controller; ((BaseApiController)controller).SecurityToken = token; //((BaseApiController)controller).TokenKey = key; actionContext.Request.Properties.Add("key", token); return(Task.FromResult <object>(null)); }
private void CustomAuthenticationModule_SecurityTokenReceived(object sender, SecurityTokenReceivedEventArgs e) { SecurityTokenHelper.StoreSecurityToken(e.SecurityToken); Debug.WriteLine($"SecurityTokenReceived. SecurityToken ID: {e.SecurityToken.Id}"); }
public static string Value([NotNull] this JwtSecurityToken thisValue) { return(SecurityTokenHelper.Value(thisValue)); }
public IActionResult Verify(string key, string hashtoken) { try { if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(hashtoken)) { var arrayVakue = SecurityTokenHelper.SplitToken(key); if (arrayVakue != null) { // arrayVakue[1] "UserId" var userId = Convert.ToInt64(arrayVakue[1]); var rvModel = _verificationQueries.GetRegistrationGeneratedToken(userId); if (rvModel != null) { var result = SecurityTokenHelper.IsTokenValid(arrayVakue, hashtoken, rvModel.GeneratedToken); if (result == 1) { TempData["TokenErrorMessage"] = "Sorry Verification Link Expired Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } if (result == 2) { TempData["TokenErrorMessage"] = "Sorry Verification Link Expired Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } if (result == 0) { if (_verificationQueries.CheckIsAlreadyVerifiedRegistration(Convert.ToInt64(arrayVakue[1]))) { TempData["TokenErrorMessage"] = "Sorry Link Expired"; return(RedirectToAction("Login", "Portal")); } HttpContext.Session.SetString("VerificationUserId", arrayVakue[1]); var resetPasswordVerificationobj = _verificationQueries.GetRegistrationGeneratedToken(userId); _unitOfWorkEntityFramework.VerificationCommand.UpdateRegisterVerification(resetPasswordVerificationobj); var updateresult = _unitOfWorkEntityFramework.Commit(); if (updateresult) { TempData["Verify"] = "Done"; return(RedirectToAction("Completed", "VerifyRegistration")); } else { TempData["TokenErrorMessage"] = "Sorry Verification Failed Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } } } } } } catch (Exception) { TempData["TokenMessage"] = "Sorry Verification Failed Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } TempData["TokenMessage"] = "Sorry Verification Failed Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); }