public async Task <ActionResult> DeleteApiKey(string apiKeyId)
        {
            await _apiKeyService.DeleteAsync(apiKeyId);

            var tenant = HttpContext.GetTenant();

            await PublishApiKeyChangeEventAsync(TopicType.Remove, new ApiKey()
            {
                Id = apiKeyId
            }, tenant !.Id !);

            return(NoContent());
        }
        public async Task <IActionResult> DeleteApiKey(string key)
        {
            var apiKey = await _apiKeyService.GetAsync(key);

            if (apiKey?.UserId != UserId)
            {
                return(HttpBadRequest("Invalid API key."));
            }

            await _apiKeyService.DeleteAsync(key);

            Notify(FlashNotificationType.Info, "API key has been removed.");
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public ApiKeyModule(IApiKeyService apiKeyService) : base("api-keys")
        {
            this.RequiresAuthentication();

            Post("", async args =>
            {
                var request = BindRequest <CreateApiKey>();
                var apiKey  = await apiKeyService.CreateAsync(CurrentUsername, request.Expiry);

                return(new { apiKey });
            });

            Delete("{apiKey}", async args =>
            {
                await apiKeyService.DeleteAsync((string)args.apiKey);

                return(HttpStatusCode.NoContent);
            });
        }
Exemple #4
0
        public async Task <IActionResult> Delete()
        {
            try
            {
                if (apiKeyProvider.ApiKey == null)
                {
                    return(NoContent());
                }

                var deleted = await apiKeyService.DeleteAsync(apiKeyProvider.ApiKey.Id.ToString());

                await imageService.DeleteAsync(apiKeyProvider.ApiKey);

                return(NoContent());
            }
            catch (Exception e)
            {
                Log.Error(e, $"An error occured while trying to delete an api key '{apiKeyProvider.ApiKey.ToString}'");
                return(StatusCode(500));
            }
        }