From a3e29a092d4175fe41828e043b72b02b4cb9062b Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Sat, 13 Apr 2024 11:06:23 +0200
Subject: [PATCH] feat(gitea)!: use `Bearer` instead of `token` for auth
 (#28308)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Previous Gitea implementation used non-standard “token” auth instead of “Bearer”. Gitea supports Bearer al alternate to token since v1.8.0, so it’s safe to make this change now.

BREAKING CHANGE: Gitea platfor authentication will now be done using Bearer auth instead of token auth.
---
 lib/util/http/auth.spec.ts | 2 +-
 lib/util/http/auth.ts      | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/util/http/auth.spec.ts b/lib/util/http/auth.spec.ts
index 2854af307c..208a8209b6 100644
--- a/lib/util/http/auth.spec.ts
+++ b/lib/util/http/auth.spec.ts
@@ -57,7 +57,7 @@ describe('util/http/auth', () => {
       expect(opts).toMatchInlineSnapshot(`
         {
           "headers": {
-            "authorization": "token XXXX",
+            "authorization": "Bearer XXXX",
           },
           "hostType": "gitea",
           "token": "XXXX",
diff --git a/lib/util/http/auth.ts b/lib/util/http/auth.ts
index 99cc9bec81..0beec921d9 100644
--- a/lib/util/http/auth.ts
+++ b/lib/util/http/auth.ts
@@ -40,7 +40,9 @@ export function applyAuthorization<GotOptions extends AuthGotOptions>(
       options.hostType &&
       GITEA_API_USING_HOST_TYPES.includes(options.hostType)
     ) {
-      options.headers.authorization = `token ${options.token}`;
+      // Gitea v1.8.0 and later support `Bearer` as alternate to `token`
+      // https://github.com/go-gitea/gitea/pull/5378
+      options.headers.authorization = `Bearer ${options.token}`;
     } else if (
       options.hostType &&
       GITHUB_API_USING_HOST_TYPES.includes(options.hostType)
-- 
GitLab