mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-17 13:07:16 +02:00
fix lndhub
This commit is contained in:
parent
9451032552
commit
44f397e2de
2 changed files with 6 additions and 2 deletions
|
|
@ -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 == "" {
|
||||
|
|
|
|||
3
main.go
3
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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue