Example #1
0
        public (string, AuthorizeUserResponse) AuthorizeUser(UserRequest request)
        {
            try
            {
                (string error, Guid userId) = _usersRepository.AuthorizeUser(request);


                var userIdentity = new ClaimsIdentity();
                userIdentity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, userId.ToString()));
                userIdentity.AddClaim(new Claim(ClaimsIdentity.DefaultRoleClaimType, "user"));

                // создаем JWT-токен
                var jwt = new JwtSecurityToken(
                    issuer: AuthOptions.ISSUER,
                    audience: AuthOptions.AUDIENCE,
                    notBefore: DateTime.UtcNow,
                    claims: userIdentity.Claims,
                    expires: DateTime.UtcNow.Add(TimeSpan.FromMinutes(AuthOptions.LIFETIME)),
                    signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256));
                var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);

                AuthorizeUserResponse response = new AuthorizeUserResponse()
                {
                    AccessToken = encodedJwt,
                    UserId      = userIdentity.Name
                };

                return(error, response);
            }
            catch (Exception ex)
            {
                return(ex.Message, null);
            }
        }
Example #2
0
        void ProcessAuthorizeUserResponse(BaseMessage response)
        {
            AuthorizeUserResponse authResponse = response as AuthorizeUserResponse;

            Console.WriteLine("Message ID: {0}, response ID: {1}, UserName: {2}, Status: {3}", authResponse.ID, authResponse.responseID,
                              authResponse.UserName, authResponse.Status);
            UserAuthorized();
        }
Example #3
0
        /// <summary>
        /// 获取编辑数据
        /// </summary>
        /// <param name="menuCode">菜单编号</param>
        /// <param name="dataID">数据Id</param>
        /// <returns></returns>
        public AuthorizeUserResponse FindEntity(string menuCode, int dataID)
        {
            var ret = new AuthorizeUserResponse();
            var dt  = Db.Context.From <TbAuthorization>()
                      .Select(
                TbAuthorization._.All
                , TbUser._.UserName)
                      .LeftJoin <TbUser>((a, c) => a.BSQR == c.UserCode)
                      .Where(p => p.MenuCode == menuCode && p.DataID == dataID).ToDataTable();
            var list = ModelConvertHelper <AuthorizeUser> .ToList(dt);

            if (list.Count > 0)
            {
                ret.AuthorizeUser = list;
                ret.DataID        = list[0].DataID;
                ret.MenuCode      = list[0].MenuCode;
            }
            return(ret);
        }