Round #213

07 May 2026, 14:13· csharp· meta/llama-3.3-70b-instruct· r12-real-contracts
Complexity
band 1
ZP / UO / OBS
5 / 8 / 0
Journey weight
972
Lightshift ΔL

Prompt

Write a refresh token rotation endpoint that invalidates old tokens

Zero-point index (what the engine surfaced)

ZPI-ZPI-0006 | 2026-05-07T14:13:24Z Write a refresh token rotation endpoint that invalidates old tokens ZERO POINT — 5 entries (structural invariants) ● hsl(228.20, 100%, 18%) IAuthenticationHandler [contract] ● hsl(61.59, 100%, 18%) AuthenticationHandler<TOptions> [contract] ● hsl(257.20, 100%, 18%) AuthenticationSchemeOptions [contract] ● hsl(161.43, 100%, 18%) JwtBearerOptions [contract] ● hsl(89.40, 100%, 18%) OpenIdConnectOptions [contract] UNOBSERVED — 8 entries (implied truths) ○ hsl(27.69, 100%, 50%) async [feature] ○ hsl(49.23, 100%, 30%) try [feature] ○ hsl(112.62, 100%, 16%) Token validation parameters [function] ○ hsl(31.38, 100%, 40%) Scoped registration [function] ○ hsl(44.31, 100%, 25%) IOptions of T binding [function] ○ hsl(9.23, 100%, 32%) interface [feature] ○ hsl(77.54, 100%, 19%) Routing middleware [function] ○ hsl(83.08, 100%, 26%) ILogger of T injection [function] OBSERVED — 0 entries (explicit in request) COMPLEXITY │ 13 entries │ spread: 103° │ band: MEDIUM

Baseline response (no ZPI)

**Refresh Token Rotation Endpoint** ===================================== This endpoint is designed to rotate refresh tokens, invalidating old tokens and issuing new ones. This is a crucial security feature to prevent token reuse and minimize the impact of token compromise. **Endpoint Details** -------------------- * **HTTP Method:** POST * **Endpoint:** `/api/auth/refresh-token` * **Request Body:** + `refreshToken`: The current refresh token to be rotated. + `clientId`: The client ID associated with the refresh token. * **Response:** + `newRefreshToken`: The newly issued refresh token. + `accessToken`: The newly issued access token. + `expiresIn`: The number of seconds until the access token expires. **Implementation** ----------------- Here is an example implementation in C#: ```csharp using Microsoft.AspNetCore.Mvc; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using Microsoft.IdentityModel.Tokens; using System; [ApiController] [Route("api/[controller]")] public class AuthController : ControllerBase { private readonly IConfiguration _configuration; private readonly ITokenService _tokenService; public AuthController(IConfiguration configuration, ITokenService tokenService) { _configuration = configuration; _tokenService = tokenService; } [HttpPost("refresh-token")] public async Task<IActionResult> RotateRefreshToken([FromBody] RefreshTokenRequest request) { // Validate the request if (string.IsNullOrEmpty(request.RefreshToken) || string.IsNullOrEmpty(request.ClientId)) { return BadRequest("Invalid request"); } // Validate the refresh token var refreshToken = await _tokenService.ValidateRefreshToken(request.RefreshToken, request.ClientId); if (refreshToken == null) { return Unauthorized("Invalid refresh token"); } // Invalidate the old refresh token await _tokenService.InvalidateRefreshToken(refreshToken); // Issue a new refresh token and access token var newRefreshToken = await _tokenService.IssueRefreshToken(request.ClientId); var accessToken = await _tokenService.IssueAccessToken(request.ClientId); // Return the new tokens return Ok(new RefreshTokenResponse { NewRefreshToken = newRefreshToken, AccessToken = accessToken, ExpiresIn = 3600 // 1 hour }); } } public class RefreshTokenRequest { public string RefreshToken { get; set; } public string ClientId { get; set; } } public class RefreshTokenResponse { public string NewRefreshToken { get; set; } public string AccessToken { get; set; } public int ExpiresIn { get; set; } } public interface ITokenService { Task<string> ValidateRefreshToken(string refreshToken, string clientId); Task InvalidateRefreshToken(string refreshToken); Task<string> IssueRefreshToken(string clientId); Task<string> IssueAccessToken(string clientId); } public class TokenService : ITokenService { private readonly IConfiguration _configuration; public TokenService(IConfiguration configuration) { _configuration = configuration; } public async Task<string> ValidateRefreshToken(string refreshToken, string clientId) { // Validate the refresh token using your preferred method (e.g., database, cache) // For demonstration purposes, we'll use a simple in-memory validation var validRefreshTokens = new Dictionary<string, string> { { "client1", "refreshToken1" }, { "client2", "refreshToken2" } }; if (validRefreshTokens.TryGetValue(clientId, out var validRefreshToken) && validRefreshToken == refreshToken) { return refreshToken; } return null; } public async Task InvalidateRefreshToken(string refreshToken) { // Invalidate the refresh token using your preferred method (e.g., database, cache) // For demonstration purposes, we'll use a simple in-memory invalidation var validRefreshTokens = new Dictionary<string, string> { { "client1", "refreshToken1" }, { "client2", "refreshToken2" } }; foreach (var client in validRefreshTokens.Keys.ToList()) { if (validRefreshTokens[client] == refreshToken) { validRefreshTokens.Remove(client); break; } } } public async Task<string> IssueRefreshToken(string clientId) { // Issue a new refresh token using your preferred method (e.g., database, cache) // For demonstration purposes, we'll use a simple in-memory issuance var newRefreshToken = Guid.NewGuid().ToString(); var validRefreshTokens = new Dictionary<string, string> { { "client1", "refreshToken1" }, { "client2", "refreshToken2" } }; validRefreshTokens[clientId] = newRefreshToken; return newRefreshToken; } public async Task<string> IssueAccessToken(string clientId)

Enhanced response (with ZPI)

```csharp using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; using System; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using System.Threading.Tasks; // Define a class to hold the refresh token rotation settings public class RefreshTokenRotationSettings { public string Issuer { get; set; } public string Audience { get; set; } public string SecretKey { get; set; } public int TokenLifetime { get; set; } } // Define a class to handle the refresh token rotation public class RefreshTokenRotationService { private readonly ILogger<RefreshTokenRotationService> _logger; private readonly RefreshTokenRotationSettings _settings; public RefreshTokenRotationService(ILogger<RefreshTokenRotationService> logger, IOptions<RefreshTokenRotationSettings> settings) { _logger = logger; _settings = settings.Value; } // Method to generate a new JWT token public string GenerateToken(ClaimsIdentity identity) { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_settings.SecretKey); var tokenDescriptor = new SecurityTokenDescriptor { Subject = identity, Issuer = _settings.Issuer, Audience = _settings.Audience, Expires = DateTime.UtcNow.AddMinutes(_settings.TokenLifetime), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); return tokenHandler.WriteToken(token); } // Method to invalidate old tokens public void InvalidateToken(string token) { // In a real-world scenario, you would store the invalidated tokens in a database or cache // For simplicity, we'll just log the invalidated token _logger.LogInformation($"Token {token} has been invalidated"); } } // Define a controller to handle the refresh token rotation endpoint [ApiController] [Route("api/[controller]")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class RefreshTokenRotationController : ControllerBase { private readonly RefreshTokenRotationService _refreshTokenRotationService; public RefreshTokenRotationController(RefreshTokenRotationService refreshTokenRotationService) { _refreshTokenRotationService = refreshTokenRotationService; } // Endpoint to rotate the refresh token [HttpPost("rotate-token")] public async Task<IActionResult> RotateToken([FromBody] string refreshToken) { try { // Validate the refresh token var tokenHandler = new JwtSecurityTokenHandler(); var tokenValidationParams = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = _refreshTokenRotationService._settings.Issuer, ValidAudience = _refreshTokenRotationService._settings.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_refreshTokenRotationService._settings.SecretKey)) }; var principal = tokenHandler.ValidateToken(refreshToken, tokenValidationParams, out var validatedToken); // If the token is valid, generate a new token and invalidate the old one if (validatedToken is JwtSecurityToken jwtToken) { var newToken = _refreshTokenRotationService.GenerateToken(principal.Identity as ClaimsIdentity); _refreshTokenRotationService.InvalidateToken(refreshToken); return Ok(new { token = newToken }); } else { return BadRequest("Invalid token"); } } catch (Exception ex) { return StatusCode(500, ex.Message); } } } // Register the services in the Startup.cs file public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = "your_issuer", ValidAudience = "your_audience", IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("your_secret_key")) }; }); services.Configure<RefreshTokenRotationSettings>(Configuration.GetSection("RefreshTokenRotationSettings")); services.AddSingleton<RefreshTokenRotationService>(); services.AddControllers(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } ``` This implementation provides a refresh token rotation endpoint that invalidates

Grader chain

Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.

V1claude-haiku-4-5-20251001
Better
V4qwen2.5-coder-7b-instruct
Better

Comments

Our grader said what it said. What do you say? Comment as a guest below.

No comments yet. Be the first to say what you make of this round.

← back to all rounds