MT-23076: expose api token expiration in create and reset requests - #253
Open
oshchyhol wants to merge 6 commits into
Open
MT-23076: expose api token expiration in create and reset requests#253oshchyhol wants to merge 6 commits into
oshchyhol wants to merge 6 commits into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Aug 7, 2026
4 tasks
oshchyhol
marked this pull request as ready for review
August 19, 2026 11:35
oshchyhol
requested review from
Rabsztok and
VladimirTaytor
and removed request for
mklocek
August 19, 2026 11:35
There was a problem hiding this comment.
Pull request overview
Exposes API-token expiration controls across creation and reset operations.
Changes:
- Adds tri-state expiration serialization.
- Adds expiration-aware reset support and tests.
- Adds masked-token account-access data.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/Mailtrap.UnitTests/GlobalUsings.cs |
Imports expiration models. |
tests/Mailtrap.UnitTests/ApiTokens/ApiTokenResourceTests.cs |
Tests null reset requests. |
tests/Mailtrap.UnitTests/ApiTokens/ApiTokenExpirationTests.cs |
Tests expiration serialization. |
tests/Mailtrap.IntegrationTests/ApiTokens/Reset_WithNeverExpiration_Success.json |
Never-expiring reset fixture. |
tests/Mailtrap.IntegrationTests/ApiTokens/Reset_WithExpiration_Success.json |
Expiring reset fixture. |
tests/Mailtrap.IntegrationTests/ApiTokens/Create_WithNeverExpiration_Success.json |
Never-expiring creation fixture. |
tests/Mailtrap.IntegrationTests/ApiTokens/Create_WithExpiration_Success.json |
Expiring creation fixture. |
tests/Mailtrap.IntegrationTests/ApiTokens/Create_ShouldThrow_WhenExpirationIsRejected.json |
Rejected-expiration fixture. |
tests/Mailtrap.IntegrationTests/ApiTokens/ApiTokensIntegrationTests.cs |
Tests request bodies and responses. |
src/Mailtrap/ApiTokens/ApiTokenResource.cs |
Implements reset with request body. |
src/Mailtrap.Abstractions/GlobalUsings.cs |
Imports expiration converter. |
src/Mailtrap.Abstractions/ApiTokens/Requests/ResetApiTokenRequest.cs |
Defines reset request model. |
src/Mailtrap.Abstractions/ApiTokens/Requests/CreateApiTokenRequest.cs |
Adds creation expiration. |
src/Mailtrap.Abstractions/ApiTokens/Models/ApiTokenExpiration.cs |
Defines expiration value type. |
src/Mailtrap.Abstractions/ApiTokens/IApiTokenResource.cs |
Exposes reset overload. |
src/Mailtrap.Abstractions/ApiTokens/Converters/ApiTokenExpirationJsonConverter.cs |
Implements expiration JSON conversion. |
src/Mailtrap.Abstractions/AccountAccesses/Models/Specifier.cs |
Adds masked-token field. |
examples/Mailtrap.Example.ApiTokens/Program.cs |
Demonstrates expiration usage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+26
to
+39
| public override void Write(Utf8JsonWriter writer, ApiTokenExpiration value, JsonSerializerOptions options) | ||
| { | ||
| Ensure.NotNull(writer, nameof(writer)); | ||
| Ensure.NotNull(value, nameof(value)); | ||
|
|
||
| if (value.Value.HasValue) | ||
| { | ||
| writer.WriteStringValue(value.Value.Value); | ||
| } | ||
| else | ||
| { | ||
| writer.WriteNullValue(); | ||
| } | ||
| } |
Comment on lines
+93
to
+95
| [JsonPropertyName("masked_token")] | ||
| [JsonPropertyOrder(6)] | ||
| public string? MaskedToken { get; set; } |
| /// The old token stops working after a short grace period. The response includes | ||
| /// the new token value – store it securely; it is only returned once. | ||
| /// </remarks> | ||
| public Task<ApiTokenResetResponse> Reset(ResetApiTokenRequest request, CancellationToken cancellationToken = default); |
Rabsztok
approved these changes
Aug 24, 2026
VladimirTaytor
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
MT-23076 – the Mailtrap API token endpoints now accept an optional
expires_atvalue. This exposes it in the .NET SDK.Changes
ApiTokenExpirationtype with a custom JSON converter implementing the tri-state contract: property unset –expires_atkey omitted from the body (server default, a 1-year default is being rolled out behind a feature flag);ApiTokenExpiration.Never– explicit"expires_at": null(token never expires);ApiTokenExpiration.At(...)– ISO 8601 date-time stringCreateApiTokenRequest.ExpiresAtfor thecreateApiTokenoperation (optional nullableexpires_atin the request body)ResetApiTokenRequestand anIApiTokenResource.Reset(ResetApiTokenRequest, CancellationToken)overload for theresetApiTokenoperation, whose request body is now optional; the existing parameterlessReset()keeps sending no bodySpecifier.MaskedToken– the account-accessApiTokenspecifier hasmasked_tokenin the spec, which the SDK model was missingNote: adding a member to
IApiTokenResourceis source-breaking for external implementors of that interface.How to test
client.Account(id).ApiTokens().Create(request)without settingExpiresAt– the request body contains noexpires_atkey; with the server flag enabled the created token gets the default 1-yearexpires_atin the responseExpiresAt = ApiTokenExpiration.Never– the request body contains"expires_at": nulland the response hasexpires_at: nullExpiresAt = ApiTokenExpiration.At(DateTimeOffset.Parse("2027-06-01T00:00:00Z"))– the request body contains the ISO date-time and the response echoes itHttpRequestFailedExceptionwith status 422apiToken.Reset()(parameterless) – the request is sent without a body and succeeds exactly as before this changeapiToken.Reset(new ResetApiTokenRequest { ExpiresAt = ApiTokenExpiration.Never })– the request body is{"expires_at":null}and the new token never expiresexpires_atis returned in responses as beforeCompanion PRs
Caveat: release/merge only after falcon deploys MT-23076 and zap_api_token_expiration is enabled in production.