public AccountService(RequestContext c, UserAccountRepository userAccounts, AuthTokenRepository authTokens, ApiKeyRepository apiKeys, StoreUserRelationshipRepository adminUsersXStores, StoreRepository stores) { context = c; AdminUsers = userAccounts; AuthTokens = authTokens; ApiKeys = apiKeys; AdminUsersXStores = adminUsersXStores; Stores = stores; }
private bool ApiKeyIsValid(string apiKey) { bool isValid = false; try { var repo = new ApiKeyRepository(); return(!string.IsNullOrEmpty(repo.Get(apiKey))); } catch (Exception ex) { logger.Error(ex); } return(isValid); }
public DeleteApiKeyHandlerTests() { _uow = ConnectionFactory.Create(); GetApplicationId(); _existingEntity = new ApiKey { ApplicationName = "Arne", GeneratedKey = Guid.NewGuid().ToString("N"), SharedSecret = Guid.NewGuid().ToString("N"), CreatedById = 20, CreatedAtUtc = DateTime.UtcNow }; _existingEntity.Add(_applicationId); var repos = new ApiKeyRepository(_uow); repos.CreateAsync(_existingEntity).Wait(); }
public async Task Should_be_able_to_Create_key() { var cmd = new CreateApiKey("Mofo", Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"), new[] { _applicationId }); var bus = Substitute.For <IMessageBus>(); var ctx = Substitute.For <IMessageContext>(); using (var uow = CreateUnitOfWork()) { var sut = new CreateApiKeyHandler(uow, bus); await sut.HandleAsync(ctx, cmd); var repos = new ApiKeyRepository(uow); var generated = await repos.GetByKeyAsync(cmd.ApiKey); generated.Should().NotBeNull(); generated.Claims.First().Value.Should().BeEquivalentTo(_applicationId.ToString()); uow.SaveChanges(); } }
public async Task Should_be_able_to_Create_a_key_without_applications_mapped() { var cmd = new CreateApiKey("Mofo", Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N")); var bus = Substitute.For <IMessageBus>(); var ctx = Substitute.For <IMessageContext>(); using (var uow = CreateUnitOfWork()) { var sut = new CreateApiKeyHandler(uow, bus); await sut.HandleAsync(ctx, cmd); var repos = new ApiKeyRepository(uow); var generated = await repos.GetByKeyAsync(cmd.ApiKey); generated.Should().NotBeNull(); generated.Claims.Should().NotBeEmpty("because keys without appIds are universal"); uow.SaveChanges(); } }
public DeleteApiKeyHandlerTests(ITestOutputHelper helper) : base(helper) { GetApplicationId(); _existingEntity = new ApiKey { ApplicationName = "Arne", GeneratedKey = Guid.NewGuid().ToString("N"), SharedSecret = Guid.NewGuid().ToString("N"), CreatedById = 20, CreatedAtUtc = DateTime.UtcNow }; _existingEntity.Add(_applicationId); using (var uow = CreateUnitOfWork()) { var repos = new ApiKeyRepository(uow); repos.CreateAsync(_existingEntity).GetAwaiter().GetResult(); uow.SaveChanges(); } }
/// <summary> /// Gets all available API keys, whether they are enabled or not. /// </summary> /// <returns>Returns all API keys.</returns> public IEnumerable <ApiKey> GetAllApiKeys() { return(ApiKeyRepository.GetAllApiKeys()); }
/// <summary> /// Creates a new API key. API keys have no rights and are disabled upon creation. /// </summary> /// <param name="name">Name of the API key to create.</param> /// <returns>Returns the newly created key.</returns> public ApiKey CreateApiKey(string name) { return(ApiKeyRepository.CreateApiKey(name)); }
/// <summary> /// Call the Api Key repository to update an api key record /// </summary> /// <param name="_db">database</param> /// <param name="key">api key</param> /// <returns>The updated api key</returns> public static ApiKey UpdateKey(DatabaseContext _db, ApiKey key) { return(ApiKeyRepository.UpdateKey(_db, key)); }
/// <summary> /// Deletes an API key. /// </summary> /// <param name="id">ID of the key to delete.</param> public void DeleteApiKey(Guid id) { ApiKeyRepository.DeleteApiKey(id); }
/// <summary> /// Call the Api Key repository to retrieve an api key record by application id and isUsed /// </summary> /// <param name="_db">database</param> /// <param name="applicationId"></param> /// <param name="isUsed">whether the key has been used</param> /// <returns></returns> public static ApiKey GetKey(DatabaseContext _db, Guid applicationId, bool isUsed) { return(ApiKeyRepository.GetKey(_db, applicationId, isUsed)); }
/// <summary> /// Call the Api Key repository to retriev an api key record by key field /// </summary> /// <param name="_db">database</param> /// <param name="key">key value of api key</param> /// <returns></returns> public static ApiKey GetKey(DatabaseContext _db, string key) { return(ApiKeyRepository.GetKey(_db, key)); }
/// <summary> /// Call the Api Key repository to retrieve an api key record by id field /// </summary> /// <param name="_db">database</param> /// <param name="id">api key id</param> /// <returns>The retrieved api key</returns> public static ApiKey GetKey(DatabaseContext _db, Guid id) { return(ApiKeyRepository.GetKey(_db, id)); }
public bool ApiKeyExists(string apiKey) { JarsApiKey key = ApiKeyRepository.GetById(apiKey); return(key != null); }
public ApiKey GetApiKey(string apiKey) { JarsApiKey key = ApiKeyRepository.GetById(apiKey); return(key.ConvertTo <ApiKey>()); }
/// <summary> /// Creates a new API key. API keys are disabled upon creation. /// </summary> /// <param name="name">Name of the API key to create.</param> /// <returns>Returns the newly created key.</returns> public async Task <ApiKey> CreateApiKey(string name) { return(await ApiKeyRepository.CreateApiKey(name)); }
/// <summary> /// Deletes an API key. /// </summary> /// <param name="id">ID of the key to delete.</param> public async Task DeleteApiKey(Guid id) { await ApiKeyRepository.DeleteApiKey(id); }
/// <summary> /// Call the Api Key repository to create a new api key record /// </summary> /// <param name="_db">database</param> /// <param name="key">api key</param> /// <returns>The created api key</returns> public static ApiKey CreateKey(DatabaseContext _db, ApiKey key) { return(ApiKeyRepository.CreateNewKey(_db, key)); }
public ApiKeyAuthorizeAttribute() { _apiKeyRepository = new ApiKeyRepository(); }