<!--
title: standardize authentication context extraction
domain: observability
topic: Security
language: Go
source: SigNoz/signoz
updated: 2025-05-29
url: https://awesomereviewers.com/reviewers/signoz-standardize-authentication-context-extraction/
-->

Always use the standardized `authtypes.ClaimsFromContext` method for extracting authentication claims from request context, and handle errors properly. This ensures consistent authentication handling across the codebase and prevents potential security vulnerabilities from incorrect claim extraction.

The correct pattern is:
```go
claims, err := authtypes.ClaimsFromContext(r.Context())
if err != nil {
    render.Error(rw, err)
    return
}
```

Avoid custom claim extraction methods or incorrect error handling patterns like `claims, ok := authtypes.ClaimsFromContext(r.Context())` followed by `if ok != nil` - this can lead to authentication bypasses if the error handling logic is inverted. Using the standardized method ensures proper error propagation and consistent security behavior across all handlers.
