Config UI: add redirect uri suggestion service (#25478)
This commit is contained in:
parent
694816512e
commit
8d94166d93
9 changed files with 101 additions and 121 deletions
|
|
@ -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
34
server/network/service.go
Normal 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})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue