单点登陆

 var queryList = _usersss.GetAll().Where(s => s.User == user).FirstOrDefault();
            if (queryList == null)
            {
                throw new UserFriendlyException("数据异常", "用户未注册");
            }
            else
            {
                if (queryList.Password != passWord)
                { throw new UserFriendlyException("数据异常", "密码错误"); }
                else
                {
                    var cleims = new[]
                    {
                        new Claim(ClaimTypes.Name, queryList.User),
                        new Claim(ClaimTypes.NameIdentifier, queryList.Id.ToString()),
                    };
                    var key = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("netcore"));
                    var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
                    var token = new JwtSecurityToken(
                        issuer: "cc",
                        audience: "cc",
                        claims: cleims,
                        expires: DateTime.Now.AddYears(1),
                        signingCredentials: creds);
                    string jwtToken = new JwtSecurityTokenHandler().WriteToken(token);

                }
            }

 

posted @ 2019-05-07 14:59  沂水弦歌  阅读(173)  评论(0编辑  收藏  举报