| | | 1 | | using AsiBackbone.Core.CapabilityGrants; |
| | | 2 | | |
| | | 3 | | namespace AsiBackbone.AspNetCore.CapabilityGrants; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Defines the stable reason codes <see cref="SignedCapabilityGrantEndpointValidator" /> places on the denied decisions |
| | | 7 | | /// returns. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <remarks> |
| | | 10 | | /// These values are public contract: they appear in decision receipts, audit ledger records, and problem responses, and |
| | | 11 | | /// they do not change within a major version. Every <see cref="CapabilityGrantValidationCategory" /> other than |
| | | 12 | | /// <see cref="CapabilityGrantValidationCategory.Valid" /> maps to one code through <see cref="ForCategory" />, whatever |
| | | 13 | | /// <see cref="Core.Signing.VerificationPolicyAction" /> the core validator attached to the result. |
| | | 14 | | /// </remarks> |
| | | 15 | | public static class SignedCapabilityGrantReasonCodes |
| | | 16 | | { |
| | | 17 | | /// <summary>No capability grant token was presented.</summary> |
| | | 18 | | public const string Missing = "endpoint.capability_grant.missing"; |
| | | 19 | | |
| | | 20 | | /// <summary>The capability grant token could not be decoded.</summary> |
| | | 21 | | public const string Malformed = "endpoint.capability_grant.malformed"; |
| | | 22 | | |
| | | 23 | | /// <summary>The request has no known, authenticated actor to bind the grant to.</summary> |
| | | 24 | | public const string ActorUnresolved = "endpoint.capability_grant.actor_unresolved"; |
| | | 25 | | |
| | | 26 | | /// <summary>No request-binding provider is registered, or the provider could not bind the request.</summary> |
| | | 27 | | public const string BindingUnavailable = "endpoint.capability_grant.binding_unavailable"; |
| | | 28 | | |
| | | 29 | | /// <summary>Required proof was missing, or no signature verification service is registered.</summary> |
| | | 30 | | public const string ProofMissing = "endpoint.capability_grant.proof_missing"; |
| | | 31 | | |
| | | 32 | | /// <summary>The grant proof did not verify or is not bound to the grant content.</summary> |
| | | 33 | | public const string ProofInvalid = "endpoint.capability_grant.proof_invalid"; |
| | | 34 | | |
| | | 35 | | /// <summary>The grant issuer did not match the configured issuer.</summary> |
| | | 36 | | public const string IssuerMismatch = "endpoint.capability_grant.issuer_mismatch"; |
| | | 37 | | |
| | | 38 | | /// <summary>The grant audience did not match the configured audience.</summary> |
| | | 39 | | public const string AudienceMismatch = "endpoint.capability_grant.audience_mismatch"; |
| | | 40 | | |
| | | 41 | | /// <summary>The grant subject did not match the authenticated actor.</summary> |
| | | 42 | | public const string SubjectMismatch = "endpoint.capability_grant.subject_mismatch"; |
| | | 43 | | |
| | | 44 | | /// <summary>The grant operation did not match the endpoint operation.</summary> |
| | | 45 | | public const string OperationMismatch = "endpoint.capability_grant.operation_mismatch"; |
| | | 46 | | |
| | | 47 | | /// <summary>The grant has expired.</summary> |
| | | 48 | | public const string Expired = "endpoint.capability_grant.expired"; |
| | | 49 | | |
| | | 50 | | /// <summary>The grant is not yet valid.</summary> |
| | | 51 | | public const string NotYetValid = "endpoint.capability_grant.not_yet_valid"; |
| | | 52 | | |
| | | 53 | | /// <summary>The grant does not carry every scope the endpoint requires.</summary> |
| | | 54 | | public const string ScopeMissing = "endpoint.capability_grant.scope_missing"; |
| | | 55 | | |
| | | 56 | | /// <summary>The grant policy version or hash did not match the current decision.</summary> |
| | | 57 | | public const string PolicyMismatch = "endpoint.capability_grant.policy_mismatch"; |
| | | 58 | | |
| | | 59 | | /// <summary>The grant carries no acknowledgment reference where one is required.</summary> |
| | | 60 | | public const string AcknowledgmentMissing = "endpoint.capability_grant.acknowledgment_missing"; |
| | | 61 | | |
| | | 62 | | /// <summary>The grant acknowledgment reference did not match.</summary> |
| | | 63 | | public const string AcknowledgmentMismatch = "endpoint.capability_grant.acknowledgment_mismatch"; |
| | | 64 | | |
| | | 65 | | /// <summary>The grant handshake reference did not match.</summary> |
| | | 66 | | public const string HandshakeMismatch = "endpoint.capability_grant.handshake_mismatch"; |
| | | 67 | | |
| | | 68 | | /// <summary>The grant gateway binding did not match.</summary> |
| | | 69 | | public const string GatewayMismatch = "endpoint.capability_grant.gateway_mismatch"; |
| | | 70 | | |
| | | 71 | | /// <summary>The grant resource binding did not match the request binding.</summary> |
| | | 72 | | public const string ResourceMismatch = "endpoint.capability_grant.resource_mismatch"; |
| | | 73 | | |
| | | 74 | | /// <summary>The grant has been used as many times as it permits, including a replayed single-use grant.</summary> |
| | | 75 | | public const string UseLimitExceeded = "endpoint.capability_grant.use_limit_exceeded"; |
| | | 76 | | |
| | | 77 | | /// <summary>The grant, or the key that signed it, was revoked or stopped.</summary> |
| | | 78 | | public const string Revoked = "endpoint.capability_grant.revoked"; |
| | | 79 | | |
| | | 80 | | /// <summary>The grant was cancelled.</summary> |
| | | 81 | | public const string Cancelled = "endpoint.capability_grant.cancelled"; |
| | | 82 | | |
| | | 83 | | /// <summary>No use store is registered, or the use store was unavailable.</summary> |
| | | 84 | | public const string UseStoreUnavailable = "endpoint.capability_grant.use_store_unavailable"; |
| | | 85 | | |
| | | 86 | | /// <summary>Validation failed without a more specific category, or failed unexpectedly.</summary> |
| | | 87 | | public const string Failed = "endpoint.capability_grant.failed"; |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// Returns the reason code for a core validation category. |
| | | 91 | | /// </summary> |
| | | 92 | | /// <param name="category">The validation category.</param> |
| | | 93 | | /// <returns>The reason code; <see cref="Failed" /> for <see cref="CapabilityGrantValidationCategory.Valid" /> or an |
| | | 94 | | public static string ForCategory(CapabilityGrantValidationCategory category) |
| | | 95 | | { |
| | 245 | 96 | | return category switch |
| | 245 | 97 | | { |
| | 12 | 98 | | CapabilityGrantValidationCategory.MissingProof => ProofMissing, |
| | 13 | 99 | | CapabilityGrantValidationCategory.InvalidProof => ProofInvalid, |
| | 12 | 100 | | CapabilityGrantValidationCategory.WrongIssuer => IssuerMismatch, |
| | 12 | 101 | | CapabilityGrantValidationCategory.WrongAudience => AudienceMismatch, |
| | 12 | 102 | | CapabilityGrantValidationCategory.Expired => Expired, |
| | 12 | 103 | | CapabilityGrantValidationCategory.NotYetValid => NotYetValid, |
| | 12 | 104 | | CapabilityGrantValidationCategory.WrongScope => ScopeMissing, |
| | 12 | 105 | | CapabilityGrantValidationCategory.PolicyMismatch => PolicyMismatch, |
| | 11 | 106 | | CapabilityGrantValidationCategory.MissingAcknowledgmentReference => AcknowledgmentMissing, |
| | 11 | 107 | | CapabilityGrantValidationCategory.AcknowledgmentMismatch => AcknowledgmentMismatch, |
| | 11 | 108 | | CapabilityGrantValidationCategory.HandshakeMismatch => HandshakeMismatch, |
| | 11 | 109 | | CapabilityGrantValidationCategory.GatewayMismatch => GatewayMismatch, |
| | 12 | 110 | | CapabilityGrantValidationCategory.ResourceMismatch => ResourceMismatch, |
| | 13 | 111 | | CapabilityGrantValidationCategory.ReuseLimitExceeded => UseLimitExceeded, |
| | 13 | 112 | | CapabilityGrantValidationCategory.Revoked => Revoked, |
| | 12 | 113 | | CapabilityGrantValidationCategory.Cancelled => Cancelled, |
| | 13 | 114 | | CapabilityGrantValidationCategory.ReplayStoreUnavailable => UseStoreUnavailable, |
| | 14 | 115 | | CapabilityGrantValidationCategory.SubjectMismatch => SubjectMismatch, |
| | 12 | 116 | | CapabilityGrantValidationCategory.OperationMismatch => OperationMismatch, |
| | 1 | 117 | | CapabilityGrantValidationCategory.Valid => Failed, |
| | 13 | 118 | | CapabilityGrantValidationCategory.Failed => Failed, |
| | 1 | 119 | | _ => Failed |
| | 245 | 120 | | }; |
| | | 121 | | } |
| | | 122 | | } |