Beispiel #1
0
        public async Task <ResponseModel> Create(User User)
        {
            User usr = userRepository.Create(User);

            if (usr == null)
            {
                return(responseModel.CreateResponse(HttpStatusCode.Unauthorized, "Check Credentials Again...!"));
            }

            var claims = new[] {
                new Claim(JwtRegisteredClaimNames.Sub, User.Username),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
            };

            var signitureKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("MyAdvanceSupperKey"));

            var token = new JwtSecurityToken(
                issuer: "http://oec.com",
                audience: "http://oec.com",
                expires: DateTime.UtcNow.AddHours(2),
                claims: claims,
                signingCredentials: new Microsoft.IdentityModel.Tokens.SigningCredentials(signitureKey, SecurityAlgorithms.HmacSha256)

                );

            return(responseModel.CreateResponse(HttpStatusCode.OK, "Welcome",
                                                new {
                Authenticated = true,
                token = new JwtSecurityTokenHandler().WriteToken(token),
                expiration = token.ValidTo
            }));
        }
        public async Task <ResponseModel> GetTechnologiesAsync()
        {
            try
            {
                var li = await technologyRepo.ListTechnologyAsync();

                return(responseModel.CreateResponse(HttpStatusCode.OK, "List Of Technology", Data: li));
            }
            catch (Exception)
            {
                throw;
            }
        }