@polymorphism-tech/morph-spec 11.2.0 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/bin/morph-spec.js +7 -7
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +1 -1
- package/framework/MORPH.md +2 -2
- package/framework/agents.json +4 -4
- package/framework/docs/CLI.md +19 -11
- package/framework/evals/review-checklist.md +26 -2
- package/framework/hooks/README.md +3 -2
- package/framework/hooks/claude-code/core/graph-refresh-kick.js +2 -2
- package/framework/mcp/registry.json +15 -15
- package/framework/rules/ai-agents-standards.md +9 -1
- package/framework/rules/gsap-standards.md +8 -0
- package/framework/rules/mcp-standards.md +10 -0
- package/framework/schemas/config.schema.json +7 -0
- package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
- package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
- package/framework/skills/core/morph-apply/SKILL.md +4 -3
- package/framework/skills/core/morph-plan/SKILL.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +1 -1
- package/framework/standards/STANDARDS.json +8 -4
- package/framework/standards/STANDARDS.meta.json +1 -1
- package/framework/standards/ai-agents/agent-archetypes.md +1 -1
- package/framework/standards/ai-agents/middleware-patterns.md +0 -2
- package/framework/standards/ai-agents/prompt-sources.md +2 -2
- package/framework/standards/ai-agents/providers/model-registry.md +9 -12
- package/framework/standards/ai-agents/rag-custom-pgvector.md +2 -9
- package/framework/standards/frontend/design-system/ai-image-generation.md +1 -1
- package/framework/standards/infrastructure/docker/local-compose-isolation.md +2 -2
- package/framework/standards/integration/mcp/mcp-tools.md +124 -266
- package/framework/templates/README.md +52 -82
- package/framework/templates/REGISTRY.json +0 -206
- package/framework/templates/code/sql/ai-agents/agent-prompts-migration.sql.template +3 -4
- package/framework/templates/context/design-system.md +1 -1
- package/framework/templates/docs/plan.md +1 -1
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/model-registry.v2.json +1 -1
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaDisclosureTests.cs +1 -1
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Morph.AiKit.Tests.csproj +2 -4
- package/framework/templates/frontend/nextjs/gsap-scroll-section.tsx.hbs +13 -17
- package/framework/templates/infrastructure/github/README.md +10 -13
- package/package.json +2 -2
- package/src/commands/mcp/manual-setup.js +95 -0
- package/src/commands/mcp/mcp-setup.js +23 -191
- package/src/commands/project/doctor.js +6 -16
- package/src/commands/project/init-contract.js +2 -2
- package/src/commands/project/init.js +15 -133
- package/src/commands/project/stack-scan.js +6 -14
- package/src/commands/project/stack-set.js +1 -1
- package/src/commands/project/standards.js +1 -2
- package/src/commands/project/update.js +52 -66
- package/src/commands/scaffold/scaffold.js +28 -7
- package/src/lib/ai/ai-project-scan.js +1 -4
- package/src/lib/ai/code-audit.js +1 -6
- package/src/lib/ai/registry-audit.js +2 -1
- package/src/lib/config/project-config.js +3 -2
- package/src/lib/contract/apply.js +2 -1
- package/src/lib/contract/merge.js +1 -0
- package/src/lib/contract/scan.js +5 -5
- package/src/lib/detectors/claude-config-detector.js +45 -47
- package/src/lib/detectors/mcp-config.js +2 -1
- package/src/lib/diff/diff-lines.js +2 -7
- package/src/lib/graph/graph-loader.js +2 -1
- package/src/lib/graph/graphifyignore.js +2 -1
- package/src/lib/installers/install-manifest.js +56 -0
- package/src/lib/installers/mcp-installer.js +14 -5
- package/src/lib/installers/rules-installer.js +9 -15
- package/src/lib/installers/stack-assets.js +42 -21
- package/src/lib/installers/stack-sync.js +12 -12
- package/src/lib/installers/stack-tooling.js +4 -3
- package/src/lib/json-file.js +9 -0
- package/src/lib/plan/artifact-vocabulary.js +1 -1
- package/src/lib/plan/checks.js +3 -2
- package/src/lib/plan/media.js +3 -3
- package/src/lib/plan/plan-parser.js +5 -10
- package/src/lib/review-reports.js +5 -4
- package/src/lib/stack/stack-scan.js +1 -1
- package/src/lib/standards/verified-against.js +1 -1
- package/src/lib/tests-audit/audit.js +1 -1
- package/src/lib/text.js +5 -0
- package/src/scripts/setup-infra.js +22 -33
- package/src/utils/agents-installer.js +13 -30
- package/src/utils/claude-md-injector.js +16 -50
- package/src/utils/claude-settings-manager.js +2 -2
- package/src/utils/file-copier.js +3 -4
- package/src/utils/hooks-installer.js +55 -20
- package/src/utils/skills-installer.js +18 -78
- package/framework/templates/IDE-SNIPPETS.md +0 -262
- package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +0 -26
- package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +0 -28
- package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +0 -99
- package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +0 -40
- package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +0 -54
- package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +0 -53
- package/framework/templates/code/dotnet/contracts/README.md +0 -74
- package/framework/templates/code/dotnet/database/vector-entity.cs +0 -49
- package/framework/templates/code/sql/ai-agents/pgvector-embeddings-migration.sql.template +0 -91
- package/framework/templates/code/sql/postgresql-migration.template.sql +0 -108
- package/framework/templates/code/typescript/contracts.ts +0 -140
- package/framework/templates/examples/design-system-examples.md +0 -354
- package/framework/templates/infrastructure/docker/Dockerfile.template +0 -58
- package/framework/templates/infrastructure/github/actions/docker-build-push/action.yml.hbs +0 -45
- package/framework/templates/infrastructure/github/actions/health-check/action.yml.hbs +0 -27
- package/framework/templates/integrations/asaas-client.cs +0 -332
- package/framework/templates/integrations/asaas-webhook.cs +0 -290
- package/framework/templates/integrations/neon-auth-config.cs +0 -170
- package/framework/templates/ui/design-system.css +0 -226
- package/src/lib/detectors/index.js +0 -153
- package/src/lib/installers/templates-reconcile.js +0 -26
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
using System.Text.Json.Serialization;
|
|
2
|
-
using Microsoft.AspNetCore.Mvc;
|
|
3
|
-
using Microsoft.Extensions.Logging;
|
|
4
|
-
|
|
5
|
-
namespace {{Namespace}}.Web.Controllers;
|
|
6
|
-
|
|
7
|
-
[ApiController]
|
|
8
|
-
[Route("api/webhooks/asaas")]
|
|
9
|
-
public class AsaasWebhookController : ControllerBase
|
|
10
|
-
{
|
|
11
|
-
private readonly IAsaasWebhookHandler _webhookHandler;
|
|
12
|
-
private readonly ILogger<AsaasWebhookController> _logger;
|
|
13
|
-
|
|
14
|
-
public AsaasWebhookController(
|
|
15
|
-
IAsaasWebhookHandler webhookHandler,
|
|
16
|
-
ILogger<AsaasWebhookController> logger)
|
|
17
|
-
{
|
|
18
|
-
_webhookHandler = webhookHandler;
|
|
19
|
-
_logger = logger;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
[HttpPost]
|
|
23
|
-
public async Task<IActionResult> HandleWebhook([FromBody] AsaasWebhookPayload payload)
|
|
24
|
-
{
|
|
25
|
-
_logger.LogInformation("Received Asaas webhook: {Event}", payload.Event);
|
|
26
|
-
|
|
27
|
-
try
|
|
28
|
-
{
|
|
29
|
-
await _webhookHandler.HandleAsync(payload);
|
|
30
|
-
return Ok();
|
|
31
|
-
}
|
|
32
|
-
catch (Exception ex)
|
|
33
|
-
{
|
|
34
|
-
_logger.LogError(ex, "Error processing Asaas webhook: {Event}", payload.Event);
|
|
35
|
-
// 200 mesmo na falha: o Asaas reenvia toda resposta não-2xx, e o erro já está no log.
|
|
36
|
-
return Ok();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public interface IAsaasWebhookHandler
|
|
42
|
-
{
|
|
43
|
-
Task HandleAsync(AsaasWebhookPayload payload, CancellationToken ct = default);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public class AsaasWebhookHandler : IAsaasWebhookHandler
|
|
47
|
-
{
|
|
48
|
-
private readonly IPaymentService _paymentService;
|
|
49
|
-
private readonly ISubscriptionService _subscriptionService;
|
|
50
|
-
private readonly ILogger<AsaasWebhookHandler> _logger;
|
|
51
|
-
|
|
52
|
-
public AsaasWebhookHandler(
|
|
53
|
-
IPaymentService paymentService,
|
|
54
|
-
ISubscriptionService subscriptionService,
|
|
55
|
-
ILogger<AsaasWebhookHandler> logger)
|
|
56
|
-
{
|
|
57
|
-
_paymentService = paymentService;
|
|
58
|
-
_subscriptionService = subscriptionService;
|
|
59
|
-
_logger = logger;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public async Task HandleAsync(AsaasWebhookPayload payload, CancellationToken ct = default)
|
|
63
|
-
{
|
|
64
|
-
_logger.LogInformation("Processing Asaas webhook: {Event} for {PaymentId}",
|
|
65
|
-
payload.Event, payload.Payment?.Id ?? "N/A");
|
|
66
|
-
|
|
67
|
-
switch (payload.Event)
|
|
68
|
-
{
|
|
69
|
-
case AsaasWebhookEvents.PaymentCreated:
|
|
70
|
-
await HandlePaymentCreatedAsync(payload, ct);
|
|
71
|
-
break;
|
|
72
|
-
|
|
73
|
-
case AsaasWebhookEvents.PaymentAwaitingRiskAnalysis:
|
|
74
|
-
await HandlePaymentAwaitingRiskAsync(payload, ct);
|
|
75
|
-
break;
|
|
76
|
-
|
|
77
|
-
case AsaasWebhookEvents.PaymentPending:
|
|
78
|
-
await HandlePaymentPendingAsync(payload, ct);
|
|
79
|
-
break;
|
|
80
|
-
|
|
81
|
-
case AsaasWebhookEvents.PaymentConfirmed:
|
|
82
|
-
case AsaasWebhookEvents.PaymentReceived:
|
|
83
|
-
await HandlePaymentConfirmedAsync(payload, ct);
|
|
84
|
-
break;
|
|
85
|
-
|
|
86
|
-
case AsaasWebhookEvents.PaymentOverdue:
|
|
87
|
-
await HandlePaymentOverdueAsync(payload, ct);
|
|
88
|
-
break;
|
|
89
|
-
|
|
90
|
-
case AsaasWebhookEvents.PaymentRefunded:
|
|
91
|
-
case AsaasWebhookEvents.PaymentRefundInProgress:
|
|
92
|
-
await HandlePaymentRefundedAsync(payload, ct);
|
|
93
|
-
break;
|
|
94
|
-
|
|
95
|
-
case AsaasWebhookEvents.PaymentChargebackRequested:
|
|
96
|
-
case AsaasWebhookEvents.PaymentChargebackDispute:
|
|
97
|
-
await HandlePaymentChargebackAsync(payload, ct);
|
|
98
|
-
break;
|
|
99
|
-
|
|
100
|
-
case AsaasWebhookEvents.PaymentDeleted:
|
|
101
|
-
await HandlePaymentDeletedAsync(payload, ct);
|
|
102
|
-
break;
|
|
103
|
-
|
|
104
|
-
case AsaasWebhookEvents.SubscriptionCreated:
|
|
105
|
-
await HandleSubscriptionCreatedAsync(payload, ct);
|
|
106
|
-
break;
|
|
107
|
-
|
|
108
|
-
case AsaasWebhookEvents.SubscriptionUpdated:
|
|
109
|
-
await HandleSubscriptionUpdatedAsync(payload, ct);
|
|
110
|
-
break;
|
|
111
|
-
|
|
112
|
-
case AsaasWebhookEvents.SubscriptionDeleted:
|
|
113
|
-
await HandleSubscriptionDeletedAsync(payload, ct);
|
|
114
|
-
break;
|
|
115
|
-
|
|
116
|
-
default:
|
|
117
|
-
_logger.LogWarning("Unhandled Asaas webhook event: {Event}", payload.Event);
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
private async Task HandlePaymentCreatedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
123
|
-
{
|
|
124
|
-
if (payload.Payment is null) return;
|
|
125
|
-
|
|
126
|
-
_logger.LogInformation("Payment created: {PaymentId}", payload.Payment.Id);
|
|
127
|
-
await _paymentService.SyncPaymentAsync(payload.Payment.Id, ct);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private async Task HandlePaymentAwaitingRiskAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
131
|
-
{
|
|
132
|
-
if (payload.Payment is null) return;
|
|
133
|
-
|
|
134
|
-
_logger.LogInformation("Payment awaiting risk analysis: {PaymentId}", payload.Payment.Id);
|
|
135
|
-
await _paymentService.UpdateStatusAsync(payload.Payment.Id, PaymentStatus.AwaitingRisk, ct);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private async Task HandlePaymentPendingAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
139
|
-
{
|
|
140
|
-
if (payload.Payment is null) return;
|
|
141
|
-
|
|
142
|
-
_logger.LogInformation("Payment pending: {PaymentId}", payload.Payment.Id);
|
|
143
|
-
await _paymentService.UpdateStatusAsync(payload.Payment.Id, PaymentStatus.Pending, ct);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
private async Task HandlePaymentConfirmedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
147
|
-
{
|
|
148
|
-
if (payload.Payment is null) return;
|
|
149
|
-
|
|
150
|
-
_logger.LogInformation("Payment confirmed: {PaymentId}, Value: {Value}",
|
|
151
|
-
payload.Payment.Id, payload.Payment.Value);
|
|
152
|
-
|
|
153
|
-
await _paymentService.ConfirmPaymentAsync(payload.Payment.Id, ct);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
private async Task HandlePaymentOverdueAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
157
|
-
{
|
|
158
|
-
if (payload.Payment is null) return;
|
|
159
|
-
|
|
160
|
-
_logger.LogWarning("Payment overdue: {PaymentId}", payload.Payment.Id);
|
|
161
|
-
await _paymentService.MarkOverdueAsync(payload.Payment.Id, ct);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private async Task HandlePaymentRefundedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
165
|
-
{
|
|
166
|
-
if (payload.Payment is null) return;
|
|
167
|
-
|
|
168
|
-
_logger.LogInformation("Payment refunded: {PaymentId}", payload.Payment.Id);
|
|
169
|
-
await _paymentService.RefundPaymentAsync(payload.Payment.Id, ct);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private async Task HandlePaymentChargebackAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
173
|
-
{
|
|
174
|
-
if (payload.Payment is null) return;
|
|
175
|
-
|
|
176
|
-
_logger.LogWarning("Payment chargeback: {PaymentId}", payload.Payment.Id);
|
|
177
|
-
await _paymentService.HandleChargebackAsync(payload.Payment.Id, ct);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
private async Task HandlePaymentDeletedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
181
|
-
{
|
|
182
|
-
if (payload.Payment is null) return;
|
|
183
|
-
|
|
184
|
-
_logger.LogInformation("Payment deleted: {PaymentId}", payload.Payment.Id);
|
|
185
|
-
await _paymentService.DeletePaymentAsync(payload.Payment.Id, ct);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
private async Task HandleSubscriptionCreatedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
189
|
-
{
|
|
190
|
-
_logger.LogInformation("Subscription created via webhook");
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
private async Task HandleSubscriptionUpdatedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
194
|
-
{
|
|
195
|
-
_logger.LogInformation("Subscription updated via webhook");
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private async Task HandleSubscriptionDeletedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
199
|
-
{
|
|
200
|
-
_logger.LogInformation("Subscription deleted via webhook");
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
public static class AsaasWebhookEvents
|
|
205
|
-
{
|
|
206
|
-
public const string PaymentCreated = "PAYMENT_CREATED";
|
|
207
|
-
public const string PaymentAwaitingRiskAnalysis = "PAYMENT_AWAITING_RISK_ANALYSIS";
|
|
208
|
-
public const string PaymentPending = "PAYMENT_PENDING";
|
|
209
|
-
public const string PaymentConfirmed = "PAYMENT_CONFIRMED";
|
|
210
|
-
public const string PaymentReceived = "PAYMENT_RECEIVED";
|
|
211
|
-
public const string PaymentOverdue = "PAYMENT_OVERDUE";
|
|
212
|
-
public const string PaymentRefunded = "PAYMENT_REFUNDED";
|
|
213
|
-
public const string PaymentRefundInProgress = "PAYMENT_REFUND_IN_PROGRESS";
|
|
214
|
-
public const string PaymentChargebackRequested = "PAYMENT_CHARGEBACK_REQUESTED";
|
|
215
|
-
public const string PaymentChargebackDispute = "PAYMENT_CHARGEBACK_DISPUTE";
|
|
216
|
-
public const string PaymentDeleted = "PAYMENT_DELETED";
|
|
217
|
-
|
|
218
|
-
public const string SubscriptionCreated = "SUBSCRIPTION_CREATED";
|
|
219
|
-
public const string SubscriptionUpdated = "SUBSCRIPTION_UPDATED";
|
|
220
|
-
public const string SubscriptionDeleted = "SUBSCRIPTION_DELETED";
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
public record AsaasWebhookPayload
|
|
224
|
-
{
|
|
225
|
-
[JsonPropertyName("event")]
|
|
226
|
-
public string Event { get; init; } = string.Empty;
|
|
227
|
-
|
|
228
|
-
[JsonPropertyName("payment")]
|
|
229
|
-
public AsaasWebhookPayment? Payment { get; init; }
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
public record AsaasWebhookPayment
|
|
233
|
-
{
|
|
234
|
-
[JsonPropertyName("id")]
|
|
235
|
-
public string Id { get; init; } = string.Empty;
|
|
236
|
-
|
|
237
|
-
[JsonPropertyName("customer")]
|
|
238
|
-
public string Customer { get; init; } = string.Empty;
|
|
239
|
-
|
|
240
|
-
[JsonPropertyName("value")]
|
|
241
|
-
public decimal Value { get; init; }
|
|
242
|
-
|
|
243
|
-
[JsonPropertyName("status")]
|
|
244
|
-
public string Status { get; init; } = string.Empty;
|
|
245
|
-
|
|
246
|
-
[JsonPropertyName("billingType")]
|
|
247
|
-
public string BillingType { get; init; } = string.Empty;
|
|
248
|
-
|
|
249
|
-
[JsonPropertyName("externalReference")]
|
|
250
|
-
public string? ExternalReference { get; init; }
|
|
251
|
-
|
|
252
|
-
[JsonPropertyName("subscription")]
|
|
253
|
-
public string? Subscription { get; init; }
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
public enum PaymentStatus
|
|
257
|
-
{
|
|
258
|
-
Pending,
|
|
259
|
-
AwaitingRisk,
|
|
260
|
-
Confirmed,
|
|
261
|
-
Received,
|
|
262
|
-
Overdue,
|
|
263
|
-
Refunded,
|
|
264
|
-
Chargeback,
|
|
265
|
-
Deleted
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
public interface IPaymentService
|
|
269
|
-
{
|
|
270
|
-
Task SyncPaymentAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
271
|
-
Task UpdateStatusAsync(string asaasPaymentId, PaymentStatus status, CancellationToken ct = default);
|
|
272
|
-
Task ConfirmPaymentAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
273
|
-
Task MarkOverdueAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
274
|
-
Task RefundPaymentAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
275
|
-
Task HandleChargebackAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
276
|
-
Task DeletePaymentAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
public interface ISubscriptionService
|
|
280
|
-
{
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
public static class AsaasWebhookServiceExtensions
|
|
284
|
-
{
|
|
285
|
-
public static IServiceCollection AddAsaasWebhook(this IServiceCollection services)
|
|
286
|
-
{
|
|
287
|
-
services.AddScoped<IAsaasWebhookHandler, AsaasWebhookHandler>();
|
|
288
|
-
return services;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
// Neon Auth signs with EdDSA (Ed25519), which Microsoft.IdentityModel cannot verify: needs BouncyCastle.Cryptography >= 2.3.1 (CVE-2024-30172).
|
|
2
|
-
using System.Security.Claims;
|
|
3
|
-
using System.Text;
|
|
4
|
-
using Microsoft.AspNetCore.Authentication;
|
|
5
|
-
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
6
|
-
using Microsoft.Extensions.Options;
|
|
7
|
-
using Microsoft.IdentityModel.JsonWebTokens;
|
|
8
|
-
using Microsoft.IdentityModel.Tokens;
|
|
9
|
-
using Org.BouncyCastle.Crypto.Parameters;
|
|
10
|
-
using Org.BouncyCastle.Crypto.Signers;
|
|
11
|
-
|
|
12
|
-
namespace {{Namespace}}.Infrastructure.Auth;
|
|
13
|
-
|
|
14
|
-
public class NeonAuthOptions
|
|
15
|
-
{
|
|
16
|
-
public const string SectionName = "NeonAuth";
|
|
17
|
-
|
|
18
|
-
// Public value, commit it in appsettings.Development.json: when missing, every request is a bare 401 with nothing in the logs.
|
|
19
|
-
public string BaseUrl { get; set; } = string.Empty;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public sealed class NeonAuthJwksProvider(HttpClient httpClient, IOptions<NeonAuthOptions> options)
|
|
23
|
-
{
|
|
24
|
-
private static readonly TimeSpan CacheTtl = TimeSpan.FromMinutes(15);
|
|
25
|
-
private readonly SemaphoreSlim _refreshLock = new(1, 1);
|
|
26
|
-
private JsonWebKeySet? _cached;
|
|
27
|
-
private DateTimeOffset _cachedAt;
|
|
28
|
-
|
|
29
|
-
public async Task<JsonWebKey?> GetKeyAsync(string kid, CancellationToken cancellationToken)
|
|
30
|
-
{
|
|
31
|
-
var keySet = await GetKeySetAsync(forceRefresh: false, cancellationToken);
|
|
32
|
-
var key = keySet.Keys.FirstOrDefault(k => k.Kid == kid);
|
|
33
|
-
if (key is not null) return key;
|
|
34
|
-
|
|
35
|
-
// Unknown kid may be a key rotation: refresh once instead of waiting out the TTL.
|
|
36
|
-
keySet = await GetKeySetAsync(forceRefresh: true, cancellationToken);
|
|
37
|
-
return keySet.Keys.FirstOrDefault(k => k.Kid == kid);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private async Task<JsonWebKeySet> GetKeySetAsync(bool forceRefresh, CancellationToken cancellationToken)
|
|
41
|
-
{
|
|
42
|
-
if (!forceRefresh && _cached is not null && DateTimeOffset.UtcNow - _cachedAt < CacheTtl)
|
|
43
|
-
return _cached;
|
|
44
|
-
|
|
45
|
-
await _refreshLock.WaitAsync(cancellationToken);
|
|
46
|
-
try
|
|
47
|
-
{
|
|
48
|
-
if (!forceRefresh && _cached is not null && DateTimeOffset.UtcNow - _cachedAt < CacheTtl)
|
|
49
|
-
return _cached;
|
|
50
|
-
|
|
51
|
-
var jwksUri = $"{options.Value.BaseUrl.TrimEnd('/')}/.well-known/jwks.json";
|
|
52
|
-
var json = await httpClient.GetStringAsync(jwksUri, cancellationToken);
|
|
53
|
-
_cached = new JsonWebKeySet(json);
|
|
54
|
-
_cachedAt = DateTimeOffset.UtcNow;
|
|
55
|
-
return _cached;
|
|
56
|
-
}
|
|
57
|
-
finally
|
|
58
|
-
{
|
|
59
|
-
_refreshLock.Release();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public static class NeonAuthServiceExtensions
|
|
65
|
-
{
|
|
66
|
-
public static IServiceCollection AddNeonAuthentication(
|
|
67
|
-
this IServiceCollection services,
|
|
68
|
-
IConfiguration configuration)
|
|
69
|
-
{
|
|
70
|
-
services.Configure<NeonAuthOptions>(configuration.GetSection(NeonAuthOptions.SectionName));
|
|
71
|
-
services.AddHttpClient<NeonAuthJwksProvider>();
|
|
72
|
-
|
|
73
|
-
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
74
|
-
.AddJwtBearer(options =>
|
|
75
|
-
{
|
|
76
|
-
// No options.Authority: Neon Auth serves no /.well-known/openid-configuration to fetch.
|
|
77
|
-
options.TokenValidationParameters = new TokenValidationParameters
|
|
78
|
-
{
|
|
79
|
-
ValidateIssuer = true,
|
|
80
|
-
ValidIssuer = configuration["NeonAuth:BaseUrl"],
|
|
81
|
-
ValidateAudience = false,
|
|
82
|
-
ValidateLifetime = true,
|
|
83
|
-
NameClaimType = "sub",
|
|
84
|
-
// The key is trusted inside SignatureValidator below, not by this flag.
|
|
85
|
-
ValidateIssuerSigningKey = false,
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Separate pass because the validator needs NeonAuthJwksProvider from DI.
|
|
90
|
-
services.AddOptions<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme)
|
|
91
|
-
.Configure<NeonAuthJwksProvider>((options, jwks) =>
|
|
92
|
-
{
|
|
93
|
-
options.TokenValidationParameters.SignatureValidator = (token, _) =>
|
|
94
|
-
{
|
|
95
|
-
var jwt = new JsonWebToken(token);
|
|
96
|
-
|
|
97
|
-
// Pin the algorithm against alg-substitution attacks.
|
|
98
|
-
if (!string.Equals(jwt.Alg, "EdDSA", StringComparison.Ordinal))
|
|
99
|
-
throw new SecurityTokenInvalidSignatureException(
|
|
100
|
-
$"Unsupported alg '{jwt.Alg}' — Neon Auth tokens must be EdDSA.");
|
|
101
|
-
|
|
102
|
-
var kid = jwt.Kid;
|
|
103
|
-
if (string.IsNullOrEmpty(kid))
|
|
104
|
-
throw new SecurityTokenInvalidSignatureException("Token is missing 'kid'.");
|
|
105
|
-
|
|
106
|
-
// SignatureValidator has no async overload; the JWKS is cached, so only a cold miss blocks on I/O.
|
|
107
|
-
var jwk = jwks.GetKeyAsync(kid, CancellationToken.None).GetAwaiter().GetResult()
|
|
108
|
-
?? throw new SecurityTokenInvalidSignatureException(
|
|
109
|
-
$"No JWKS key found for kid '{kid}'.");
|
|
110
|
-
|
|
111
|
-
if (jwk.Kty != "OKP" || jwk.Crv != "Ed25519")
|
|
112
|
-
throw new SecurityTokenInvalidSignatureException(
|
|
113
|
-
"JWKS key is not an Ed25519 (OKP) key.");
|
|
114
|
-
|
|
115
|
-
var parts = token.Split('.');
|
|
116
|
-
if (parts.Length != 3)
|
|
117
|
-
throw new SecurityTokenInvalidSignatureException(
|
|
118
|
-
"Malformed JWT — expected 3 segments.");
|
|
119
|
-
|
|
120
|
-
var signingInput = Encoding.ASCII.GetBytes($"{parts[0]}.{parts[1]}");
|
|
121
|
-
var signature = Base64UrlEncoder.DecodeBytes(parts[2]);
|
|
122
|
-
var publicKey = new Ed25519PublicKeyParameters(Base64UrlEncoder.DecodeBytes(jwk.X), 0);
|
|
123
|
-
|
|
124
|
-
var verifier = new Ed25519Signer();
|
|
125
|
-
verifier.Init(forSigning: false, publicKey);
|
|
126
|
-
verifier.BlockUpdate(signingInput, 0, signingInput.Length);
|
|
127
|
-
|
|
128
|
-
if (!verifier.VerifySignature(signature))
|
|
129
|
-
throw new SecurityTokenInvalidSignatureException(
|
|
130
|
-
"Ed25519 signature verification failed.");
|
|
131
|
-
|
|
132
|
-
// Must be JsonWebToken: returning a JwtSecurityToken fails with IDX10506 on ASP.NET Core 8+.
|
|
133
|
-
return jwt;
|
|
134
|
-
};
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
services.AddAuthorization();
|
|
138
|
-
|
|
139
|
-
return services;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
public interface ICurrentUserService
|
|
144
|
-
{
|
|
145
|
-
string? UserId { get; }
|
|
146
|
-
string? Email { get; }
|
|
147
|
-
bool IsAuthenticated { get; }
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public class CurrentUserService(IHttpContextAccessor httpContextAccessor) : ICurrentUserService
|
|
151
|
-
{
|
|
152
|
-
public string? UserId =>
|
|
153
|
-
httpContextAccessor.HttpContext?.User.FindFirstValue("sub");
|
|
154
|
-
|
|
155
|
-
public string? Email =>
|
|
156
|
-
httpContextAccessor.HttpContext?.User.FindFirstValue("email");
|
|
157
|
-
|
|
158
|
-
public bool IsAuthenticated =>
|
|
159
|
-
httpContextAccessor.HttpContext?.User.Identity?.IsAuthenticated ?? false;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
public static class NeonAuthMiddlewareExtensions
|
|
163
|
-
{
|
|
164
|
-
public static IApplicationBuilder UseNeonAuthentication(this IApplicationBuilder app)
|
|
165
|
-
{
|
|
166
|
-
app.UseAuthentication();
|
|
167
|
-
app.UseAuthorization();
|
|
168
|
-
return app;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Design System - {Project Name}
|
|
3
|
-
*
|
|
4
|
-
* CSS Variables generated from design-system.md
|
|
5
|
-
* Use estas variáveis em todo o projeto para manter consistência visual.
|
|
6
|
-
*
|
|
7
|
-
* Template MORPH-SPEC by Polymorphism Tech
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
:root {
|
|
11
|
-
/* ========================================
|
|
12
|
-
* CORES PRINCIPAIS
|
|
13
|
-
* ======================================== */
|
|
14
|
-
|
|
15
|
-
--color-primary: #{hex da cor primária};
|
|
16
|
-
--color-primary-hover: #{hex da cor primária mais escura};
|
|
17
|
-
--color-primary-active: #{hex da cor primária ainda mais escura};
|
|
18
|
-
|
|
19
|
-
--color-secondary: #{hex da cor secundária};
|
|
20
|
-
--color-secondary-hover: #{hex};
|
|
21
|
-
--color-secondary-active: #{hex};
|
|
22
|
-
|
|
23
|
-
/* ========================================
|
|
24
|
-
* CORES DE ESTADO
|
|
25
|
-
* ======================================== */
|
|
26
|
-
|
|
27
|
-
--color-success: #{hex};
|
|
28
|
-
--color-success-bg: #{hex com transparência ou shade mais claro};
|
|
29
|
-
--color-success-border: #{hex};
|
|
30
|
-
|
|
31
|
-
--color-error: #{hex};
|
|
32
|
-
--color-error-bg: #{hex};
|
|
33
|
-
--color-error-border: #{hex};
|
|
34
|
-
|
|
35
|
-
--color-warning: #{hex};
|
|
36
|
-
--color-warning-bg: #{hex};
|
|
37
|
-
--color-warning-border: #{hex};
|
|
38
|
-
|
|
39
|
-
--color-info: #{hex};
|
|
40
|
-
--color-info-bg: #{hex};
|
|
41
|
-
--color-info-border: #{hex};
|
|
42
|
-
|
|
43
|
-
/* ========================================
|
|
44
|
-
* ESCALA DE NEUTROS (Cinzas)
|
|
45
|
-
* ======================================== */
|
|
46
|
-
|
|
47
|
-
--color-gray-50: #{hex};
|
|
48
|
-
--color-gray-100: #{hex};
|
|
49
|
-
--color-gray-200: #{hex};
|
|
50
|
-
--color-gray-300: #{hex};
|
|
51
|
-
--color-gray-400: #{hex};
|
|
52
|
-
--color-gray-500: #{hex};
|
|
53
|
-
--color-gray-600: #{hex};
|
|
54
|
-
--color-gray-700: #{hex};
|
|
55
|
-
--color-gray-800: #{hex};
|
|
56
|
-
--color-gray-900: #{hex};
|
|
57
|
-
|
|
58
|
-
/* ========================================
|
|
59
|
-
* TIPOGRAFIA - FONTES
|
|
60
|
-
* ======================================== */
|
|
61
|
-
|
|
62
|
-
--font-sans: '{Font Name}', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
|
63
|
-
--font-serif: '{Font Name}', Georgia, 'Times New Roman', serif;
|
|
64
|
-
--font-mono: '{Font Name}', 'Fira Code', 'Courier New', Consolas, monospace;
|
|
65
|
-
|
|
66
|
-
/* ========================================
|
|
67
|
-
* TIPOGRAFIA - TAMANHOS
|
|
68
|
-
* ======================================== */
|
|
69
|
-
|
|
70
|
-
--text-xs: 0.75rem; /* 12px */
|
|
71
|
-
--text-sm: 0.875rem; /* 14px */
|
|
72
|
-
--text-base: 1rem; /* 16px */
|
|
73
|
-
--text-lg: 1.125rem; /* 18px */
|
|
74
|
-
--text-xl: 1.25rem; /* 20px */
|
|
75
|
-
--text-2xl: 1.5rem; /* 24px */
|
|
76
|
-
--text-3xl: 1.875rem; /* 30px */
|
|
77
|
-
--text-4xl: 2.25rem; /* 36px */
|
|
78
|
-
--text-5xl: 3rem; /* 48px */
|
|
79
|
-
|
|
80
|
-
/* ========================================
|
|
81
|
-
* TIPOGRAFIA - LINE HEIGHTS
|
|
82
|
-
* ======================================== */
|
|
83
|
-
|
|
84
|
-
--leading-none: 1;
|
|
85
|
-
--leading-tight: 1.25;
|
|
86
|
-
--leading-snug: 1.375;
|
|
87
|
-
--leading-normal: 1.5;
|
|
88
|
-
--leading-relaxed: 1.625;
|
|
89
|
-
--leading-loose: 2;
|
|
90
|
-
|
|
91
|
-
/* ========================================
|
|
92
|
-
* TIPOGRAFIA - FONT WEIGHTS
|
|
93
|
-
* ======================================== */
|
|
94
|
-
|
|
95
|
-
--font-light: 300;
|
|
96
|
-
--font-regular: 400;
|
|
97
|
-
--font-medium: 500;
|
|
98
|
-
--font-semibold: 600;
|
|
99
|
-
--font-bold: 700;
|
|
100
|
-
--font-extrabold: 800;
|
|
101
|
-
|
|
102
|
-
/* ========================================
|
|
103
|
-
* ESPAÇAMENTO
|
|
104
|
-
* Baseado em múltiplos de {base}px (ex: 4px)
|
|
105
|
-
* ======================================== */
|
|
106
|
-
|
|
107
|
-
--space-0: 0;
|
|
108
|
-
--space-1: 0.25rem; /* 4px */
|
|
109
|
-
--space-2: 0.5rem; /* 8px */
|
|
110
|
-
--space-3: 0.75rem; /* 12px */
|
|
111
|
-
--space-4: 1rem; /* 16px */
|
|
112
|
-
--space-5: 1.25rem; /* 20px */
|
|
113
|
-
--space-6: 1.5rem; /* 24px */
|
|
114
|
-
--space-7: 1.75rem; /* 28px */
|
|
115
|
-
--space-8: 2rem; /* 32px */
|
|
116
|
-
--space-10: 2.5rem; /* 40px */
|
|
117
|
-
--space-12: 3rem; /* 48px */
|
|
118
|
-
--space-16: 4rem; /* 64px */
|
|
119
|
-
--space-20: 5rem; /* 80px */
|
|
120
|
-
--space-24: 6rem; /* 96px */
|
|
121
|
-
|
|
122
|
-
/* ========================================
|
|
123
|
-
* BORDER RADIUS
|
|
124
|
-
* ======================================== */
|
|
125
|
-
|
|
126
|
-
--rounded-none: 0;
|
|
127
|
-
--rounded-sm: 0.125rem; /* 2px */
|
|
128
|
-
--rounded-md: 0.375rem; /* 6px */
|
|
129
|
-
--rounded-lg: 0.5rem; /* 8px */
|
|
130
|
-
--rounded-xl: 0.75rem; /* 12px */
|
|
131
|
-
--rounded-2xl: 1rem; /* 16px */
|
|
132
|
-
--rounded-full: 9999px;
|
|
133
|
-
|
|
134
|
-
/* ========================================
|
|
135
|
-
* SOMBRAS (Shadows)
|
|
136
|
-
* ======================================== */
|
|
137
|
-
|
|
138
|
-
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
139
|
-
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
|
140
|
-
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
141
|
-
--shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
|
142
|
-
--shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
|
143
|
-
|
|
144
|
-
/* ========================================
|
|
145
|
-
* Z-INDEX LAYERS
|
|
146
|
-
* ======================================== */
|
|
147
|
-
|
|
148
|
-
--z-0: 0;
|
|
149
|
-
--z-10: 10;
|
|
150
|
-
--z-20: 20;
|
|
151
|
-
--z-30: 30;
|
|
152
|
-
--z-40: 40;
|
|
153
|
-
--z-50: 50; /* Modals, dropdowns */
|
|
154
|
-
--z-100: 100; /* Tooltips */
|
|
155
|
-
--z-max: 9999; /* Toasts, notifications */
|
|
156
|
-
|
|
157
|
-
/* ========================================
|
|
158
|
-
* TRANSITIONS / ANIMATIONS
|
|
159
|
-
* ======================================== */
|
|
160
|
-
|
|
161
|
-
--transition-fast: 150ms ease-in-out;
|
|
162
|
-
--transition-base: 250ms ease-in-out;
|
|
163
|
-
--transition-slow: 350ms ease-in-out;
|
|
164
|
-
|
|
165
|
-
--ease-in: cubic-bezier(0.4, 0, 1, 1);
|
|
166
|
-
--ease-out: cubic-bezier(0, 0, 0.2, 1);
|
|
167
|
-
--ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
|
|
168
|
-
|
|
169
|
-
/* ========================================
|
|
170
|
-
* BREAKPOINTS (informativo - usar em media queries)
|
|
171
|
-
* ======================================== */
|
|
172
|
-
|
|
173
|
-
/* @media (min-width: 640px) - sm */
|
|
174
|
-
/* @media (min-width: 768px) - md */
|
|
175
|
-
/* @media (min-width: 1024px) - lg */
|
|
176
|
-
/* @media (min-width: 1280px) - xl */
|
|
177
|
-
/* @media (min-width: 1536px) - 2xl */
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/* ========================================
|
|
181
|
-
* MODO ESCURO (Dark Mode)
|
|
182
|
-
* Opcional - ajuste as cores para dark theme
|
|
183
|
-
* ======================================== */
|
|
184
|
-
|
|
185
|
-
@media (prefers-color-scheme: dark) {
|
|
186
|
-
:root {
|
|
187
|
-
/* Inverter cores conforme necessário */
|
|
188
|
-
--color-gray-50: #{hex do gray-900};
|
|
189
|
-
--color-gray-900: #{hex do gray-50};
|
|
190
|
-
/* ... outras inversões */
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/* ========================================
|
|
195
|
-
* CLASSES UTILITÁRIAS (Exemplo)
|
|
196
|
-
* ======================================== */
|
|
197
|
-
|
|
198
|
-
/* Exemplo de uso das variáveis */
|
|
199
|
-
.btn-primary {
|
|
200
|
-
background-color: var(--color-primary);
|
|
201
|
-
color: white;
|
|
202
|
-
padding: var(--space-2) var(--space-4);
|
|
203
|
-
border-radius: var(--rounded-md);
|
|
204
|
-
font-weight: var(--font-semibold);
|
|
205
|
-
transition: background-color var(--transition-base);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
.btn-primary:hover {
|
|
209
|
-
background-color: var(--color-primary-hover);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
.card {
|
|
213
|
-
background-color: white;
|
|
214
|
-
padding: var(--space-6);
|
|
215
|
-
border-radius: var(--rounded-lg);
|
|
216
|
-
box-shadow: var(--shadow-md);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
.text-muted {
|
|
220
|
-
color: var(--color-gray-600);
|
|
221
|
-
font-size: var(--text-sm);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/* ========================================
|
|
225
|
-
* FIM DO DESIGN SYSTEM
|
|
226
|
-
* ======================================== */
|