Add auth config struct and restructure social auth provider config to enable iteration and adding other providers

This commit is contained in:
Ken-Håvard Lieng 2020-05-01 04:35:26 +02:00
parent 3d7011e504
commit b81e1e482a
2 changed files with 18 additions and 5 deletions

View File

@ -46,19 +46,19 @@ login = true
# Enable username/password registration # Enable username/password registration
registration = true registration = true
[auth.github] [auth.providers.github]
key = "" key = ""
secret = "" secret = ""
[auth.facebook] [auth.providers.facebook]
key = "" key = ""
secret = "" secret = ""
[auth.google] [auth.providers.google]
key = "" key = ""
secret = "" secret = ""
[auth.twitter] [auth.providers.twitter]
key = "" key = ""
secret = "" secret = ""

View File

@ -3,8 +3,8 @@ package config
import ( import (
"time" "time"
"github.com/khlieng/dispatch/storage"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/khlieng/dispatch/storage"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -18,6 +18,7 @@ type Config struct {
Defaults Defaults Defaults Defaults
HTTPS HTTPS HTTPS HTTPS
LetsEncrypt LetsEncrypt LetsEncrypt LetsEncrypt
Auth Auth
} }
type Defaults struct { type Defaults struct {
@ -51,6 +52,18 @@ type LetsEncrypt struct {
Email string Email string
} }
type Auth struct {
Anonymous bool
Login bool
Registration bool
Providers map[string]Provider
}
type Provider struct {
Key string
Secret string
}
func LoadConfig() (*Config, chan *Config) { func LoadConfig() (*Config, chan *Config) {
viper.SetConfigName("config") viper.SetConfigName("config")
viper.AddConfigPath(storage.Path.ConfigRoot()) viper.AddConfigPath(storage.Path.ConfigRoot())