Skip to content

Add support for authenticating requests using tokens in the Authorization header#93

Open
acvigue wants to merge 5 commits intolukaszraczylo:mainfrom
acvigue:main
Open

Add support for authenticating requests using tokens in the Authorization header#93
acvigue wants to merge 5 commits intolukaszraczylo:mainfrom
acvigue:main

Conversation

@acvigue
Copy link

@acvigue acvigue commented Nov 23, 2025

This pull request introduces support for authenticating requests using bearer tokens in the Authorization header, allowing for stateless session synthesis without relying on cookies. It adds a new method to create in-memory session data from validated access tokens and includes comprehensive unit tests to verify correct behavior and error handling. The changes improve flexibility and security for downstream components that expect session-backed data.

Bearer token authentication and session synthesis:

  • Added logic to ServeHTTP in middleware.go to detect bearer tokens in the Authorization header, verify them, and synthesize a session for downstream processing. If the token is invalid or missing, an error response is sent. ([middleware.goR83-R111](https://github.com/lukaszraczylo/traefikoidc/pull/93/files#diff-02f50901140d6057da6310a106670552aa766a093efbc2200fb34c099b762131R83-R111))
  • Implemented CreateSessionFromAccessToken in session.go, which constructs a synthetic, in-memory SessionData object from a validated JWT access token. This method parses claims, ensures essential fields (like email) are present, and initializes session state without cookie persistence. ([session.goR862-R1033](https://github.com/lukaszraczylo/traefikoidc/pull/93/files#diff-3d4a6b7d54b5107bc5694b7a06383f9ec4c68f9abe43ba0942f5d970f3a8ccacR862-R1033))

Testing and validation:

  • Added unit tests in session_test.go to verify session creation from valid access tokens, including checks for authentication, email extraction, token storage, and session cleanliness. ([session_test.goR209-R283](https://github.com/lukaszraczylo/traefikoidc/pull/93/files#diff-f27c62978dcbd8717b591269e831e3cc0eec4fbdb8fbf53f66435cd8450c4557R209-R283))
  • Added tests to ensure proper error handling when the access token is missing required claims, such as email, confirming robust validation and error reporting. ([session_test.goR209-R283](https://github.com/lukaszraczylo/traefikoidc/pull/93/files#diff-f27c62978dcbd8717b591269e831e3cc0eec4fbdb8fbf53f66435cd8450c4557R209-R283))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant