Spring Security Tutorial Details Refresh Token Implementation to Complement JWT Authentication
A comprehensive tutorial on Spring Security demonstrates how to extend JWT authentication with refresh tokens to balance security and usability. The guide begins by explaining the limitations of short-lived access tokens, which typically expire within 15 minutes to one hour, and introduces refresh tokens that can last from one week to one month.
The article details the creation of a RefreshToken entity annotated with JPA mappings, including fields for the token string, associated user, expiration instant, and revocation flag. It also provides the corresponding RefreshTokenRepository interface with methods to find tokens and delete all tokens for a given user.
In the service layer, RefreshTokenService implements token creation by removing existing tokens for the user, generating a new UUID-based token, setting an expiration based on a configurable property, and persisting it. The verify method checks for existence, expiration, and revocation status, throwing a custom RefreshTokenException when necessary, while the revoke method marks tokens as revoked.
Security considerations are thoroughly covered, highlighting benefits such as reduced exposure time for access tokens, automatic session renewal, centralized session control, and minimized password transmission. Risks discussed include potential database compromise mitigated by hashing with SHA-256 or HMAC-SHA256, increased database load due to statefulness, implementation complexity involving token rotation, and client-side storage vulnerabilities addressed by using HttpOnly cookies instead of localStorage.
The tutorial updates DTOs to include AuthResponse and RefreshRequest, modifies AuthService to integrate refresh token creation during registration and login, and enhances AuthController with endpoints for refresh and logout. A helper method sets secure, HTTP-only cookies with appropriate path and max-age settings.
Finally, adjustments to SecurityConfig are shown to permit public access to authentication endpoints and profile retrieval while restricting administrative routes, ensuring a complete implementation of refresh token mechanics alongside JWT handling.
Related articles
OAuth Authorization Server Built Without Storing User Profiles
The article details the evolution of an OAuth Authorization Server that deliberately avoids storing user profiles, relying instead on external identity providers for authentication. It addresses three core constraints: hundreds of dynamically created isolated APIs, a public SPA client without a BFF, and the inability of resources to query the AS on every request. The design separates concerns so the AS handles only clients, tenants, grants, audiences, scopes, keys, sessions, and token issuance while the Main API owns profiles and roles. Tokens are managed securely inside a Service Worker using a custom FedCM grant, eliminating races across tabs and reducing XSS exposure. The approach minimizes blast radius, simplifies compliance, and keeps the AS replaceable without affecting product domain logic.
Why a 202-Character License Key Uses ECDSA P-256 Instead of Ed25519 or RSA
A developer building offline license verification for a .NET desktop application evaluated Ed25519, RSA, and ECDSA P-256 before selecting the last option. The decision was driven by the requirement for zero external dependencies, keys short enough for manual entry from email, and support for key rotation without breaking existing licenses. Although Ed25519 offers faster verification and a smaller public key, it is absent from System.Security.Cryptography in both .NET 8 and .NET 10, with API approval only targeted for version 11. RSA-2048 produces signatures too long for practical use, resulting in a 571-character Base32 string that users would find cumbersome. ECDSA P-256 with SHA-256 delivers a fixed 64-byte signature that becomes a manageable 202-character key when encoded in Base32, while remaining fully available in the runtime. The article also covers performance measurements, the risks of ECDSA nonce generation, and the deliberate choice of the IEEE P1363 signature format to guarantee fixed-length output.
Pilcrow Publishes Free Comprehensive Guide on Web Authentication
Author Pilcrow has released a detailed, ad-free handbook covering authentication and authorization practices for web applications. The resource draws on personal experience and includes practical examples in JavaScript and Go. It examines password-based methods, email verification, multi-factor authentication, passwordless flows, and passkeys while highlighting associated risks and usability trade-offs. The book also provides in-depth guidance on session management, token security, expiration policies, and email address handling as account identifiers. Recommendations emphasize choosing methods that match application security requirements and user expectations. Additional context is given on OWASP resources and community support channels.
redb 3.4.0 Adds Replay Checkpoints, Shared Runtime Layer and Declarative Secrets Handling for .NET Ecosystem
redb 3.4.0 delivers operational improvements for the .NET integration platform that includes typed storage over Postgres, MSSQL and SQLite, the redb.Route engine modeled after Apache Camel, the Tsak runtime with dashboard and clustering, and redb.Identity for OIDC and OAuth 2.1. The release focuses on post-deployment resilience with replay checkpoints that capture message state at named points inside routes, allowing safe re-execution of downstream steps without duplicating side effects. A shared runtime layer moves framework assemblies into a separate Libs/shared directory so that individual DLLs can be replaced without rebuilding or redeploying the entire Tsak or Identity packages. Secrets are now declared with a [Sensitive] attribute on endpoint options, ensuring URIs containing passwords or keys are sanitized before they reach logs, metrics or health checks. Additional controls include role-based access to management APIs, persistent audit trails and cryptographic signing of dynamically loaded modules. All Pro features remain free on the entire 3.x line with no licensing server required.