mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Remove the Facade concept
This commit is contained in:
@@ -518,7 +518,6 @@ namespace BTCPayServer.Tests
|
|||||||
var controller = acc.GetController<StoresController>();
|
var controller = acc.GetController<StoresController>();
|
||||||
var token = (RedirectToActionResult)controller.CreateToken(new Models.StoreViewModels.CreateTokenViewModel()
|
var token = (RedirectToActionResult)controller.CreateToken(new Models.StoreViewModels.CreateTokenViewModel()
|
||||||
{
|
{
|
||||||
Facade = Facade.Merchant.ToString(),
|
|
||||||
Label = "bla",
|
Label = "bla",
|
||||||
PublicKey = null
|
PublicKey = null
|
||||||
}).GetAwaiter().GetResult();
|
}).GetAwaiter().GetResult();
|
||||||
@@ -972,7 +971,6 @@ namespace BTCPayServer.Tests
|
|||||||
var storeController = user.GetController<StoresController>();
|
var storeController = user.GetController<StoresController>();
|
||||||
storeController.CreateToken(new CreateTokenViewModel()
|
storeController.CreateToken(new CreateTokenViewModel()
|
||||||
{
|
{
|
||||||
Facade = Facade.Merchant.ToString(),
|
|
||||||
Label = "test2",
|
Label = "test2",
|
||||||
StoreId = user.StoreId
|
StoreId = user.StoreId
|
||||||
}).GetAwaiter().GetResult();
|
}).GetAwaiter().GetResult();
|
||||||
|
|||||||
@@ -8,10 +8,6 @@ namespace BTCPayServer.Authentication
|
|||||||
{
|
{
|
||||||
public class BitTokenEntity
|
public class BitTokenEntity
|
||||||
{
|
{
|
||||||
public string Facade
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
public string Value
|
public string Value
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
@@ -39,7 +35,6 @@ namespace BTCPayServer.Authentication
|
|||||||
return new BitTokenEntity()
|
return new BitTokenEntity()
|
||||||
{
|
{
|
||||||
Label = Label,
|
Label = Label,
|
||||||
Facade = Facade,
|
|
||||||
StoreId = StoreId,
|
StoreId = StoreId,
|
||||||
PairingTime = PairingTime,
|
PairingTime = PairingTime,
|
||||||
SIN = SIN,
|
SIN = SIN,
|
||||||
|
|||||||
@@ -11,11 +11,6 @@ namespace BTCPayServer.Authentication
|
|||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
public string Facade
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
public string Label
|
public string Label
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ namespace BTCPayServer.Authentication
|
|||||||
return new BitTokenEntity()
|
return new BitTokenEntity()
|
||||||
{
|
{
|
||||||
Label = data.Label,
|
Label = data.Label,
|
||||||
Facade = data.Facade,
|
|
||||||
Value = data.Id,
|
Value = data.Id,
|
||||||
SIN = data.SIN,
|
SIN = data.SIN,
|
||||||
PairingTime = data.PairingTime,
|
PairingTime = data.PairingTime,
|
||||||
@@ -129,7 +128,6 @@ namespace BTCPayServer.Authentication
|
|||||||
{
|
{
|
||||||
var pairingCode = await ctx.PairingCodes.FindAsync(pairingCodeEntity.Id);
|
var pairingCode = await ctx.PairingCodes.FindAsync(pairingCodeEntity.Id);
|
||||||
pairingCode.Label = pairingCodeEntity.Label;
|
pairingCode.Label = pairingCodeEntity.Label;
|
||||||
pairingCode.Facade = pairingCodeEntity.Facade;
|
|
||||||
await ctx.SaveChangesAsync();
|
await ctx.SaveChangesAsync();
|
||||||
return CreatePairingCodeEntity(pairingCode);
|
return CreatePairingCodeEntity(pairingCode);
|
||||||
}
|
}
|
||||||
@@ -178,7 +176,6 @@ namespace BTCPayServer.Authentication
|
|||||||
{
|
{
|
||||||
Id = pairingCode.TokenValue,
|
Id = pairingCode.TokenValue,
|
||||||
PairingTime = DateTime.UtcNow,
|
PairingTime = DateTime.UtcNow,
|
||||||
Facade = pairingCode.Facade,
|
|
||||||
Label = pairingCode.Label,
|
Label = pairingCode.Label,
|
||||||
StoreDataId = pairingCode.StoreDataId,
|
StoreDataId = pairingCode.StoreDataId,
|
||||||
SIN = pairingCode.SIN
|
SIN = pairingCode.SIN
|
||||||
@@ -213,7 +210,6 @@ namespace BTCPayServer.Authentication
|
|||||||
return null;
|
return null;
|
||||||
return new PairingCodeEntity()
|
return new PairingCodeEntity()
|
||||||
{
|
{
|
||||||
Facade = data.Facade,
|
|
||||||
Id = data.Id,
|
Id = data.Id,
|
||||||
Label = data.Label,
|
Label = data.Label,
|
||||||
Expiration = data.Expiration,
|
Expiration = data.Expiration,
|
||||||
|
|||||||
@@ -42,15 +42,12 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(request.Id) || !NBitpayClient.Extensions.BitIdExtensions.ValidateSIN(request.Id))
|
if (string.IsNullOrEmpty(request.Id) || !NBitpayClient.Extensions.BitIdExtensions.ValidateSIN(request.Id))
|
||||||
throw new BitpayHttpException(400, "'id' property is required");
|
throw new BitpayHttpException(400, "'id' property is required");
|
||||||
if (string.IsNullOrEmpty(request.Facade))
|
|
||||||
throw new BitpayHttpException(400, "'facade' property is required");
|
|
||||||
|
|
||||||
var pairingCode = await _TokenRepository.CreatePairingCodeAsync();
|
var pairingCode = await _TokenRepository.CreatePairingCodeAsync();
|
||||||
await _TokenRepository.PairWithSINAsync(pairingCode, request.Id);
|
await _TokenRepository.PairWithSINAsync(pairingCode, request.Id);
|
||||||
pairingEntity = await _TokenRepository.UpdatePairingCode(new PairingCodeEntity()
|
pairingEntity = await _TokenRepository.UpdatePairingCode(new PairingCodeEntity()
|
||||||
{
|
{
|
||||||
Id = pairingCode,
|
Id = pairingCode,
|
||||||
Facade = request.Facade,
|
|
||||||
Label = request.Label
|
Label = request.Label
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -86,7 +83,7 @@ namespace BTCPayServer.Controllers
|
|||||||
PairingCode = pairingEntity.Id,
|
PairingCode = pairingEntity.Id,
|
||||||
PairingExpiration = pairingEntity.Expiration,
|
PairingExpiration = pairingEntity.Expiration,
|
||||||
DateCreated = pairingEntity.CreatedTime,
|
DateCreated = pairingEntity.CreatedTime,
|
||||||
Facade = pairingEntity.Facade,
|
Facade = "merchant",
|
||||||
Token = pairingEntity.TokenValue,
|
Token = pairingEntity.TokenValue,
|
||||||
Label = pairingEntity.Label
|
Label = pairingEntity.Label
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -613,7 +613,6 @@ namespace BTCPayServer.Controllers
|
|||||||
model.StoreNotConfigured = StoreNotConfigured;
|
model.StoreNotConfigured = StoreNotConfigured;
|
||||||
model.Tokens = tokens.Select(t => new TokenViewModel()
|
model.Tokens = tokens.Select(t => new TokenViewModel()
|
||||||
{
|
{
|
||||||
Facade = t.Facade,
|
|
||||||
Label = t.Label,
|
Label = t.Label,
|
||||||
SIN = t.SIN,
|
SIN = t.SIN,
|
||||||
Id = t.Value
|
Id = t.Value
|
||||||
@@ -698,7 +697,6 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
var tokenRequest = new TokenRequest()
|
var tokenRequest = new TokenRequest()
|
||||||
{
|
{
|
||||||
Facade = model.Facade,
|
|
||||||
Label = model.Label,
|
Label = model.Label,
|
||||||
Id = model.PublicKey == null ? null : NBitpayClient.Extensions.BitIdExtensions.GetBitIDSIN(new PubKey(model.PublicKey))
|
Id = model.PublicKey == null ? null : NBitpayClient.Extensions.BitIdExtensions.GetBitIDSIN(new PubKey(model.PublicKey))
|
||||||
};
|
};
|
||||||
@@ -710,7 +708,6 @@ namespace BTCPayServer.Controllers
|
|||||||
await _TokenRepository.UpdatePairingCode(new PairingCodeEntity()
|
await _TokenRepository.UpdatePairingCode(new PairingCodeEntity()
|
||||||
{
|
{
|
||||||
Id = tokenRequest.PairingCode,
|
Id = tokenRequest.PairingCode,
|
||||||
Facade = model.Facade,
|
|
||||||
Label = model.Label,
|
Label = model.Label,
|
||||||
});
|
});
|
||||||
await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, storeId);
|
await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, storeId);
|
||||||
@@ -750,7 +747,6 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var model = new CreateTokenViewModel();
|
var model = new CreateTokenViewModel();
|
||||||
model.Facade = "merchant";
|
|
||||||
ViewBag.HidePublicKey = storeId == null;
|
ViewBag.HidePublicKey = storeId == null;
|
||||||
ViewBag.ShowStores = storeId == null;
|
ViewBag.ShowStores = storeId == null;
|
||||||
ViewBag.ShowMenu = storeId != null;
|
ViewBag.ShowMenu = storeId != null;
|
||||||
@@ -802,7 +798,6 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(new PairingModel()
|
return View(new PairingModel()
|
||||||
{
|
{
|
||||||
Id = pairing.Id,
|
Id = pairing.Id,
|
||||||
Facade = pairing.Facade,
|
|
||||||
Label = pairing.Label,
|
Label = pairing.Label,
|
||||||
SIN = pairing.SIN ?? "Server-Initiated Pairing",
|
SIN = pairing.SIN ?? "Server-Initiated Pairing",
|
||||||
SelectedStore = selectedStore ?? stores.FirstOrDefault()?.Id,
|
SelectedStore = selectedStore ?? stores.FirstOrDefault()?.Id,
|
||||||
|
|||||||
@@ -12,11 +12,6 @@ namespace BTCPayServer.Data
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Facade
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string StoreDataId
|
public string StoreDataId
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace BTCPayServer.Data
|
|||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
[Obsolete("Unused")]
|
||||||
public string Facade
|
public string Facade
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace BTCPayServer.Models
|
|||||||
{
|
{
|
||||||
JObject item = new JObject();
|
JObject item = new JObject();
|
||||||
jarray.Add(item);
|
jarray.Add(item);
|
||||||
JProperty jProp = new JProperty(token.Facade);
|
JProperty jProp = new JProperty("merchant");
|
||||||
item.Add(jProp);
|
item.Add(jProp);
|
||||||
jProp.Value = token.Value;
|
jProp.Value = token.Value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
public string Facade
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
public string SIN
|
public string SIN
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
|
|||||||
@@ -21,12 +21,6 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string Facade
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string StoreId
|
public string StoreId
|
||||||
{
|
{
|
||||||
@@ -52,10 +46,6 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
public string Facade
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public class TokensViewModel
|
public class TokensViewModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,11 +20,6 @@ namespace BTCPayServer.Models
|
|||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
[JsonProperty(PropertyName = "facade")]
|
|
||||||
public string Facade
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
[JsonProperty(PropertyName = "count")]
|
[JsonProperty(PropertyName = "count")]
|
||||||
public int Count
|
public int Count
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ namespace BTCPayServer.Security
|
|||||||
|
|
||||||
if (token != null)
|
if (token != null)
|
||||||
{
|
{
|
||||||
var bitToken = await GetTokenPermissionAsync(sin, token);
|
var bitToken = (await _TokenRepository.GetTokens(sin)).FirstOrDefault();
|
||||||
if (bitToken == null)
|
if (bitToken == null)
|
||||||
{
|
{
|
||||||
return (null, false);
|
return (null, false);
|
||||||
@@ -184,34 +184,6 @@ namespace BTCPayServer.Security
|
|||||||
}
|
}
|
||||||
return await _TokenRepository.GetStoreIdFromAPIKey(apiKey);
|
return await _TokenRepository.GetStoreIdFromAPIKey(apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<BitTokenEntity> GetTokenPermissionAsync(string sin, string expectedToken)
|
|
||||||
{
|
|
||||||
var actualTokens = (await _TokenRepository.GetTokens(sin)).ToArray();
|
|
||||||
actualTokens = actualTokens.SelectMany(t => GetCompatibleTokens(t)).ToArray();
|
|
||||||
|
|
||||||
var actualToken = actualTokens.FirstOrDefault(a => a.Value.Equals(expectedToken, StringComparison.Ordinal));
|
|
||||||
if (expectedToken == null || actualToken == null)
|
|
||||||
{
|
|
||||||
Logs.PayServer.LogDebug($"No token found for facade {Facade.Merchant} for SIN {sin}");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return actualToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerable<BitTokenEntity> GetCompatibleTokens(BitTokenEntity token)
|
|
||||||
{
|
|
||||||
if (token.Facade == Facade.Merchant.ToString())
|
|
||||||
{
|
|
||||||
yield return token.Clone(Facade.User);
|
|
||||||
yield return token.Clone(Facade.PointOfSale);
|
|
||||||
}
|
|
||||||
if (token.Facade == Facade.PointOfSale.ToString())
|
|
||||||
{
|
|
||||||
yield return token.Clone(Facade.User);
|
|
||||||
}
|
|
||||||
yield return token;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
internal static void AddAuthentication(IServiceCollection services, Action<BitpayAuthOptions> bitpayAuth = null)
|
internal static void AddAuthentication(IServiceCollection services, Action<BitpayAuthOptions> bitpayAuth = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,14 +28,6 @@
|
|||||||
<input asp-for="PublicKey" class="form-control" />
|
<input asp-for="PublicKey" class="form-control" />
|
||||||
<span asp-validation-for="PublicKey" class="text-danger"></span>
|
<span asp-validation-for="PublicKey" class="text-danger"></span>
|
||||||
</div>}
|
</div>}
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Facade"></label>
|
|
||||||
<select asp-for="Facade" class="form-control">
|
|
||||||
<option value="merchant">merchant</option>
|
|
||||||
<option value="pos">pos</option>
|
|
||||||
</select>
|
|
||||||
<span asp-validation-for="Facade" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@if(ViewBag.ShowStores)
|
@if(ViewBag.ShowStores)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Label</th>
|
<th>Label</th>
|
||||||
<th>Facade</th>
|
|
||||||
<th class="text-right">Actions</th>
|
<th class="text-right">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -34,7 +33,6 @@
|
|||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>@token.Label</td>
|
<td>@token.Label</td>
|
||||||
<td>@token.Facade</td>
|
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<a asp-action="ShowToken" asp-route-tokenId="@token.Id">See information</a> - <a asp-action="RevokeToken" asp-route-tokenId="@token.Id">Revoke</a>
|
<a asp-action="ShowToken" asp-route-tokenId="@token.Id">See information</a> - <a asp-action="RevokeToken" asp-route-tokenId="@token.Id">Revoke</a>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -20,10 +20,6 @@
|
|||||||
<th>Label</th>
|
<th>Label</th>
|
||||||
<td style="text-align:right;">@Model.Label</td>
|
<td style="text-align:right;">@Model.Label</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<th>Facade</th>
|
|
||||||
<td style="text-align:right;">@Model.Facade</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>SIN</th>
|
<th>SIN</th>
|
||||||
<td style="text-align:right;">@Model.SIN</td>
|
<td style="text-align:right;">@Model.SIN</td>
|
||||||
|
|||||||
@@ -20,10 +20,6 @@
|
|||||||
<th>Token</th>
|
<th>Token</th>
|
||||||
<td>@Model.Value</td>
|
<td>@Model.Value</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<th>Facade</th>
|
|
||||||
<td>@Model.Facade</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user