From 44f397e2de12a4993cd666dc80b6e93e7e8a6bbe Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Mon, 22 Aug 2022 09:32:30 +0200 Subject: [PATCH] fix lndhub --- internal/api/middleware.go | 5 +++++ main.go | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/api/middleware.go b/internal/api/middleware.go index f4eebf9..314aa23 100644 --- a/internal/api/middleware.go +++ b/internal/api/middleware.go @@ -31,6 +31,7 @@ type AuthType struct { var AuthTypeBasic = AuthType{Type: "Basic"} var AuthTypeBearerBase64 = AuthType{Type: "Bearer", Decoder: base64.StdEncoding.DecodeString} +var AuthTypeNone = AuthType{} // invoice key or admin key requirement type AccessKeyType struct { @@ -43,6 +44,10 @@ var AccessKeyTypeNone = AccessKeyType{Type: "none"} // no authorization required func AuthorizationMiddleware(database *gorm.DB, authType AuthType, accessType AccessKeyType, next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + if accessType.Type == "none" { + next.ServeHTTP(w, r) + return + } auth := r.Header.Get("Authorization") // check if the user is banned if auth == "" { diff --git a/main.go b/main.go index 11c8297..a85c8be 100644 --- a/main.go +++ b/main.go @@ -60,8 +60,7 @@ func startApiServer(bot *telegram.TipBot) { // append lndhub ctx functions hub := lndhub.New(bot) - //s.AppendRoute(`/lndhub/ext/{.*}`, hub.Handle) - // s.AppendRoute(`/lndhub/ext`, hub.Handle) + s.AppendAuthorizedRoute(`/lndhub/ext/auth`, api.AuthTypeNone, api.AccessKeyTypeNone, bot.DB.Users, hub.Handle) s.AppendAuthorizedRoute(`/lndhub/ext/{.*}`, api.AuthTypeBearerBase64, api.AccessKeyTypeAdmin, bot.DB.Users, hub.Handle) s.AppendAuthorizedRoute(`/lndhub/ext`, api.AuthTypeBearerBase64, api.AccessKeyTypeAdmin, bot.DB.Users, hub.Handle)