Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Resend/IResend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,14 @@ public interface IResend
/// <returns>Response.</returns>
Task<ResendResponse> WebhookDeleteAsync( Guid webhookId, CancellationToken cancellationToken = default );

/// <summary>
/// Rotates the signing secret of a webhook.
/// </summary>
/// <param name="webhookId">Webhook identifier.</param>
/// <param name="cancellationToken">Cancelation token.</param>
/// <returns>Webhook identifier and new signing secret.</returns>
Task<ResendResponse<WebhookNew>> WebhookRotateSigningSecretAsync( Guid webhookId, CancellationToken cancellationToken = default );

/// <summary>
/// Lists webhook events.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Resend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The `ResendClient` supports the following objects (and methods):
* Segment (List, Create, Retrieve, Update, Delete)
* Topics (List, Create, Retrieve, Update, Delete)
* Templates (List, Create, Retrieve, Update, Delete, Publish, Duplicate)
* Webhooks (List, Create, Retrieve, Update, Delete, Event List, Event Retrieve, Event Replay, Event Attempt List)
* Webhooks (List, Create, Retrieve, Update, Delete, Rotate Signing Secret, Event List, Event Retrieve, Event Replay, Event Attempt List)


Installing via NuGet
Expand Down
9 changes: 9 additions & 0 deletions src/Resend/ResendClient.Webhooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public partial class ResendClient
}


/// <inheritdoc />
public Task<ResendResponse<WebhookNew>> WebhookRotateSigningSecretAsync( Guid webhookId, CancellationToken cancellationToken = default )
Comment thread
gabrielmfern marked this conversation as resolved.
Resolved
{
var req = new HttpRequestMessage( HttpMethod.Post, $"/webhooks/{webhookId}/signing-secret/rotate" );

return Execute<WebhookNew, WebhookNew>( req, ( x ) => x, cancellationToken );
}


/// <inheritdoc />
public Task<ResendResponse<WebhookEventListResult>> WebhookEventListAsync( Guid webhookId, PaginatedAfterQuery? query = null, CancellationToken cancellationToken = default )
{
Expand Down
2 changes: 1 addition & 1 deletion src/Resend/WebhookNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Resend;

/// <summary>
/// Response when the webhook is created.
/// Response when the webhook is created or its signing secret is rotated.
Comment thread
gabrielmfern marked this conversation as resolved.
Resolved
/// </summary>
public class WebhookNew
{
Expand Down
13 changes: 13 additions & 0 deletions tests/Resend.Tests/ResendClientTests.Webhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ public async Task WebhookDelete()
}


/// <summary/>
[Fact]
public async Task WebhookRotateSigningSecret()
{
var webhookId = Guid.NewGuid();
var resp = await _resend.WebhookRotateSigningSecretAsync( webhookId );

Assert.NotNull( resp );
Assert.Equal( webhookId, resp.Content.Id );
Assert.Equal( "whsec_rotated-secret", resp.Content.SigningSecret );
}


[Fact]
public async Task WebhookEventList()
{
Expand Down
15 changes: 15 additions & 0 deletions tools/Resend.ApiServer/Controllers/WebhookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ public ActionResult WebhookDelete( [FromRoute] Guid id )
}


/// <summary />
[HttpPost]
[Route( "webhooks/{id}/signing-secret/rotate" )]
public WebhookNew WebhookRotateSigningSecret( [FromRoute] Guid id )
{
_logger.LogDebug( "WebhookRotateSigningSecret" );

return new WebhookNew()
{
Id = id,
SigningSecret = "whsec_rotated-secret",
};
}


/// <summary />
[HttpGet]
[Route( "webhooks" )]
Expand Down
Loading