示例#1
0
        public ResultMessageEntity GenerateToken(AuthenticationReqMsgEntity authenticationMsgEntity)
        {
            try
            {
                var claims = new[] {
                    new Claim(JwtRegisteredClaimNames.Sub, authenticationMsgEntity.Username),
                    new Claim(JwtRegisteredClaimNames.Jti, authenticationMsgEntity.PartnerKey)
                };

                var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("ThisismySecretKey"));
                var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
                var issuer      = "local.com";

                var token = new JwtSecurityToken(issuer, issuer, claims: claims, expires: DateTime.UtcNow.AddMinutes(10), signingCredentials: credentials);
                authenticationMsgEntity.TokenDetail = new JwtSecurityTokenHandler().WriteToken(token);
            }
            catch (Exception ex)
            {
                return(ColdFishServiceOpenApiUtility.GetResultMessageEntity(ResultStatus.Fail, "Error while generating token", authenticationServiceErrorCodes.TokenGenerationUnexpectedError));
            }

            return(new ResultMessageEntity()
            {
                ResultStatus = ResultStatus.Success
            });
        }
 public ResultMessageEntity IsPartnerKeyValid(AuthenticationReqMsgEntity authenticationMsgEntity)
 {
     if (authenticationMsgEntity.PartnerKey.IsEmpty())
     {
         return(ColdFishServiceOpenApiUtility.GetResultMessageEntity(ResultStatus.Fail, "PartnerKey is empty", authenticationServiceErrorCodes.PartnerKeyIsEmpty));
     }
     return(new ResultMessageEntity {
         ResultStatus = ResultStatus.Success
     });
 }
 public ResultMessageEntity IsAuthenticationReqMsgEntityValid(AuthenticationReqMsgEntity authenticationMsgEntity)
 {
     if (authenticationMsgEntity == null)
     {
         return(ColdFishServiceOpenApiUtility.GetResultMessageEntity(ResultStatus.Fail, "AuthenticationReqMsgEntity is empty", authenticationServiceErrorCodes.AuthenticationReqMsgEntityIsEmpty));
     }
     return(new ResultMessageEntity()
     {
         ResultStatus = ResultStatus.Success
     });
 }
 public ResultMessageEntity IsUserNameValid(AuthenticationReqMsgEntity authenticationMsgEntity)
 {
     if (authenticationMsgEntity.Username.IsEmpty())
     {
         return(ColdFishServiceOpenApiUtility.GetResultMessageEntity(ResultStatus.Fail, "Username is empty", authenticationServiceErrorCodes.UsernameIsEmpty));
     }
     if (authenticationMsgEntity.Username.IsEmpty())
     {
         return(ColdFishServiceOpenApiUtility.GetResultMessageEntity(ResultStatus.Fail, "Username is empty", authenticationServiceErrorCodes.UsernameIsEmpty));
     }
     return(new ResultMessageEntity {
         ResultStatus = ResultStatus.Success
     });
 }
        public ResultMessageEntity IsPartnerValid(AuthenticationReqMsgEntity authenticationReqMsgEntity)
        {
            PartnerKeyDetailsDAO        partnerKeyDetailsDAO      = authenticationServiceMapper.MapPartnerKeyDetailsDAO(authenticationReqMsgEntity);
            List <PartnerKeyDetailsDAO> validPartnerKeyDetailsDAO = authenticationServiceRepository.GetPartnerDetail(partnerKeyDetailsDAO);

            if (!validPartnerKeyDetailsDAO.AnyWithNullCheck())
            {
                return(ColdFishServiceOpenApiUtility.GetResultMessageEntity(ResultStatus.Fail, "Partner is Invalid", authenticationServiceErrorCodes.PartnerNotFound));
            }
            if (validPartnerKeyDetailsDAO.Count > 1)
            {
                return(ColdFishServiceOpenApiUtility.GetResultMessageEntity(ResultStatus.Fail, "To Many partners", authenticationServiceErrorCodes.PartnerNotFound));
            }
            return(new ResultMessageEntity {
                ResultStatus = ResultStatus.Success
            });
        }