Viessmann: require redirect uri (BC) (#24827)
Some checks failed
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled
Release / call-build-workflow (push) Has been cancelled

This commit is contained in:
andig 2025-10-28 18:00:01 +01:00 • committed by GitHub
parent 8319ac1ec6
commit 4d33297cad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 21 deletions

View file

@ -3,28 +3,21 @@ package auth
import (
"context"
"dario.cat/mergo"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
"golang.org/x/oauth2"
)
const (
OAuthURI = "https://iam.viessmann-climatesolutions.com/idp/v3"
RedirectURI = "http://localhost:4200/"
// ^ the value of RedirectURI doesn't matter, but it must be the same between requests
)
const OAuthURI = "https://iam.viessmann-climatesolutions.com/idp/v3"
func oauth2Config(clientID string) *oauth2.Config {
return &oauth2.Config{
ClientID: clientID,
Endpoint: oauth2.Endpoint{
AuthURL: OAuthURI + "/authorize",
TokenURL: OAuthURI + "/token",
AuthStyle: oauth2.AuthStyleInHeader,
},
RedirectURL: RedirectURI,
Scopes: []string{"IoT User", "offline_access"},
}
var oauthConfig = oauth2.Config{
Endpoint: oauth2.Endpoint{
AuthURL: OAuthURI + "/authorize",
TokenURL: OAuthURI + "/token",
AuthStyle: oauth2.AuthStyleInHeader,
},
Scopes: []string{"IoT User", "offline_access"},
}
func init() {
@ -33,8 +26,9 @@ func init() {
func NewViessmannFromConfig(ctx context.Context, other map[string]any) (oauth2.TokenSource, error) {
var cc struct {
ClientID string
Gateway string
ClientID string
RedirectURI string
Gateway string
}
if err := util.DecodeOther(other, &cc); err != nil {
@ -44,5 +38,13 @@ func NewViessmannFromConfig(ctx context.Context, other map[string]any) (oauth2.T
log := util.NewLogger("viessmann").Redact(cc.ClientID)
ctx = context.WithValue(ctx, oauth2.HTTPClient, request.NewClient(log))
return NewOauth(ctx, "Viessmann", cc.Gateway, oauth2Config(cc.ClientID))
oc := oauth2.Config{
ClientID: cc.ClientID,
RedirectURL: cc.RedirectURI,
}
if err := mergo.Merge(&oc, oauthConfig); err != nil {
return nil, err
}
return NewOauth(ctx, "Viessmann", cc.Gateway, &oc)
}