From b7b2c877e3553c4c1d65bead653e59a6933bfcf7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 15 Feb 2024 11:53:44 +0100 Subject: [PATCH 1/5] Advertice WebauthN support This well-known indicates for password manager, that passkeys are supported. source: https://android-developers.googleblog.com/2023/10/make-passkey-endpoints-well-known-url-part-of-your-passkey-implementation.html --- routers/web/passkey.go | 24 ++++++++++++++++++++++++ routers/web/web.go | 1 + 2 files changed, 25 insertions(+) create mode 100644 routers/web/passkey.go diff --git a/routers/web/passkey.go b/routers/web/passkey.go new file mode 100644 index 0000000000000..cabde0cf0d2e2 --- /dev/null +++ b/routers/web/passkey.go @@ -0,0 +1,24 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package web + +import ( + "net/http" + "path" + + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/setting" +) + +type passkeyEndpoints struct { + Enroll string `json:"enroll"` + Manage string `json:"manage"` +} + +func PasskeyEndpoints(ctx *context.Context) { + ctx.JSON(http.StatusOK, passkeyEndpoints{ + Enroll: path.Join(setting.AppURL, setting.AppSubURL, "user/settings/security"), + Manage: path.Join(setting.AppURL, setting.AppSubURL, "user/settings/security"), + }) +} diff --git a/routers/web/web.go b/routers/web/web.go index ba5c86cc7e3dd..3a8ada181b81c 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -473,6 +473,7 @@ func registerRoutes(m *web.Route) { m.Get("/change-password", func(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/user/settings/account") }) + m.Get("/passkey-endpoints", PasskeyEndpoints) m.Methods("GET, HEAD", "/*", public.FileHandlerFunc()) }, optionsCorsHandler()) From 92e0b7e6185bd2da6310c31c6544445f6fc95717 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 15 Feb 2024 13:25:26 +0100 Subject: [PATCH 2/5] unexport & dedup --- routers/web/passkey.go | 11 ++++++----- routers/web/web.go | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/routers/web/passkey.go b/routers/web/passkey.go index cabde0cf0d2e2..9d26dab069276 100644 --- a/routers/web/passkey.go +++ b/routers/web/passkey.go @@ -11,14 +11,15 @@ import ( "code.gitea.io/gitea/modules/setting" ) -type passkeyEndpoints struct { +type passkeyEndpointsType struct { Enroll string `json:"enroll"` Manage string `json:"manage"` } -func PasskeyEndpoints(ctx *context.Context) { - ctx.JSON(http.StatusOK, passkeyEndpoints{ - Enroll: path.Join(setting.AppURL, setting.AppSubURL, "user/settings/security"), - Manage: path.Join(setting.AppURL, setting.AppSubURL, "user/settings/security"), +func passkeyEndpoints(ctx *context.Context) { + url := path.Join(setting.AppURL, setting.AppSubURL, "user/settings/security") + ctx.JSON(http.StatusOK, passkeyEndpointsType{ + Enroll: url, + Manage: url, }) } diff --git a/routers/web/web.go b/routers/web/web.go index 3a8ada181b81c..7aa9bb07950a3 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -473,7 +473,7 @@ func registerRoutes(m *web.Route) { m.Get("/change-password", func(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/user/settings/account") }) - m.Get("/passkey-endpoints", PasskeyEndpoints) + m.Get("/passkey-endpoints", passkeyEndpoints) m.Methods("GET, HEAD", "/*", public.FileHandlerFunc()) }, optionsCorsHandler()) From c7c25eaa71df408f5b116543eb023c2cbc073c9a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 15 Feb 2024 14:27:27 +0100 Subject: [PATCH 3/5] Update routers/web/passkey.go --- routers/web/passkey.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/passkey.go b/routers/web/passkey.go index 9d26dab069276..e2f0b8a74ed0f 100644 --- a/routers/web/passkey.go +++ b/routers/web/passkey.go @@ -17,7 +17,7 @@ type passkeyEndpointsType struct { } func passkeyEndpoints(ctx *context.Context) { - url := path.Join(setting.AppURL, setting.AppSubURL, "user/settings/security") + url := path.Join(setting.AppURL, "user/settings/security") ctx.JSON(http.StatusOK, passkeyEndpointsType{ Enroll: url, Manage: url, From 48cb1ff1e3f882ac2760460a95a7c33ae88b6e4a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 15 Feb 2024 18:20:39 +0100 Subject: [PATCH 4/5] Update routers/web/passkey.go Co-authored-by: KN4CK3R --- routers/web/passkey.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/passkey.go b/routers/web/passkey.go index e2f0b8a74ed0f..088f4c677c21b 100644 --- a/routers/web/passkey.go +++ b/routers/web/passkey.go @@ -17,7 +17,7 @@ type passkeyEndpointsType struct { } func passkeyEndpoints(ctx *context.Context) { - url := path.Join(setting.AppURL, "user/settings/security") + url := setting.AppURL + "user/settings/security" ctx.JSON(http.StatusOK, passkeyEndpointsType{ Enroll: url, Manage: url, From aa6b9f6846c731ea2b253b2b129c41ccfe6351f2 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 15 Feb 2024 18:23:23 +0100 Subject: [PATCH 5/5] Update routers/web/passkey.go --- routers/web/passkey.go | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/web/passkey.go b/routers/web/passkey.go index 088f4c677c21b..95874dfc48d71 100644 --- a/routers/web/passkey.go +++ b/routers/web/passkey.go @@ -5,7 +5,6 @@ package web import ( "net/http" - "path" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting"