Config UI: add redirect uri suggestion service (#25478)

This commit is contained in:
andig 2025-11-23 18:03:56 +01:00 • committed by GitHub
parent 694816512e
commit 8d94166d93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 101 additions and 121 deletions

View file

@ -1,33 +0,0 @@
package network
import (
"sync"
"github.com/evcc-io/evcc/api/globalconfig"
)
var (
mu sync.Mutex
registry []func()
)
var config globalconfig.Network
func Config() globalconfig.Network {
return config
}
func Register(fun func()) {
mu.Lock()
defer mu.Unlock()
registry = append(registry, fun)
}
func Start(conf globalconfig.Network) {
config = conf
for _, fun := range registry {
go fun()
}
}

34
server/network/service.go Normal file
View file

@ -0,0 +1,34 @@
package network
import (
"encoding/json"
"net/http"
"github.com/evcc-io/evcc/api/globalconfig"
"github.com/evcc-io/evcc/server/service"
)
var config globalconfig.Network
const CallbackPath = "/providerauth/callback"
func init() {
// auth service is registered here to avoid import cycle
mux := http.NewServeMux()
mux.HandleFunc("GET /redirecturi", getRedirectUri)
service.Register("auth", mux)
}
func Start(conf globalconfig.Network) {
config = conf
}
func Config() globalconfig.Network {
return config
}
func getRedirectUri(w http.ResponseWriter, req *http.Request) {
uri := config.ExternalURL() + CallbackPath
json.NewEncoder(w).Encode([]string{uri})
}