Exemplo n.º 1
0
 public OutPutDTO SearchListDomainTypes([FromBody] DomainType objSearch)
 {
     try
     {
         List <DomainType> result = commonBu.FindByProperty <DomainType, DomainType>(objSearch, "DomainTypeID asc");
         return(new OutPutDTO(true, Constants.STATUS_CODE.SUCCESS, Constants.STATUS_MESSAGE.SUCCESS, result));
     }
     catch (Exception ex)
     {
         return(new OutPutDTO(false, Constants.STATUS_CODE.EXCEPTION, Constants.STATUS_MESSAGE.EXCEPTION + ex.Message, null));
     }
 }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            string hashedTokenId = context.Token.GetHash();

            CommonBusiness    commonBu     = new CommonBusiness();
            OAuthRefreshToken refreshToken = commonBu.FindByProperty <OAuthRefreshToken>("TokenId", hashedTokenId, "")[0];

            if (refreshToken != null)
            {
                //Get protectedTicket from refreshToken class
                context.DeserializeTicket(refreshToken.Authentication);

                commonBu.getDbContext().OAuthRefreshTokens.Remove(refreshToken);
                commonBu.getDbContext().SaveChanges();
            }
        }
Exemplo n.º 3
0
 public OutPutDTO CreateUser([FromBody] OAuthDetailDTO oAuthDetailDTO)
 {
     if (!ModelState.IsValid)
     {
         return(new OutPutDTO(false, Constants.STATUS_CODE.FAILURE, Constants.STATUS_MESSAGE.FAILURE, null));
     }
     try
     {
         // Tạo OAuthDetail
         string clientId     = CommonUtil.RandomString(32);
         string clientSecret = CommonUtil.RandomString(32);
         // validate
         List <OAuthDetail> lst = commonBu.FindByProperty <OAuthDetail>("UserName", oAuthDetailDTO.UserName, "");
         // check user name
         if (!CommonUtil.IsNullOrEmpty <OAuthDetail>(lst))
         {
             return(new OutPutDTO(false, Constants.STATUS_CODE.FAILURE, Constants.STATUS_MESSAGE.FAILURE, null));
         }
         // check client id
         lst = commonBu.FindByProperty <OAuthDetail>("ClientId", clientId, "");
         if (!CommonUtil.IsNullOrEmpty <OAuthDetail>(lst))
         {
             return(new OutPutDTO(false, Constants.STATUS_CODE.FAILURE, Constants.STATUS_MESSAGE.FAILURE, null));
         }
         // check quyen
         if (oAuthDetailDTO.Role.Contains(Constants.AUTHENTICATION.ROLE_ADMINISTRATOR))
         {
             return(new OutPutDTO(false, Constants.STATUS_CODE.FAILURE, Constants.STATUS_MESSAGE.FAILURE, null));
         }
         // save OAuthDetail
         OAuthDetail oAuthDetail = new OAuthDetail();
         oAuthDetail.UserName = oAuthDetailDTO.UserName;
         oAuthDetail.Password = oAuthDetailDTO.Password.Encrypt(Constants.ENCRYPT_KEY);
         oAuthDetail.IpAccess = oAuthDetailDTO.IpAccess;
         oAuthDetail.ClientId = clientId;
         commonBu.getDbContext().OAuthDetails.Add(oAuthDetail);
         //commonBu.Save(oAuthDetail);
         commonBu.getDbContext().SaveChanges();
         // save OAuthClientDetail
         OAuthClientDetail oAuthClientDetail = new OAuthClientDetail();
         oAuthClientDetail.AccessTokenValidity  = ACCESS_TOKEN_VALIDITY;
         oAuthClientDetail.RefreshTokenValidity = REFRESS_TOKEN_VALIDITY;
         oAuthClientDetail.Authorities          = oAuthDetailDTO.Role;
         oAuthClientDetail.GrantTypes           = AUTHORIZED_GRANT_TYPE;
         oAuthClientDetail.ClientId             = clientId;
         oAuthClientDetail.ClientSecret         = clientSecret;
         oAuthClientDetail.ResourceIds          = RESOURCE_ID;
         oAuthClientDetail.Scope = SCOPE;
         commonBu.Save(oAuthClientDetail);
         commonBu.getDbContext().SaveChanges();
         // set return data
         OAuthDetailDTO outPut = oAuthDetailDTO;
         outPut.ClientId     = clientId;
         outPut.ClientSecret = clientSecret;
         return(new OutPutDTO(true, Constants.STATUS_CODE.FAILURE, Constants.STATUS_MESSAGE.SUCCESS, outPut));
     }
     catch (Exception ex)
     {
         return(new OutPutDTO(false, Constants.STATUS_CODE.EXCEPTION, Constants.STATUS_MESSAGE.EXCEPTION + ex.Message, null));
     }
 }