Green Grid Compass: upgrade api (BC) (#26809)

This commit is contained in:
StefanSchoof 2026-01-22 09:05:13 +01:00 • committed by GitHub
parent 821f381e8c
commit 849bc997f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 57 additions and 8 deletions

View file

@ -0,0 +1,33 @@
package auth
import (
"context"
"errors"
"github.com/evcc-io/evcc/util"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
)
func init() {
registry.AddCtx("clientcredentials", NewClientcredentialsFromConfig)
}
func NewClientcredentialsFromConfig(ctx context.Context, other map[string]any) (oauth2.TokenSource, error) {
var cc clientcredentials.Config
if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}
switch {
case cc.ClientID == "":
return nil, errors.New("clientcredentials: missing required clientid")
case cc.ClientSecret == "":
return nil, errors.New("clientcredentials: missing required clientsecret")
case cc.TokenURL == "":
return nil, errors.New("clientcredentials: missing required tokenurl")
}
return cc.TokenSource(ctx), nil
}