Rename GreenField -> Greenfield

This commit is contained in:
nicolas.dorier 2022-01-14 13:05:23 +09:00
parent 7a787fc945
commit 23a96c07ae
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
45 changed files with 96 additions and 96 deletions

View file

@ -52,18 +52,18 @@ namespace BTCPayServer.Client
if (message.StatusCode == System.Net.HttpStatusCode.UnprocessableEntity) if (message.StatusCode == System.Net.HttpStatusCode.UnprocessableEntity)
{ {
var err = JsonConvert.DeserializeObject<Models.GreenfieldValidationError[]>(await message.Content.ReadAsStringAsync()); var err = JsonConvert.DeserializeObject<Models.GreenfieldValidationError[]>(await message.Content.ReadAsStringAsync());
throw new GreenFieldValidationException(err); throw new GreenfieldValidationException(err);
} }
if (message.StatusCode == System.Net.HttpStatusCode.Forbidden) if (message.StatusCode == System.Net.HttpStatusCode.Forbidden)
{ {
var err = JsonConvert.DeserializeObject<Models.GreenfieldPermissionAPIError>(await message.Content.ReadAsStringAsync()); var err = JsonConvert.DeserializeObject<Models.GreenfieldPermissionAPIError>(await message.Content.ReadAsStringAsync());
throw new GreenFieldAPIException((int)message.StatusCode, err); throw new GreenfieldAPIException((int)message.StatusCode, err);
} }
else else
{ {
var err = JsonConvert.DeserializeObject<Models.GreenfieldAPIError>(await message.Content.ReadAsStringAsync()); var err = JsonConvert.DeserializeObject<Models.GreenfieldAPIError>(await message.Content.ReadAsStringAsync());
if (err.Code != null) if (err.Code != null)
throw new GreenFieldAPIException((int)message.StatusCode, err); throw new GreenfieldAPIException((int)message.StatusCode, err);
} }
} }
message.EnsureSuccessStatusCode(); message.EnsureSuccessStatusCode();

View file

@ -2,9 +2,9 @@ using System;
namespace BTCPayServer.Client namespace BTCPayServer.Client
{ {
public class GreenFieldAPIException : Exception public class GreenfieldAPIException : Exception
{ {
public GreenFieldAPIException(int httpCode, Models.GreenfieldAPIError error) : base(error.Message) public GreenfieldAPIException(int httpCode, Models.GreenfieldAPIError error) : base(error.Message)
{ {
if (error == null) if (error == null)
throw new ArgumentNullException(nameof(error)); throw new ArgumentNullException(nameof(error));

View file

@ -4,9 +4,9 @@ using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client
{ {
public class GreenFieldValidationException : Exception public class GreenfieldValidationException : Exception
{ {
public GreenFieldValidationException(Models.GreenfieldValidationError[] errors) : base(BuildMessage(errors)) public GreenfieldValidationException(Models.GreenfieldValidationError[] errors) : base(BuildMessage(errors))
{ {
ValidationErrors = errors; ValidationErrors = errors;
} }

View file

@ -6,7 +6,7 @@ using System.Threading.Tasks;
using BTCPayServer.Client; using BTCPayServer.Client;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Security.GreenField; using BTCPayServer.Security.Greenfield;
using BTCPayServer.Tests.Logging; using BTCPayServer.Tests.Logging;
using BTCPayServer.Views.Manage; using BTCPayServer.Views.Manage;
using Newtonsoft.Json; using Newtonsoft.Json;

View file

@ -602,15 +602,15 @@ namespace BTCPayServer.Tests
return new DateTimeOffset(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, dateTimeOffset.Hour, dateTimeOffset.Minute, dateTimeOffset.Second, dateTimeOffset.Offset); return new DateTimeOffset(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, dateTimeOffset.Hour, dateTimeOffset.Minute, dateTimeOffset.Second, dateTimeOffset.Offset);
} }
private async Task<GreenFieldAPIException> AssertAPIError(string expectedError, Func<Task> act) private async Task<GreenfieldAPIException> AssertAPIError(string expectedError, Func<Task> act)
{ {
var err = await Assert.ThrowsAsync<GreenFieldAPIException>(async () => await act()); var err = await Assert.ThrowsAsync<GreenfieldAPIException>(async () => await act());
Assert.Equal(expectedError, err.APIError.Code); Assert.Equal(expectedError, err.APIError.Code);
return err; return err;
} }
private async Task<GreenFieldAPIException> AssertPermissionError(string expectedPermission, Func<Task> act) private async Task<GreenfieldAPIException> AssertPermissionError(string expectedPermission, Func<Task> act)
{ {
var err = await Assert.ThrowsAsync<GreenFieldAPIException>(async () => await act()); var err = await Assert.ThrowsAsync<GreenfieldAPIException>(async () => await act());
var err2 = Assert.IsType<GreenfieldPermissionAPIError>(err.APIError); var err2 = Assert.IsType<GreenfieldPermissionAPIError>(err.APIError);
Assert.Equal(expectedPermission, err2.MissingPermission); Assert.Equal(expectedPermission, err2.MissingPermission);
return err; return err;
@ -675,10 +675,10 @@ namespace BTCPayServer.Tests
} }
} }
private async Task<GreenFieldValidationException> AssertValidationError(string[] fields, Func<Task> act) private async Task<GreenfieldValidationException> AssertValidationError(string[] fields, Func<Task> act)
{ {
var remainingFields = fields.ToHashSet(); var remainingFields = fields.ToHashSet();
var ex = await Assert.ThrowsAsync<GreenFieldValidationException>(act); var ex = await Assert.ThrowsAsync<GreenfieldValidationException>(act);
foreach (var field in fields) foreach (var field in fields)
{ {
Assert.Contains(field, ex.ValidationErrors.Select(e => e.Path).ToArray()); Assert.Contains(field, ex.ValidationErrors.Select(e => e.Path).ToArray());
@ -690,7 +690,7 @@ namespace BTCPayServer.Tests
private async Task AssertHttpError(int code, Func<Task> act) private async Task AssertHttpError(int code, Func<Task> act)
{ {
var ex = await Assert.ThrowsAsync<GreenFieldAPIException>(act); var ex = await Assert.ThrowsAsync<GreenfieldAPIException>(act);
Assert.Equal(code, ex.HttpCode); Assert.Equal(code, ex.HttpCode);
} }
@ -1496,12 +1496,12 @@ namespace BTCPayServer.Tests
{ {
BOLT11 = merchantInvoice.BOLT11 BOLT11 = merchantInvoice.BOLT11
}); });
await Assert.ThrowsAsync<GreenFieldValidationException>(async () => await client.PayLightningInvoice(user.StoreId, "BTC", new PayLightningInvoiceRequest() await Assert.ThrowsAsync<GreenfieldValidationException>(async () => await client.PayLightningInvoice(user.StoreId, "BTC", new PayLightningInvoiceRequest()
{ {
BOLT11 = "lol" BOLT11 = "lol"
})); }));
var validationErr = await Assert.ThrowsAsync<GreenFieldValidationException>(async () => await client.CreateLightningInvoice(user.StoreId, "BTC", new CreateLightningInvoiceRequest() var validationErr = await Assert.ThrowsAsync<GreenfieldValidationException>(async () => await client.CreateLightningInvoice(user.StoreId, "BTC", new CreateLightningInvoiceRequest()
{ {
Amount = -1, Amount = -1,
Expiry = TimeSpan.FromSeconds(-1), Expiry = TimeSpan.FromSeconds(-1),

View file

@ -3,9 +3,9 @@ using BTCPayServer.Client.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
public static class GreenFieldUtils public static class GreenfieldUtils
{ {
public static IActionResult CreateValidationError(this ControllerBase controller, ModelStateDictionary modelState) public static IActionResult CreateValidationError(this ControllerBase controller, ModelStateDictionary modelState)
{ {

View file

@ -5,7 +5,7 @@ using BTCPayServer.Client;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Security; using BTCPayServer.Security;
using BTCPayServer.Security.GreenField; using BTCPayServer.Security.Greenfield;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Mvc;
using NBitcoin; using NBitcoin;
using NBitcoin.DataEncoders; using NBitcoin.DataEncoders;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.GreenfieldAPIKeys)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.GreenfieldAPIKeys)]

View file

@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[Controller] [Controller]
[EnableCors(CorsPolicies.All)] [EnableCors(CorsPolicies.All)]

View file

@ -17,7 +17,7 @@ using NBitcoin;
using CreateInvoiceRequest = BTCPayServer.Client.Models.CreateInvoiceRequest; using CreateInvoiceRequest = BTCPayServer.Client.Models.CreateInvoiceRequest;
using InvoiceData = BTCPayServer.Client.Models.InvoiceData; using InvoiceData = BTCPayServer.Client.Models.InvoiceData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -17,7 +17,7 @@ using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
public class LightningUnavailableExceptionFilter : Attribute, IExceptionFilter public class LightningUnavailableExceptionFilter : Attribute, IExceptionFilter
{ {

View file

@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NotificationData = BTCPayServer.Client.Models.NotificationData; using NotificationData = BTCPayServer.Client.Models.NotificationData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PaymentRequestData = BTCPayServer.Data.PaymentRequestData; using PaymentRequestData = BTCPayServer.Data.PaymentRequestData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -18,7 +18,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[EnableCors(CorsPolicies.All)] [EnableCors(CorsPolicies.All)]

View file

@ -20,7 +20,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using StoreData = BTCPayServer.Data.StoreData; using StoreData = BTCPayServer.Data.StoreData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -20,7 +20,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using StoreData = BTCPayServer.Data.StoreData; using StoreData = BTCPayServer.Data.StoreData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NBXplorer.Models; using NBXplorer.Models;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
public partial class GreenfieldStoreOnChainPaymentMethodsController public partial class GreenfieldStoreOnChainPaymentMethodsController
{ {

View file

@ -17,7 +17,7 @@ using NBXplorer.DerivationStrategy;
using NBXplorer.Models; using NBXplorer.Models;
using StoreData = BTCPayServer.Data.StoreData; using StoreData = BTCPayServer.Data.StoreData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -28,7 +28,7 @@ using NBXplorer.Models;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using StoreData = BTCPayServer.Data.StoreData; using StoreData = BTCPayServer.Data.StoreData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
@ -353,7 +353,7 @@ namespace BTCPayServer.Controllers.GreenField
request.AddModelError(transactionRequest => transactionRequest.Destinations[index], request.AddModelError(transactionRequest => transactionRequest.Destinations[index],
"Amount must be specified or destination must be a BIP21 payment link, and greater than 0", this); "Amount must be specified or destination must be a BIP21 payment link, and greater than 0", this);
} }
if (request.ProceedWithPayjoin && bip21?.UnknowParameters?.ContainsKey(PayjoinClient.BIP21EndpointKey) is true) if (request.ProceedWithPayjoin && bip21?.UnknownParameters?.ContainsKey(PayjoinClient.BIP21EndpointKey) is true)
{ {
payjoinOutputIndex = index; payjoinOutputIndex = index;
} }

View file

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using StoreData = BTCPayServer.Data.StoreData; using StoreData = BTCPayServer.Data.StoreData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -18,7 +18,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield, [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield,

View file

@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using StoreData = BTCPayServer.Data.StoreData; using StoreData = BTCPayServer.Data.StoreData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]

View file

@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
/// <summary> /// <summary>
/// this controller serves as a testing endpoint for our api key unit tests /// this controller serves as a testing endpoint for our api key unit tests

View file

@ -12,7 +12,7 @@ using BTCPayServer.Events;
using BTCPayServer.HostedServices; using BTCPayServer.HostedServices;
using BTCPayServer.Logging; using BTCPayServer.Logging;
using BTCPayServer.Security; using BTCPayServer.Security;
using BTCPayServer.Security.GreenField; using BTCPayServer.Security.Greenfield;
using BTCPayServer.Services; using BTCPayServer.Services;
using BTCPayServer.Services.Stores; using BTCPayServer.Services.Stores;
using BTCPayServer.Storage.Services; using BTCPayServer.Storage.Services;
@ -22,7 +22,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NicolasDorier.RateLimits; using NicolasDorier.RateLimits;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
[ApiController] [ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
@ -99,7 +99,7 @@ namespace BTCPayServer.Controllers.GreenField
throw new JsonHttpException(this.StatusCode(401)); throw new JsonHttpException(this.StatusCode(401));
var anyAdmin = (await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin)).Any(); var anyAdmin = (await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin)).Any();
var policies = await _settingsRepository.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings(); var policies = await _settingsRepository.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings();
var isAuth = User.Identity.AuthenticationType == GreenFieldConstants.AuthenticationType; var isAuth = User.Identity.AuthenticationType == GreenfieldConstants.AuthenticationType;
// If registration are locked and that an admin exists, don't accept unauthenticated connection // If registration are locked and that an admin exists, don't accept unauthenticated connection
if (anyAdmin && policies.LockSubscription && !isAuth) if (anyAdmin && policies.LockSubscription && !isAuth)

View file

@ -9,7 +9,7 @@ using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Client; using BTCPayServer.Client;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Security.GreenField; using BTCPayServer.Security.Greenfield;
using BTCPayServer.Services.Stores; using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
@ -27,7 +27,7 @@ using StoreData = BTCPayServer.Client.Models.StoreData;
using StoreWebhookData = BTCPayServer.Client.Models.StoreWebhookData; using StoreWebhookData = BTCPayServer.Client.Models.StoreWebhookData;
using WebhookDeliveryData = BTCPayServer.Client.Models.WebhookDeliveryData; using WebhookDeliveryData = BTCPayServer.Client.Models.WebhookDeliveryData;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.Greenfield
{ {
public class BTCPayServerClientFactory : IBTCPayServerClientFactory public class BTCPayServerClientFactory : IBTCPayServerClientFactory
{ {
@ -107,18 +107,18 @@ namespace BTCPayServer.Controllers.GreenField
List<Claim> claims = new List<Claim> List<Claim> claims = new List<Claim>
{ {
new Claim(_identityOptions.CurrentValue.ClaimsIdentity.UserIdClaimType, userId), new Claim(_identityOptions.CurrentValue.ClaimsIdentity.UserIdClaimType, userId),
new Claim(GreenFieldConstants.ClaimTypes.Permission, new Claim(GreenfieldConstants.ClaimTypes.Permission,
Permission.Create(Policies.Unrestricted).ToString()) Permission.Create(Policies.Unrestricted).ToString())
}; };
claims.AddRange((await _userManager.GetRolesAsync(user)).Select(s => claims.AddRange((await _userManager.GetRolesAsync(user)).Select(s =>
new Claim(_identityOptions.CurrentValue.ClaimsIdentity.RoleClaimType, s))); new Claim(_identityOptions.CurrentValue.ClaimsIdentity.RoleClaimType, s)));
context.User = context.User =
new ClaimsPrincipal(new ClaimsIdentity(claims, GreenFieldConstants.AuthenticationType)); new ClaimsPrincipal(new ClaimsIdentity(claims, GreenfieldConstants.AuthenticationType));
} }
else else
{ {
context.User = context.User =
new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>(), $"Local{GreenFieldConstants.AuthenticationType}")); new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>(), $"Local{GreenfieldConstants.AuthenticationType}"));
} }
if (storeIds?.Any() is true) if (storeIds?.Any() is true)
@ -484,11 +484,11 @@ namespace BTCPayServer.Controllers.GreenField
switch (result) switch (result)
{ {
case UnprocessableEntityObjectResult { Value: List<GreenfieldValidationError> validationErrors }: case UnprocessableEntityObjectResult { Value: List<GreenfieldValidationError> validationErrors }:
throw new GreenFieldValidationException(validationErrors.ToArray()); throw new GreenfieldValidationException(validationErrors.ToArray());
case BadRequestObjectResult { Value: GreenfieldAPIError error }: case BadRequestObjectResult { Value: GreenfieldAPIError error }:
throw new GreenFieldAPIException(400, error); throw new GreenfieldAPIException(400, error);
case NotFoundResult _: case NotFoundResult _:
throw new GreenFieldAPIException(404, new GreenfieldAPIError("not-found", "")); throw new GreenfieldAPIException(404, new GreenfieldAPIError("not-found", ""));
default: default:
return; return;
} }

View file

@ -8,7 +8,7 @@ using BTCPayServer.Abstractions.Models;
using BTCPayServer.Client; using BTCPayServer.Client;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Models; using BTCPayServer.Models;
using BTCPayServer.Security.GreenField; using BTCPayServer.Security.Greenfield;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NBitcoin; using NBitcoin;

View file

@ -7,7 +7,7 @@ using BTCPayServer.Data;
using BTCPayServer.Fido2; using BTCPayServer.Fido2;
using BTCPayServer.Models; using BTCPayServer.Models;
using BTCPayServer.Models.ManageViewModels; using BTCPayServer.Models.ManageViewModels;
using BTCPayServer.Security.GreenField; using BTCPayServer.Security.Greenfield;
using BTCPayServer.Services; using BTCPayServer.Services;
using BTCPayServer.Services.Mails; using BTCPayServer.Services.Mails;
using BTCPayServer.Services.Stores; using BTCPayServer.Services.Stores;

View file

@ -3,7 +3,7 @@ using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants; using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Client; using BTCPayServer.Client;
using BTCPayServer.Security.Bitpay; using BTCPayServer.Security.Bitpay;
using BTCPayServer.Security.GreenField; using BTCPayServer.Security.Greenfield;
using BTCPayServer.Services; using BTCPayServer.Services;
using CsvHelper.Configuration.Attributes; using CsvHelper.Configuration.Attributes;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -26,7 +26,7 @@ namespace BTCPayServer
bool isAdmin = false; bool isAdmin = false;
if (claimUser.AuthenticationType == AuthenticationSchemes.Cookie) if (claimUser.AuthenticationType == AuthenticationSchemes.Cookie)
isAdmin = user.IsInRole(Roles.ServerAdmin); isAdmin = user.IsInRole(Roles.ServerAdmin);
else if (claimUser.AuthenticationType == GreenFieldConstants.AuthenticationType) else if (claimUser.AuthenticationType == GreenfieldConstants.AuthenticationType)
isAdmin = (await authorizationService.AuthorizeAsync(user, Policies.CanModifyServerSettings)).Succeeded; isAdmin = (await authorizationService.AuthorizeAsync(user, Policies.CanModifyServerSettings)).Succeeded;
return isAdmin ? (true, true) : return isAdmin ? (true, true) :
(policiesSettings?.AllowHotWalletForAll is true, policiesSettings?.AllowHotWalletRPCImportForAll is true); (policiesSettings?.AllowHotWalletForAll is true, policiesSettings?.AllowHotWalletRPCImportForAll is true);

View file

@ -9,7 +9,7 @@ using System.Threading;
using System.Threading.Channels; using System.Threading.Channels;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.Controllers.GreenField; using BTCPayServer.Controllers.Greenfield;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Events; using BTCPayServer.Events;
using BTCPayServer.Logging; using BTCPayServer.Logging;

View file

@ -10,7 +10,7 @@ using BTCPayServer.Client;
using BTCPayServer.Common; using BTCPayServer.Common;
using BTCPayServer.Configuration; using BTCPayServer.Configuration;
using BTCPayServer.Controllers; using BTCPayServer.Controllers;
using BTCPayServer.Controllers.GreenField; using BTCPayServer.Controllers.Greenfield;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Data.Payouts.LightningLike; using BTCPayServer.Data.Payouts.LightningLike;
using BTCPayServer.HostedServices; using BTCPayServer.HostedServices;
@ -24,7 +24,7 @@ using BTCPayServer.Payments.PayJoin;
using BTCPayServer.Plugins; using BTCPayServer.Plugins;
using BTCPayServer.Security; using BTCPayServer.Security;
using BTCPayServer.Security.Bitpay; using BTCPayServer.Security.Bitpay;
using BTCPayServer.Security.GreenField; using BTCPayServer.Security.Greenfield;
using BTCPayServer.Services; using BTCPayServer.Services;
using BTCPayServer.Services.Apps; using BTCPayServer.Services.Apps;
using BTCPayServer.Services.Fees; using BTCPayServer.Services.Fees;

View file

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.Security.GreenField; using BTCPayServer.Security.Greenfield;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Infrastructure;
@ -35,7 +35,7 @@ namespace BTCPayServer.Hosting
(httpContext.Response.StatusCode == 401 || httpContext.Response.StatusCode == 403)) (httpContext.Response.StatusCode == 401 || httpContext.Response.StatusCode == 403))
{ {
if (httpContext.Response.StatusCode == 403 && if (httpContext.Response.StatusCode == 403 &&
httpContext.Items.TryGetValue(GreenFieldAuthorizationHandler.RequestedPermissionKey, out var p) && httpContext.Items.TryGetValue(GreenfieldAuthorizationHandler.RequestedPermissionKey, out var p) &&
p is string policy) p is string policy)
{ {
var outputObj = new GreenfieldPermissionAPIError(policy); var outputObj = new GreenfieldPermissionAPIError(policy);

View file

@ -4,7 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using BTCPayServer.Configuration; using BTCPayServer.Configuration;
using BTCPayServer.Controllers.GreenField; using BTCPayServer.Controllers.Greenfield;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Fido2; using BTCPayServer.Fido2;
using BTCPayServer.Filters; using BTCPayServer.Filters;

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.Controllers.GreenField; using BTCPayServer.Controllers.Greenfield;
using BTCPayServer.Payments.Lightning; using BTCPayServer.Payments.Lightning;
using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Invoices;
using NBitcoin; using NBitcoin;

View file

@ -1,6 +1,6 @@
using System; using System;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.Controllers.GreenField; using BTCPayServer.Controllers.Greenfield;
using BTCPayServer.Payments.Lightning; using BTCPayServer.Payments.Lightning;
using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Invoices;
using NBitcoin; using NBitcoin;

View file

@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
namespace BTCPayServer.Security.GreenField namespace BTCPayServer.Security.Greenfield
{ {
public static class APIKeyExtensions public static class APIKeyExtensions
{ {
@ -26,9 +26,9 @@ namespace BTCPayServer.Security.GreenField
public static AuthenticationBuilder AddAPIKeyAuthentication(this AuthenticationBuilder builder) public static AuthenticationBuilder AddAPIKeyAuthentication(this AuthenticationBuilder builder)
{ {
builder.AddScheme<GreenFieldAuthenticationOptions, APIKeysAuthenticationHandler>(AuthenticationSchemes.GreenfieldAPIKeys, builder.AddScheme<GreenfieldAuthenticationOptions, APIKeysAuthenticationHandler>(AuthenticationSchemes.GreenfieldAPIKeys,
o => { }); o => { });
builder.AddScheme<GreenFieldAuthenticationOptions, BasicAuthenticationHandler>(AuthenticationSchemes.GreenfieldBasic, builder.AddScheme<GreenfieldAuthenticationOptions, BasicAuthenticationHandler>(AuthenticationSchemes.GreenfieldBasic,
o => { }); o => { });
return builder; return builder;
} }
@ -36,15 +36,15 @@ namespace BTCPayServer.Security.GreenField
public static IServiceCollection AddAPIKeyAuthentication(this IServiceCollection serviceCollection) public static IServiceCollection AddAPIKeyAuthentication(this IServiceCollection serviceCollection)
{ {
serviceCollection.AddSingleton<APIKeyRepository>(); serviceCollection.AddSingleton<APIKeyRepository>();
serviceCollection.AddScoped<IAuthorizationHandler, GreenFieldAuthorizationHandler>(); serviceCollection.AddScoped<IAuthorizationHandler, GreenfieldAuthorizationHandler>();
serviceCollection.AddScoped<IAuthorizationHandler, LocalGreenFieldAuthorizationHandler>(); serviceCollection.AddScoped<IAuthorizationHandler, LocalGreenfieldAuthorizationHandler>();
return serviceCollection; return serviceCollection;
} }
public static string[] GetPermissions(this AuthorizationHandlerContext context) public static string[] GetPermissions(this AuthorizationHandlerContext context)
{ {
return context.User.Claims.Where(c => return context.User.Claims.Where(c =>
c.Type.Equals(GreenFieldConstants.ClaimTypes.Permission, StringComparison.InvariantCultureIgnoreCase)) c.Type.Equals(GreenfieldConstants.ClaimTypes.Permission, StringComparison.InvariantCultureIgnoreCase))
.Select(claim => claim.Value).ToArray(); .Select(claim => claim.Value).ToArray();
} }
public static bool HasPermission(this AuthorizationHandlerContext context, Permission permission) public static bool HasPermission(this AuthorizationHandlerContext context, Permission permission)
@ -54,7 +54,7 @@ namespace BTCPayServer.Security.GreenField
public static bool HasPermission(this AuthorizationHandlerContext context, Permission permission, bool requireUnscoped) public static bool HasPermission(this AuthorizationHandlerContext context, Permission permission, bool requireUnscoped)
{ {
foreach (var claim in context.User.Claims.Where(c => foreach (var claim in context.User.Claims.Where(c =>
c.Type.Equals(GreenFieldConstants.ClaimTypes.Permission, StringComparison.InvariantCultureIgnoreCase))) c.Type.Equals(GreenfieldConstants.ClaimTypes.Permission, StringComparison.InvariantCultureIgnoreCase)))
{ {
if (Permission.TryParse(claim.Value, out var claimPermission)) if (Permission.TryParse(claim.Value, out var claimPermission))
{ {

View file

@ -5,7 +5,7 @@ using System.Threading.Tasks;
using BTCPayServer.Data; using BTCPayServer.Data;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace BTCPayServer.Security.GreenField namespace BTCPayServer.Security.Greenfield
{ {
public class APIKeyRepository public class APIKeyRepository
{ {

View file

@ -10,9 +10,9 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace BTCPayServer.Security.GreenField namespace BTCPayServer.Security.Greenfield
{ {
public class APIKeysAuthenticationHandler : AuthenticationHandler<GreenFieldAuthenticationOptions> public class APIKeysAuthenticationHandler : AuthenticationHandler<GreenfieldAuthenticationOptions>
{ {
private readonly APIKeyRepository _apiKeyRepository; private readonly APIKeyRepository _apiKeyRepository;
private readonly IOptionsMonitor<IdentityOptions> _identityOptions; private readonly IOptionsMonitor<IdentityOptions> _identityOptions;
@ -21,7 +21,7 @@ namespace BTCPayServer.Security.GreenField
public APIKeysAuthenticationHandler( public APIKeysAuthenticationHandler(
APIKeyRepository apiKeyRepository, APIKeyRepository apiKeyRepository,
IOptionsMonitor<IdentityOptions> identityOptions, IOptionsMonitor<IdentityOptions> identityOptions,
IOptionsMonitor<GreenFieldAuthenticationOptions> options, IOptionsMonitor<GreenfieldAuthenticationOptions> options,
ILoggerFactory logger, ILoggerFactory logger,
UrlEncoder encoder, UrlEncoder encoder,
ISystemClock clock, ISystemClock clock,
@ -48,10 +48,10 @@ namespace BTCPayServer.Security.GreenField
claims.AddRange((await _userManager.GetRolesAsync(key.User)).Select(s => new Claim(_identityOptions.CurrentValue.ClaimsIdentity.RoleClaimType, s))); claims.AddRange((await _userManager.GetRolesAsync(key.User)).Select(s => new Claim(_identityOptions.CurrentValue.ClaimsIdentity.RoleClaimType, s)));
claims.AddRange(Permission.ToPermissions(key.GetBlob().Permissions).Select(permission => claims.AddRange(Permission.ToPermissions(key.GetBlob().Permissions).Select(permission =>
new Claim(GreenFieldConstants.ClaimTypes.Permission, permission.ToString()))); new Claim(GreenfieldConstants.ClaimTypes.Permission, permission.ToString())));
return AuthenticateResult.Success(new AuthenticationTicket( return AuthenticateResult.Success(new AuthenticationTicket(
new ClaimsPrincipal(new ClaimsIdentity(claims, GreenFieldConstants.AuthenticationType)), new ClaimsPrincipal(new ClaimsIdentity(claims, GreenfieldConstants.AuthenticationType)),
GreenFieldConstants.AuthenticationType)); GreenfieldConstants.AuthenticationType));
} }
} }
} }

View file

@ -13,9 +13,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace BTCPayServer.Security.GreenField namespace BTCPayServer.Security.Greenfield
{ {
public class BasicAuthenticationHandler : AuthenticationHandler<GreenFieldAuthenticationOptions> public class BasicAuthenticationHandler : AuthenticationHandler<GreenfieldAuthenticationOptions>
{ {
private readonly IOptionsMonitor<IdentityOptions> _identityOptions; private readonly IOptionsMonitor<IdentityOptions> _identityOptions;
private readonly SignInManager<ApplicationUser> _signInManager; private readonly SignInManager<ApplicationUser> _signInManager;
@ -23,7 +23,7 @@ namespace BTCPayServer.Security.GreenField
public BasicAuthenticationHandler( public BasicAuthenticationHandler(
IOptionsMonitor<IdentityOptions> identityOptions, IOptionsMonitor<IdentityOptions> identityOptions,
IOptionsMonitor<GreenFieldAuthenticationOptions> options, IOptionsMonitor<GreenfieldAuthenticationOptions> options,
ILoggerFactory logger, ILoggerFactory logger,
UrlEncoder encoder, UrlEncoder encoder,
ISystemClock clock, ISystemClock clock,
@ -74,14 +74,14 @@ namespace BTCPayServer.Security.GreenField
var claims = new List<Claim>() var claims = new List<Claim>()
{ {
new Claim(_identityOptions.CurrentValue.ClaimsIdentity.UserIdClaimType, user.Id), new Claim(_identityOptions.CurrentValue.ClaimsIdentity.UserIdClaimType, user.Id),
new Claim(GreenFieldConstants.ClaimTypes.Permission, new Claim(GreenfieldConstants.ClaimTypes.Permission,
Permission.Create(Policies.Unrestricted).ToString()) Permission.Create(Policies.Unrestricted).ToString())
}; };
claims.AddRange((await _userManager.GetRolesAsync(user)).Select(s => new Claim(_identityOptions.CurrentValue.ClaimsIdentity.RoleClaimType, s))); claims.AddRange((await _userManager.GetRolesAsync(user)).Select(s => new Claim(_identityOptions.CurrentValue.ClaimsIdentity.RoleClaimType, s)));
return AuthenticateResult.Success(new AuthenticationTicket( return AuthenticateResult.Success(new AuthenticationTicket(
new ClaimsPrincipal(new ClaimsIdentity(claims, GreenFieldConstants.AuthenticationType)), new ClaimsPrincipal(new ClaimsIdentity(claims, GreenfieldConstants.AuthenticationType)),
GreenFieldConstants.AuthenticationType)); GreenfieldConstants.AuthenticationType));
} }
} }
} }

View file

@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
namespace BTCPayServer.Security.GreenField namespace BTCPayServer.Security.Greenfield
{ {
public class GreenFieldAuthenticationOptions : AuthenticationSchemeOptions public class GreenfieldAuthenticationOptions : AuthenticationSchemeOptions
{ {
} }
} }

View file

@ -13,13 +13,13 @@ using Microsoft.AspNetCore.Identity;
using Newtonsoft.Json; using Newtonsoft.Json;
using StoreData = BTCPayServer.Data.StoreData; using StoreData = BTCPayServer.Data.StoreData;
namespace BTCPayServer.Security.GreenField namespace BTCPayServer.Security.Greenfield
{ {
public class LocalGreenFieldAuthorizationHandler : AuthorizationHandler<PolicyRequirement> public class LocalGreenfieldAuthorizationHandler : AuthorizationHandler<PolicyRequirement>
{ {
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, PolicyRequirement requirement) protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, PolicyRequirement requirement)
{ {
var succeed = context.User.Identity.AuthenticationType == $"Local{GreenFieldConstants.AuthenticationType}"; var succeed = context.User.Identity.AuthenticationType == $"Local{GreenfieldConstants.AuthenticationType}";
if (succeed) if (succeed)
{ {
@ -29,14 +29,14 @@ namespace BTCPayServer.Security.GreenField
} }
} }
public class GreenFieldAuthorizationHandler : AuthorizationHandler<PolicyRequirement> public class GreenfieldAuthorizationHandler : AuthorizationHandler<PolicyRequirement>
{ {
private readonly HttpContext _HttpContext; private readonly HttpContext _HttpContext;
private readonly UserManager<ApplicationUser> _userManager; private readonly UserManager<ApplicationUser> _userManager;
private readonly StoreRepository _storeRepository; private readonly StoreRepository _storeRepository;
public GreenFieldAuthorizationHandler(IHttpContextAccessor httpContextAccessor, public GreenfieldAuthorizationHandler(IHttpContextAccessor httpContextAccessor,
UserManager<ApplicationUser> userManager, UserManager<ApplicationUser> userManager,
StoreRepository storeRepository) StoreRepository storeRepository)
{ {
@ -48,7 +48,7 @@ namespace BTCPayServer.Security.GreenField
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context,
PolicyRequirement requirement) PolicyRequirement requirement)
{ {
if (context.User.Identity.AuthenticationType != GreenFieldConstants.AuthenticationType) if (context.User.Identity.AuthenticationType != GreenfieldConstants.AuthenticationType)
return; return;
var userid = _userManager.GetUserId(context.User); var userid = _userManager.GetUserId(context.User);
bool success = false; bool success = false;

View file

@ -1,8 +1,8 @@
namespace BTCPayServer.Security.GreenField namespace BTCPayServer.Security.Greenfield
{ {
public static class GreenFieldConstants public static class GreenfieldConstants
{ {
public const string AuthenticationType = "GreenField"; public const string AuthenticationType = "Greenfield";
public static class ClaimTypes public static class ClaimTypes
{ {

View file

@ -1,6 +1,6 @@
@using BTCPayServer.Client @using BTCPayServer.Client
@using BTCPayServer.Controllers @using BTCPayServer.Controllers
@using BTCPayServer.Security.GreenField @using BTCPayServer.Security.Greenfield
@model UIManageController.AddApiKeyViewModel @model UIManageController.AddApiKeyViewModel
@{ @{

View file

@ -1,6 +1,6 @@
@using BTCPayServer.Client @using BTCPayServer.Client
@using BTCPayServer.Controllers @using BTCPayServer.Controllers
@using BTCPayServer.Security.GreenField @using BTCPayServer.Security.Greenfield
@model BTCPayServer.Controllers.UIManageController.AuthorizeApiKeysViewModel @model BTCPayServer.Controllers.UIManageController.AuthorizeApiKeysViewModel
@{ @{