Green Grid Compass: upgrade api (BC) (#26809)
This commit is contained in:
parent
821f381e8c
commit
849bc997f7
2 changed files with 57 additions and 8 deletions
33
plugin/auth/clientcredentials.go
Normal file
33
plugin/auth/clientcredentials.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue