Example #1
0
        public async Task <IActionResult> LogOutToken([FromBody] string token)
        {
            var res = await _tokenAuthService.BlackToken(token, "black", $"{KeepCallServer.getTokenAuthHostPort(_urlConfig.Value.ZooKeeperList)}{_urlConfig.Value.TokenAuthUrl}");

            if ("Success".Equals(res))
            {
                //HttpContext.Response.Cookies.Delete("token");
                //HttpContext.Session.Remove("CurrentUser");
                return(Ok(new { Result = "Success", Token = token }));
            }
            else
            {
                return(Ok(new { Result = "Faild" }));
            }
        }
Example #2
0
        //验证当前请求的角色权限
        private string VerfiyAuth(string jti, string userId, string roleIds, string currController, string currPath)
        {
            HttpClient _httpClient = new HttpClient();
            var        parameters  = new Dictionary <string, string>();

            parameters.Add("jti", jti);
            parameters.Add("userId", userId);
            parameters.Add("roleIds", roleIds);
            parameters.Add("currController", currController);
            parameters.Add("currPath", currPath);
            parameters.Add("role", "validate");
            var response = _httpClient.PostAsync($"{KeepCallServer.getTokenAuthHostPort(_urlConfig.Value.ZooKeeperList)}{_urlConfig.Value.TokenAuthUrl}", new FormUrlEncodedContent(parameters)).Result;  //验证权限需同步执行
            var result   = response.Content.ReadAsStringAsync();

            if (response.StatusCode != HttpStatusCode.OK)
            {
                return(result.Result);
            }
            var json = JsonConvert.DeserializeObject <Dictionary <string, object> >(result.Result);

            return(json.Where(t => t.Key == "Result").FirstOrDefault().Value.ToString());
        }
Example #3
0
        public async Task <IActionResult> GetToken([FromBody] LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(new
                {
                    Result = "Faild",
                    Message = GetModelStateError()
                }));
            }
            var token = await _tokenAuthService.GetToken(model.UserName, model.Password, "auth", $"{KeepCallServer.getTokenAuthHostPort(_urlConfig.Value.ZooKeeperList)}{_urlConfig.Value.TokenAuthUrl}");

            if (!string.IsNullOrWhiteSpace(token) && token.Length > 50)
            {
                CookieOptions conf = new CookieOptions();
                conf.Expires = DateTimeOffset.Now.AddMinutes(30);
                //HttpContext.Response.Cookies.Append("token", token, conf);
                //HttpContext.Session.Set("token", ByteConvertHelper.Object2Bytes(token));
                return(Ok(new { Result = "Success", Token = token }));
            }
            else
            {
                return(Ok(new { Result = "Faild", Message = token }));
            }
        }