Powerwall: add Fleet API support (BC) (#32410)
This commit is contained in:
parent
28e41bdd09
commit
fdea008b0b
21 changed files with 548 additions and 200 deletions
45
util/oauth/config.go
Normal file
45
util/oauth/config.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package oauth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
// ClientCredentials contains OAuth2 client id and secret
|
||||
type ClientCredentials struct {
|
||||
ID, Secret string
|
||||
}
|
||||
|
||||
// Error validates the credentials and returns an error if they are incomplete
|
||||
func (c *ClientCredentials) Error() error {
|
||||
if c.ID == "" {
|
||||
return errors.New("missing client id")
|
||||
}
|
||||
|
||||
if c.Secret == "" {
|
||||
return errors.New("missing client secret")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Tokens contains access and refresh tokens
|
||||
type Tokens struct {
|
||||
Access, Refresh string
|
||||
}
|
||||
|
||||
// Token builds token from credentials and returns an error if they are incomplete
|
||||
func (t *Tokens) Token() (*oauth2.Token, error) {
|
||||
if t.Access == "" && t.Refresh == "" {
|
||||
return nil, api.ErrMissingToken
|
||||
}
|
||||
|
||||
return &oauth2.Token{
|
||||
AccessToken: t.Access,
|
||||
RefreshToken: t.Refresh,
|
||||
Expiry: time.Now(),
|
||||
}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue