async Task <IActionResult> extern_signin() { Mo_User_SignIn model; UserAccount uacc; PairValue <Mo_Result, UserAccount> backward; ClaimsIdentity claimsIdentity; List <Claim> claims; Mo_AuthResult frontend = new Mo_AuthResult(); string reqJson = string.Empty; if ((Request.ContentLength.HasValue && Request.ContentLength > 0 || Request.Body.CanRead)) { using (var reader = new System.IO.StreamReader(Request.Body)) reqJson = await reader.ReadToEndAsync(); if (!string.IsNullOrEmpty(reqJson)) { model = JsonSerializer.Deserialize <Mo_User_SignIn>(reqJson); // go sign in backward = await signin(model); uacc = backward.second; if (backward.first.result) { //complete claims = new List <Claim>(2) { new Claim("username", uacc.username), new Claim("role", uacc.role ?? "User") }; claimsIdentity = new ClaimsIdentity(claims, "Token", "untype", "unroletype"); string token = JWT_Token_Controller.create_token(claimsIdentity); frontend.access_token = token; frontend.refresh_token = null; frontend.result = true; frontend.role = uacc.role; frontend.loggedDate = uacc.lastLoggedDate; frontend.userId = uacc.getUserId();// get the user id frontend.redirectPage = "//todo: link to redirecting"; frontend.message = "Sign in complete"; } else { frontend.message = backward.first.message; } return(Json(frontend)); } } return(Unauthorized()); }
public IActionResult GET_Valid() { bool isValid = false; string type = "unknown"; if (Request.Query.ContainsKey("access_token")) { string access_token = Request.Query["access_token"].ToString(); isValid = JWT_Token_Controller.check_token(access_token); type = "Token Validator"; } return(Json(new { valid = isValid, validator = type, messageToHacker = ConstEnums.Message_To_Hacker })); }