/// <summary> /// Create system generated security key pair /// </summary> /// <param name="userId"> </param> /// <param name="securityKeysGeneration"></param> /// <returns></returns> public static SecurityKeysPair SystemGeneratedSecurityKeyPair(int userId, ISecurityKeysGenerationService securityKeysGeneration) { var keys = securityKeysGeneration.GenerateNewSecurityKeys(); SecurityKeysPair securityKeysPair = new SecurityKeysPair(keys.Item1, keys.Item2, DateTime.Now.ToString(), userId, true); return(securityKeysPair); }
/// <summary> /// Create user generated api key /// </summary> /// <returns></returns> public static SecurityKeysPair UserGeneratedSecurityPair(int userId, string keyDescription, string apiKey, string secretKey, bool enableExpirationDate, string expirationDate, bool enableStartDate, string startDate, bool enableEndDate, string endDate, List <SecurityKeysPermission> keysPermissions, ISecurityKeysRepository repository) { //check if key description already exist if (repository.GetByKeyDescriptionAndUserId(keyDescription, userId) != null) { throw new ArgumentException("The key description already exist"); } SecurityKeysPair securityKeysPair = new SecurityKeysPair(apiKey, secretKey, keyDescription, userId, false, keysPermissions); if (enableExpirationDate) { securityKeysPair.ExpirationDate = Convert.ToDateTime(expirationDate); } else { securityKeysPair.ExpirationDate = null; } if (enableStartDate) { securityKeysPair.StartDate = Convert.ToDateTime(startDate); } else { securityKeysPair.StartDate = null; } if (enableEndDate) { securityKeysPair.EndDate = Convert.ToDateTime(endDate); } else { securityKeysPair.EndDate = null; } securityKeysPair.EnableStartDate = enableStartDate; securityKeysPair.EnableEndDate = enableEndDate; securityKeysPair.EnableExpirationDate = enableExpirationDate; return(securityKeysPair); }