Class WebhookRequestParser
Entry point for receiving LINE webhooks. A thin helper that bundles x-line-signature
signature validation (WebhookSignatureValidator) and deserialization of the
body into Line.OpenApi.Messaging.Webhook.Generated.Models.CallbackRequest into a single call.
Deserialization is done by instantiating Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory directly and
does not depend at all on Kiota's global default serializer registry
(ParseNodeFactoryRegistry.DefaultInstance / ApiClientBuilder.RegisterDefaultDeserializer).
(KiotaJsonSerializer internally consults that default registry, so it fails in a
clean process where no JSON factory has been registered. Using the factory directly does
not carry that assumption.) As a result it works standalone even in an app that has not
constructed the Messaging client, and has no side effects (the regression is guarded by the
standalone assembly Line.OpenApi.Messaging.Webhook.IsolationTests).
Polymorphic reconstruction of the event array (dispatch to Line.OpenApi.Messaging.Webhook.Generated.Models.MessageEvent etc.
by the type discriminator, with a fallback to the base Line.OpenApi.Messaging.Webhook.Generated.Models.Event for
unknown types) is handled by the generated code. This helper only returns the
Line.OpenApi.Messaging.Webhook.Generated.Models.CallbackRequest; the subsequent event branching is done on the caller side
(see README).
Example usage with ASP.NET Core (obtaining the raw body and signature header is the caller's responsibility):
var body = await ReadRawBodyBytesAsync(Request); // raw bytes (same as what is signed)
var sig = Request.Headers["x-line-signature"];
CallbackRequest callback = await parser.ParseAsync(body, sig); // throws on invalid signature
public sealed class WebhookRequestParser
- Inheritance
-
WebhookRequestParser
- Inherited Members
Constructors
WebhookRequestParser(string)
public WebhookRequestParser(string channelSecret)
Parameters
channelSecretstringThe channel secret (the key for signature validation).
Exceptions
- ArgumentException
channelSecretis empty or whitespace only.
Methods
ParseAsync(byte[], string?, CancellationToken)
Validates the signature with the channel secret supplied at construction and deserializes the body into Line.OpenApi.Messaging.Webhook.Generated.Models.CallbackRequest.
public Task<CallbackRequest> ParseAsync(byte[] body, string? signatureHeader, CancellationToken cancellationToken = default)
Parameters
bodybyte[]The raw request body (both signature validation and deserialization operate on these same bytes).
signatureHeaderstringThe
x-line-signatureheader value.cancellationTokenCancellationTokenCancellation token.
Returns
- Task<CallbackRequest>
Exceptions
- ArgumentNullException
bodyis null.- WebhookSignatureException
Signature validation failed.
- WebhookPayloadException
The signature was valid but the body could not be deserialized.
ParseAsync(string, byte[], string?, CancellationToken)
Validates the signature and deserializes the body, specifying the channel secret per call (for multi-tenant scenarios).
public static Task<CallbackRequest> ParseAsync(string channelSecret, byte[] body, string? signatureHeader, CancellationToken cancellationToken = default)
Parameters
channelSecretstringbodybyte[]signatureHeaderstringcancellationTokenCancellationToken
Returns
- Task<CallbackRequest>
Exceptions
- ArgumentNullException
bodyis null.- ArgumentException
channelSecretis empty or whitespace only.- WebhookSignatureException
Signature validation failed.
- WebhookPayloadException
The signature was valid but the body could not be deserialized.