platformplatform / PlatformPlatform

Alpha state. A platform designed for building enterprise-grade, multi-tenant products using Azure, .NET, React, TypeScript, Infrastructure as Code, etc.
https://platformplatform.github.io
MIT License
253 stars 26 forks source link

Refactor authentication token logic and standardize naming conventions #620

Closed tjementum closed 6 days ago

tjementum commented 6 days ago

Summary & Motivation

Move authentication token logic to the SharedKernel for improved separation of concerns, enabling tests in other self-contained systems to generate valid access tokens. This includes using UserInfo instead of User to create tokens. The AuthenticationTokenGenerator has been split into AccessTokenGenerator, RefreshTokenGenerator, and SecurityTokenDescriptorExtensions, providing clear and modular responsibilities.

Introduce a strongly typed ID for RefreshTokenId to enhance type safety. Standardize the naming of authentication cookies, changing from hyphen-case (refresh-token and access-token) to snake_case (refresh_token and access_token) to align with common practices.

Additional improvements include extracting refresh and access token validation periods into constants with added documentation. The RefreshAuthenticationTokens command now returns an Unauthorized result instead of throwing exceptions for invalid refresh tokens.

The CreateUser command has been updated to validate that the TenantId matches the execution context, except during signup, ensuring data integrity.

New HTTP clients (anonymous and authenticated) have been introduced in the BackOffice self-contained system's EndpointBaseTest, facilitating robust testing.

Downstream Projects

Update BaseTest and EndpointBaseTest go gain access to the making authenticated API calls.

Checklist

linear[bot] commented 6 days ago

PP-245 Move authentication token logic to Shared Kernel

sonarcloud[bot] commented 6 days ago

Quality Gate Passed Quality Gate passed

Issues
2 New issues
0 Accepted issues

Measures
0 Security Hotspots
50.5% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud