Skip to content

[Refactor] Extract the token decoder from get_current_principal #62

@Robbo-lab

Description

@Robbo-lab

Issue Type

  • Bug
  • Feature
  • Documentation
  • Other

Other: auth boundary cleanup

Description

app/utils/get_principal.py currently handles too many responsibilities in one place:

  • FastAPI header handling
  • bearer token parsing
  • principal creation
  • demo auth mapping
  • HTTP error handling

This makes the authentication flow harder to reuse and harder to extend later.

A small shared token-decoder interface would improve separation of concerns while keeping the current demo authentication behaviour unchanged.

Steps to Review

  1. Open app/utils/get_principal.py
  2. Review get_current_principal
  3. Observe that FastAPI request handling and auth logic are mixed together

Expected Behaviour

Authentication logic should be separated from FastAPI request handling.

Current Behaviour

Token parsing, principal creation, and HTTP handling are all combined in one function.

Additional Context

Proposed Scope

  • Add a small shared token-decoder interface
  • Move token parsing and principal creation into shared auth logic
  • Keep get_current_principal focused on FastAPI boundary handling only
  • Preserve the current demo-token behaviour

Out of Scope

  • JWT validation
  • Password hashing
  • Database authentication
  • Role redesign
  • Security framework changes

Acceptance Criteria

  • A small shared auth/token interface exists
  • Token parsing no longer depends directly on FastAPI classes
  • get_current_principal becomes a thin FastAPI adapter
  • Existing demo-token behaviour remains unchanged

Possible Solution

Create a small token-decoder service that returns Principal objects from bearer tokens, while keeping FastAPI request extraction and HTTP exceptions inside get_current_principal.

Environment

  • OS: N/A
  • Browser: N/A
  • Version: current main branch

Metadata

Metadata

Assignees

Labels

DXIssue would improve the developer experienceenhancementNew feature or requestgood first issueGood for newcomers

Projects

Status
Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions