public ApiKeysModule(ICommandDispatcher commandDispatcher, IIdentityProvider identityProvider, IValidatorResolver validatorResolver, IApiKeyStorage apiKeyStorage) : base(commandDispatcher, validatorResolver, identityProvider, modulePath: "api-keys") { Get("", async args => await FetchCollection <BrowseApiKeys, ApiKey> (async x => await apiKeyStorage.BrowseAsync(x)) .MapTo(x => new { Name = x.Name, Key = x.Key }) .HandleAsync()); Get("{name}", async args => await Fetch <GetApiKey, ApiKey> (async x => await apiKeyStorage.GetAsync(x.UserId, x.Name)) .MapTo(x => new { Name = x.Name, Key = x.Key }) .HandleAsync()); Post("", async args => await For <RequestNewApiKey>() .OnSuccessAccepted("api-keys") .DispatchAsync()); Delete("{name}", async args => await For <DeleteApiKey>() .OnSuccess(HttpStatusCode.NoContent) .DispatchAsync()); }
public ApiKeysModule(ICommandDispatcher commandDispatcher, IIdentityProvider identityProvider, IApiKeyStorage apiKeyStorage) : base(commandDispatcher, identityProvider, modulePath: "api-keys") { Get("", async args => await FetchCollection <BrowseApiKeys, ApiKeyDto> (async x => await apiKeyStorage.BrowseAsync(x)).HandleAsync()); Post("", async args => await For <RequestNewApiKey>() .SetResourceId(x => x.ApiKeyId) .OnSuccessAccepted("api-keys/{0}") .DispatchAsync()); Delete("", async args => await For <DeleteApiKey>() .OnSuccess(HttpStatusCode.NoContent) .DispatchAsync()); }
public async Task ExecuteAsync() { //TODO: Fetch all api keys using pagination. var apiKeys = await _apiKeyStorage.BrowseAsync(new BrowseApiKeys { Page = 1, Results = 1000 }); if (apiKeys.HasNoValue) { return; } if (apiKeys.Value.IsEmpty) { return; } foreach (var apiKey in apiKeys.Value.Items) { _identityProvider.SetUserIdForApiKey(apiKey.Key, apiKey.UserId); } }