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;
 }
示例#2
0
        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();
            }
        }
示例#6
0
        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();
            }
        }
示例#7
0
 /// <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());
 }
示例#8
0
 /// <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));
 }
示例#9
0
 /// <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));
 }
示例#10
0
 /// <summary>
 /// Deletes an API key.
 /// </summary>
 /// <param name="id">ID of the key to delete.</param>
 public void DeleteApiKey(Guid id)
 {
     ApiKeyRepository.DeleteApiKey(id);
 }
示例#11
0
 /// <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));
 }
示例#12
0
 /// <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));
 }
示例#13
0
 /// <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));
 }
示例#14
0
        public bool ApiKeyExists(string apiKey)
        {
            JarsApiKey key = ApiKeyRepository.GetById(apiKey);

            return(key != null);
        }
示例#15
0
        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);
 }
示例#18
0
 /// <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));
 }
示例#19
0
 public ApiKeyAuthorizeAttribute()
 {
     _apiKeyRepository = new ApiKeyRepository();
 }