private string GenerateJSONWebToken(User userInfo)
        {
            var user = _users.Where(x => x.Username == userInfo.Username && x.Password == userInfo.Password).SingleOrDefault();

            if (user != null)
            {
                var signingKey      = Convert_base64String.ConvertFromBase64String(_config["Jwt:Key"]);
                var expiryDuration  = int.Parse(_config["Jwt:ExpiryDuration"]);
                var tokenDiscriptor = new SecurityTokenDescriptor
                {
                    Issuer    = null,
                    Audience  = null,
                    IssuedAt  = DateTime.UtcNow,
                    NotBefore = DateTime.UtcNow,
                    Expires   = DateTime.UtcNow.AddMinutes(expiryDuration),
                    Subject   = new ClaimsIdentity(new List <Claim> {
                        new Claim("id", user.Id.ToString()),
                        new Claim("username", user.Username),
                        new Claim(ClaimTypes.Role, user.Role)
                    }),
                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(signingKey), SecurityAlgorithms.HmacSha256Signature)
                };

                var jwtTokenHandler = new JwtSecurityTokenHandler();
                var jwtToken        = jwtTokenHandler.CreateJwtSecurityToken(tokenDiscriptor);
                var token           = jwtTokenHandler.WriteToken(jwtToken);

                return(token);
            }

            return(null);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                var signingKey = Convert_base64String.ConvertFromBase64String(Configuration["Jwt:Key"]);

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["Jwt:Issuer"],
                    ValidAudience    = Configuration["Jwt:Issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(signingKey)
                };
            });

            services.ConfigureApplicationCookie(options =>
            {
                options.Events.OnRedirectToLogin = context =>
                {
                    context.Response.StatusCode = 401;
                    return(Task.CompletedTask);
                };
            });

            services.AddCors(options => options.AddPolicy("CorsPolicy", builder =>
                                                          { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); }
                                                          ));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }