fix lndhub

This commit is contained in:
callebtc 2022-08-22 09:32:30 +02:00
parent 9451032552
commit 44f397e2de
2 changed files with 6 additions and 2 deletions

View file

@ -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 == "" {

View file

@ -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)