Пример #1
0
        public override Task <AccessReplyMessage> AccessRequest(AccessReqMessage request, ServerCallContext context)
        {
            string token = "";

            if (request.Name == "1" && request.Pass == "1")
            {
                token = SecUtility.GenerateJWT(request, config);
            }

            return(Task.FromResult(new AccessReplyMessage {
                Token = token
            }));
        }
        public static string GenerateJWT(AccessReqMessage m, IConfiguration config)
        {
            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config["Jwt:Key"]));
            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken(config["Jwt:Issuer"],
                                             config["Jwt:Issuer"],
                                             null,
                                             expires: DateTime.Now.AddMinutes(60),
                                             signingCredentials: credentials);

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }