From 94c4da0a92583093cfb9ca0aba5d3a51ce6a2e9b Mon Sep 17 00:00:00 2001
From: Nagarajan Shanmugam <94837505+nagashan@users.noreply.github.com>
Date: Thu, 21 Dec 2023 09:39:52 +0530
Subject: [PATCH] [extension/bearertokenauthextension] Fix for extension Always
return "401 Unauthorized" via HTTP connection #24656 (#29992)
Fix for extension Always return "401 Unauthorized" via HTTP connection
#24656
**Description:** We are always trying to get the `authorization` with
the lower case from headers, But The headers from Http is received as
`Authorization` capitalcase even-though we sent in lower case.
**Link to tracking Issue:**
<[24656](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/24656)>
**Testing:** Tested in the local
---------
Co-authored-by: Curtis Robert
---
...ga_fix_24656-http-bearertokenauth-401.yaml | 27 +++++++++++++++++++
.../bearertokenauth.go | 3 +++
2 files changed, 30 insertions(+)
create mode 100755 .chloggen/naga_fix_24656-http-bearertokenauth-401.yaml
diff --git a/.chloggen/naga_fix_24656-http-bearertokenauth-401.yaml b/.chloggen/naga_fix_24656-http-bearertokenauth-401.yaml
new file mode 100755
index 000000000000..2970cb3063a3
--- /dev/null
+++ b/.chloggen/naga_fix_24656-http-bearertokenauth-401.yaml
@@ -0,0 +1,27 @@
+# Use this changelog template to create an entry for release notes.
+
+# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
+change_type: bug_fix
+
+# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
+component: bearertokenauthextension
+
+# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
+note: "Http receiver trying to get the authorization with the lower case from headers, But The headers from Http is received as Authorization capitalcase even-though we sent in lower case and Always return 401 Unauthorized"
+
+# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
+issues: [24656]
+
+# (Optional) One or more lines of additional information to render under the primary note.
+# These lines will be padded with 2 spaces and then inserted directly into the document.
+# Use pipe (|) for multiline entries.
+subtext:
+
+# If your change doesn't affect end users or the exported elements of any package,
+# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
+# Optional: The change log or logs in which this entry should be included.
+# e.g. '[user]' or '[user, api]'
+# Include 'user' if the change is relevant to end users.
+# Include 'api' if there is a change to a library API.
+# Default: '[user]'
+change_logs: [user]
diff --git a/extension/bearertokenauthextension/bearertokenauth.go b/extension/bearertokenauthextension/bearertokenauth.go
index c4d420db2cc6..b41521925142 100644
--- a/extension/bearertokenauthextension/bearertokenauth.go
+++ b/extension/bearertokenauthextension/bearertokenauth.go
@@ -180,6 +180,9 @@ func (b *BearerTokenAuth) RoundTripper(base http.RoundTripper) (http.RoundTrippe
// Authenticate checks whether the given context contains valid auth data.
func (b *BearerTokenAuth) Authenticate(ctx context.Context, headers map[string][]string) (context.Context, error) {
auth, ok := headers["authorization"]
+ if !ok {
+ auth, ok = headers["Authorization"]
+ }
if !ok || len(auth) == 0 {
return ctx, errors.New("authentication didn't succeed")
}