// ...

        private ClaimsPrincipal GenerateResponse(HttpContext context)
        {
            try
            {
                string token = context.Request.Headers["Token"];
                if (token != null)
                {
                    TokenManager.Token tokenManager = new TokenManager.Token();
                    ClaimsPrincipal    principal    = tokenManager.ValidateToken(token);
                    return(principal);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(null);
        }
Exemple #2
0
        public dynamic Login(string username, string password, DateTime dt)
        {
            dynamic obj   = dal.Login(username, password, dt);
            string  token = string.Empty;
            dynamic obje  = new ExpandoObject();

            if (obj != null)
            {
                tokenManager = new TokenManager.Token();

                ClaimsIdentity claims = new ClaimsIdentity();
                claims.AddClaim(new Claim("Name", obj.Name));
                claims.AddClaim(new Claim("Role", obj.Role));
                claims.AddClaim(new Claim("Id", Convert.ToString(obj.Id)));
                claims.AddClaim(new Claim("RId", Convert.ToString(obj.RoleId)));
                token      = tokenManager.GenerateToken(claims);
                obje.token = token;
                obje.Role  = obj.Role;
            }


            return(obje);
        }