Skip to content

Commit 4d33297

Browse files
authored
Viessmann: require redirect uri (BC) (#24827)
1 parent 8319ac1 commit 4d33297

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

plugin/auth/viessmann.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,21 @@ package auth
33
import (
44
"context"
55

6+
"dario.cat/mergo"
67
"github.com/evcc-io/evcc/util"
78
"github.com/evcc-io/evcc/util/request"
89
"golang.org/x/oauth2"
910
)
1011

11-
const (
12-
OAuthURI = "https://iam.viessmann-climatesolutions.com/idp/v3"
13-
RedirectURI = "http://localhost:4200/"
14-
// ^ the value of RedirectURI doesn't matter, but it must be the same between requests
15-
)
12+
const OAuthURI = "https://iam.viessmann-climatesolutions.com/idp/v3"
1613

17-
func oauth2Config(clientID string) *oauth2.Config {
18-
return &oauth2.Config{
19-
ClientID: clientID,
20-
Endpoint: oauth2.Endpoint{
21-
AuthURL: OAuthURI + "/authorize",
22-
TokenURL: OAuthURI + "/token",
23-
AuthStyle: oauth2.AuthStyleInHeader,
24-
},
25-
RedirectURL: RedirectURI,
26-
Scopes: []string{"IoT User", "offline_access"},
27-
}
14+
var oauthConfig = oauth2.Config{
15+
Endpoint: oauth2.Endpoint{
16+
AuthURL: OAuthURI + "/authorize",
17+
TokenURL: OAuthURI + "/token",
18+
AuthStyle: oauth2.AuthStyleInHeader,
19+
},
20+
Scopes: []string{"IoT User", "offline_access"},
2821
}
2922

3023
func init() {
@@ -33,8 +26,9 @@ func init() {
3326

3427
func NewViessmannFromConfig(ctx context.Context, other map[string]any) (oauth2.TokenSource, error) {
3528
var cc struct {
36-
ClientID string
37-
Gateway string
29+
ClientID string
30+
RedirectURI string
31+
Gateway string
3832
}
3933

4034
if err := util.DecodeOther(other, &cc); err != nil {
@@ -44,5 +38,13 @@ func NewViessmannFromConfig(ctx context.Context, other map[string]any) (oauth2.T
4438
log := util.NewLogger("viessmann").Redact(cc.ClientID)
4539
ctx = context.WithValue(ctx, oauth2.HTTPClient, request.NewClient(log))
4640

47-
return NewOauth(ctx, "Viessmann", cc.Gateway, oauth2Config(cc.ClientID))
41+
oc := oauth2.Config{
42+
ClientID: cc.ClientID,
43+
RedirectURL: cc.RedirectURI,
44+
}
45+
if err := mergo.Merge(&oc, oauthConfig); err != nil {
46+
return nil, err
47+
}
48+
49+
return NewOauth(ctx, "Viessmann", cc.Gateway, &oc)
4850
}

templates/definition/charger/viessmann.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ params:
2222
help:
2323
de: Konfigurieren in [app.developer.viessmann-climatesolutions.com](https://app.developer.viessmann-climatesolutions.com)
2424
en: Configure at [app.developer.viessmann-climatesolutions.com](https://app.developer.viessmann-climatesolutions.com)
25+
- name: redirecturi
26+
required: true
27+
description:
28+
generic: Redirect URI
29+
help:
30+
en: "Redirect URI of the evcc instance. Must match the redirect URI set in the Viessmann developer portal."
31+
de: "Redirect-URI der evcc-Instanz. Muss mit der Redirect URI übereinstimmen, die Viessmann Developer Portal konfiguriert ist."
32+
example: "https://evcc.example.org/providerauth/callback"
2533
- name: gateway_serial
2634
required: true
2735
description:
@@ -50,7 +58,7 @@ params:
5058
Dann holen wir uns einen oauth token (n.b. am besten den gesamten Block in das Terminal kopieren, da die Zwischenvariable 'CODE' nur 20 Sekunden gültig ist):
5159
5260
```
53-
VIESSMANN_REDIRECT_URI="http://localhost:4200/"
61+
VIESSMANN_REDIRECT_URI=<your-redirect-uri>
5462
VIESSMANN_CODE_CHALLENGE="5M5nhkBfkWZCGfLZYcTL-l7esjPUN7PpZ4rq8k4cmys"
5563
VIESSMANN_CODE_VERIFIER="6PygdmeK8JKPuuftlkc6q4ceyvjhMM_a_cJrPbcmcLc-SPjx2ZXTYr-SOofPUBydQ3McNYRy7Hibc2L2WtVLJFpOQ~Qbgic455ArKjUz9_UiTLnO6q8A3e.I_fIF8hAo"
5664
@@ -92,7 +100,7 @@ params:
92100
Then execute the following to get an oauth token (n.b. it's best to paste the entire block as-is, since the intermediate 'CODE' is only valid for 20 seconds):
93101
94102
```
95-
VIESSMANN_REDIRECT_URI="http://localhost:4200/"
103+
VIESSMANN_REDIRECT_URI=<your-redirect-uri>
96104
VIESSMANN_CODE_CHALLENGE="5M5nhkBfkWZCGfLZYcTL-l7esjPUN7PpZ4rq8k4cmys"
97105
VIESSMANN_CODE_VERIFIER="6PygdmeK8JKPuuftlkc6q4ceyvjhMM_a_cJrPbcmcLc-SPjx2ZXTYr-SOofPUBydQ3McNYRy7Hibc2L2WtVLJFpOQ~Qbgic455ArKjUz9_UiTLnO6q8A3e.I_fIF8hAo"
98106
@@ -149,6 +157,7 @@ render: |
149157
auth:
150158
source: viessmann
151159
clientid: {{ .clientid }}
160+
redirecturi: {{ .redirecturi }}
152161
gateway: {{ .gateway_serial }}
153162
jq: '.data.properties.active.value | if . == false then 2 elif . == true then 3 else . end'
154163
# false -> oneTimeCharge is disabled -> normal mode -> 2
@@ -170,6 +179,7 @@ render: |
170179
auth:
171180
source: viessmann
172181
clientid: {{ .clientid }}
182+
redirecturi: {{ .redirecturi }}
173183
gateway: {{ .gateway_serial }}
174184
body: >
175185
{ }
@@ -183,6 +193,7 @@ render: |
183193
auth:
184194
source: viessmann
185195
clientid: {{ .clientid }}
196+
redirecturi: {{ .redirecturi }}
186197
gateway: {{ .gateway_serial }}
187198
body: >
188199
{ }

0 commit comments

Comments
 (0)