Add Bearer token authentication for protected endpoints#8
Draft
Add Bearer token authentication for protected endpoints#8
Conversation
Co-authored-by: drdule <204492158+drdule@users.noreply.github.com>
…lidation, and refactor metrics Co-authored-by: drdule <204492158+drdule@users.noreply.github.com>
…stant-time comparison Co-authored-by: drdule <204492158+drdule@users.noreply.github.com>
…ning useful logging Co-authored-by: drdule <204492158+drdule@users.noreply.github.com>
Co-authored-by: drdule <204492158+drdule@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement Bearer token authentication for upload endpoint
Add Bearer token authentication for protected endpoints
Jan 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements Bearer token authentication to protect upload endpoints while keeping health/metrics public.
Changes
Authentication System
verify_token()dependency with constant-time token comparison (secrets.compare_digest())Authorization: Bearer <token>header format (case-insensitive)API_TOKENnot configuredProtected Endpoints (require token)
POST /upload- Water meter image uploadPOST /notify_upload- Upload notification (new endpoint)Public Endpoints (no authentication)
GET /- RootGET /health- Health checkGET /metrics- System metrics (new endpoint)Data Models
NotifyUploadRequestwith Literal type validation for status field (uploaded,processing,completed,failed)Database
get_metrics()method to centralize metrics retrievalConfiguration
.env.examplewithAPI_TOKENand generation instructionsUsage
Security
Original prompt
Tačka 6: API Token Authentication
Implementirati Bearer token autentikaciju za zaštitu upload endpoint-a.
Zahtevi:
1. Dependency funkcija
verify_token()umain.pyKreirati async dependency funkciju koja:
AuthorizationheaderBearer <token>API_TOKENenv varijablomImplementacija:
2. Primena autentikacije na endpoint-e
Zaštićeni endpoint-i (ZAHTEVAJU token):
POST /uploadPOST /notify_uploadJavni endpoint-i (BEZ autentikacije):
Ovi endpoint-i OSTAJU bez autentikacije:
GET /- Root endpointGET /health- Health checkGET /metrics- Metrics3.
.env.exampletemplate fajlKreirati
.env.examplefajl u root direktorijumu:4. Provera da je
.envu.gitignoreAko
.gitignorene postoji, kreiraj ga. Ako postoji, dodaj.envako već nije:5. Ažuriranje README.md
Dodaj sekciju o autentikaciji:
Usage
Include the token in the
Authorizationheader:Protected Endpoints
The following endpoints require authentication:
POST /upload- Upload water meter imagePOST /notify_upload- Notify upload completionPublic Endpoints
The following endpoints are public (no authentication required):
GET /- Root endpointGET /health- Health checkGET /metrics- System metricsResponse Codes
401 Unauthorized- Missing, invalid, or incorrect token200 OK- Request successful with valid token**Te...
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.