feat: add support for `allowUserIds` in config
continuous-integration/drone/push Build is passing Details

main
RaviAnand Mohabir 1 year ago
parent 150d1a20c8
commit 1e2e7adbb9

@ -8,6 +8,7 @@ import (
"gitea.ravianand.me/Dan6erbond/listy/core"
"gitea.ravianand.me/Dan6erbond/listy/internal"
"gitea.ravianand.me/Dan6erbond/listy/users"
"github.com/spf13/viper"
"github.com/zmb3/spotify/v2"
)
@ -65,6 +66,24 @@ func Callback(app *core.App) func(w http.ResponseWriter, r *http.Request) {
return
}
var allowUser bool
if allowUserIDs := viper.GetStringSlice("alloweduserids"); len(viper.GetStringSlice("alloweduserids")) != 0 {
for _, userID := range allowUserIDs {
if user.ID == userID {
allowUser = true
break
}
}
} else {
allowUser = true
}
if !allowUser {
http.Error(w, "You aren't allowed to access this application", http.StatusUnauthorized)
return
}
_, err = users.SaveUserToken(ctx, app, user.ID, token)
if err != nil {

Loading…
Cancel
Save