@@ -58,7 +58,7 @@ Wichtig:
5858| ` COOKIE_EXPORT_FILE ` | Optional | ` ${DATA_DIR}/cookie.json ` | Zieldatei fuer die von ` 37_echodevice.pm ` erwartete Cookie-Cachedatei |
5959| ` DEBUG_HTML_DIR ` | Optional | ` ${DATA_DIR}/debug-html ` | Ablageort fuer Debug-Artefakte aus dem Login-Flow |
6060| ` AMAZON_PAGE ` | Optional | ` amazon.de ` | Ziel-Region fuer den Amazon-Login |
61- | ` BASE_AMAZON_PAGE ` | Optional | Wert von ` AMAZON_PAGE ` | Basis-Domain fuer den Login-Flow |
61+ | ` BASE_AMAZON_PAGE ` | Optional | ` amazon.com ` | Basis-Domain fuer den Login-Flow; fuer westliche Regionen in der Regel ` amazon.com ` , fuer Japan ` amazon.co.jp ` |
6262| ` ACCEPT_LANGUAGE ` | Optional | ` de-DE ` | Sprach-Header fuer den Login-Flow |
6363| ` PROXY_OWN_IP ` | Pflicht | leer | Von Browsern erreichbare IP oder DNS-Name des Docker-Hosts fuer den Login-Proxy |
6464| ` PROXY_LISTEN_BIND ` | Optional | ` 0.0.0.0 ` | Bind-Adresse des Login-Proxys im Container |
@@ -72,10 +72,21 @@ Wichtig:
7272| ` REQUEST_TIMEOUT_MS ` | Optional | ` 30000 ` | Timeout fuer Netzwerkoperationen in Millisekunden |
7373| ` LOG_LEVEL ` | Optional | ` combined ` | Format/Level fuer HTTP-Request-Logging |
7474
75+ ` AMAZON_PAGE ` und ` BASE_AMAZON_PAGE ` haben unterschiedliche Aufgaben:
76+
77+ - ` AMAZON_PAGE ` ist die eigentliche Ziel-Region fuer das Amazon-Konto, z.B. ` amazon.de ` .
78+ - ` BASE_AMAZON_PAGE ` ist die Basis-Domain des Login-Flows.
79+
80+ Empfehlung:
81+
82+ - Fuer Deutschland und die meisten westlichen Laender ` AMAZON_PAGE=amazon.de|amazon.fr|amazon.it|amazon.es|amazon.co.uk ` passend zur Region setzen, aber ` BASE_AMAZON_PAGE=amazon.com ` belassen.
83+ - Nur fuer Japan ` BASE_AMAZON_PAGE=amazon.co.jp ` setzen.
84+ - ` BASE_AMAZON_PAGE ` nur dann von ` amazon.com ` abweichend setzen, wenn der Login-Flow mit dem Standardwert nicht funktioniert oder ` alexa-cookie2 ` dies fuer die jeweilige Region verlangt.
85+
7586### 2. Starten
7687
7788``` bash
78- docker pull ghcr.io/fhem/alexa-cookie-service:0.2.0
89+ docker pull ghcr.io/fhem/alexa-cookie-service:0.2.1
7990docker compose up -d
8091```
8192
@@ -135,25 +146,8 @@ Funktionsfähiges Beispiel für einen gemeinsamen Compose-Stack:
135146
136147``` yaml
137148services :
138- fhem :
139- image : ghcr.io/fhem/fhem-docker:5-bookworm
140- volumes :
141- - " ./fhem/:/opt/fhem/"
142- - " ./fhem/cache:/opt/fhem/cache"
143- environment :
144- FHEM_UID : 6061
145- FHEM_GID : 6061
146- TIMEOUT : 10
147- RESTART : 1
148- TZ : Europe/Berlin
149- ports :
150- - " 8083:8083"
151- networks :
152- - fhem_cookie_net
153- restart : always
154-
155149 alexa-cookie-service :
156- image : ghcr.io/fhem/alexa-cookie-service:0.2.0
150+ image : ghcr.io/fhem/alexa-cookie-service:0.2.1
157151 volumes :
158152 - ./alexa-cookie-data:/data
159153 - ./fhem/cache:/opt/fhem/cache
@@ -172,6 +166,23 @@ services:
172166 restart : unless-stopped
173167 user : " 6061:6061"
174168
169+ fhem :
170+ image : ghcr.io/fhem/fhem-docker:5-bookworm
171+ volumes :
172+ - " ./fhem/:/opt/fhem/"
173+ - " ./fhem/cache:/opt/fhem/cache"
174+ environment :
175+ FHEM_UID : 6061
176+ FHEM_GID : 6061
177+ TIMEOUT : 10
178+ RESTART : 1
179+ TZ : Europe/Berlin
180+ ports :
181+ - " 8083:8083"
182+ networks :
183+ - fhem_cookie_net
184+ restart : always
185+
175186networks :
176187 fhem_cookie_net :
177188 driver : bridge
@@ -183,7 +194,7 @@ In diesem Setup:
183194- die aktuelle Cookie-Cachedatei liegt für FHEM direkt unter `./fhem/cache/alexa-cookie.json`
184195
185196Das Beispiel verwendet `ghcr.io/fhem/fhem-docker:5-bookworm`,
186- das veröffentlichte Image `ghcr.io/fhem/alexa-cookie-service:0.2.0 `
197+ das veröffentlichte Image `ghcr.io/fhem/alexa-cookie-service:0.2.1 `
187198und ein dediziertes Docker-Netz.
188199
189200Wichtig :
@@ -263,13 +274,16 @@ ohne ihn im Klartext in jedem `define` zu hinterlegen.
263274
264275Das Beispiel ruft den Refresh-Endpunkt auf
265276und spiegelt danach die JSON-Cachedatei in eine lokale Datei,
266- die `37_echodevice.pm` direkt verwenden kann :
277+ die `37_echodevice.pm` direkt verwenden kann.
278+ Wenn FHEM und `alexa-cookie-service` in getrennten Containern laufen,
279+ aber im selben Docker-Netz sind, muss hier der Docker-Service-Name
280+ statt `127.0.0.1` verwendet werden :
267281
268282` ` ` perl
269283define AlexaCookieRefresh at +*06:00:00 {
270284 my $token = getKeyValue('alexa_cookie_service_token');;
271285 return 'missing token' if !$token;;
272- my $base = 'http://127.0.0.1 :58080';;
286+ my $base = 'http://alexa-cookie-service :58080';;
273287
274288 my $refresh = qx(curl -fsS -X POST -H 'x-auth-token: $token' $base/api/refresh 2>&1);;
275289 return "refresh failed: $refresh" if $? != 0;;
@@ -305,23 +319,122 @@ define AlexaCookieRefresh at +*06:00:00 {
305319
306320In diesem Fall verwendet `37_echodevice.pm` direkt `/opt/fhem/cache/alexa-cookie.json`.
307321
308- # ## HTTPMOD-Beispiel für Status/Monitoring
322+ # ## HTTPMOD-Beispiel fuer Login-Start, Refresh und Status
323+
324+ ` HTTPMOD` kann den Registrierungsprozess direkt anstossen,
325+ ohne dass `AUTH_TOKEN` im Klartext in den Attributen stehen muss.
326+ Dafuer wird der Token einmalig per `storeKeyValue` gespeichert
327+ und vor dem Senden per `replacement...Mode key` in die Header eingesetzt.
328+
329+ # ### 1. Token einmalig in HTTPMOD speichern
330+
331+ ` ` ` text
332+ set AlexaCookie storeKeyValue alexa_cookie_service_token change-me
333+ ` ` `
309334
310- Für Monitoring ist `HTTPMOD` sinnvoller als für den eigentlichen Cookie-Download.
311- Beispiel für `/api/status` :
335+ # ### 2. HTTPMOD-Definition in FHEM anlegen
312336
313337` ` ` text
314- define AlexaCookieStatus HTTPMOD http://127.0.0.1:58080/api/status 300
315- attr AlexaCookieStatus requestHeader01 x-auth-token: change-me
316- attr AlexaCookieStatus reading01JSON ok
317- attr AlexaCookieStatus reading02JSON updatedAt
318- attr AlexaCookieStatus reading03JSON ageHours
319- attr AlexaCookieStatus reading04JSON hasCookie
320- attr AlexaCookieStatus reading05JSON hasRefreshToken
338+ define AlexaCookie HTTPMOD http://alexa-cookie-service:58080/api/status 300
339+
340+ attr AlexaCookie replacement01Mode key
341+ attr AlexaCookie replacement01Regex %%ACS_TOKEN%%
342+ attr AlexaCookie replacement01Value alexa_cookie_service_token
343+
344+ attr AlexaCookie reading01JSON ok
345+ attr AlexaCookie reading02JSON updatedAt
346+ attr AlexaCookie reading03JSON ageHours
347+ attr AlexaCookie reading04JSON hasCookie
348+ attr AlexaCookie reading05JSON hasRefreshToken
349+ attr AlexaCookie reading06JSON proxyUrl
350+ attr AlexaCookie reading07JSON message
351+ attr AlexaCookie reading08JSON error
352+
353+ attr AlexaCookie set01Name loginStart
354+ attr AlexaCookie set01NoArg 1
355+ attr AlexaCookie set01Method POST
356+ attr AlexaCookie set01URL http://alexa-cookie-service:58080/api/login/start
357+ attr AlexaCookie set01Header1 x-auth-token: %%ACS_TOKEN%%
358+ attr AlexaCookie set01Header2 Content-Type: application/json
359+ attr AlexaCookie set01Data {}
360+ attr AlexaCookie set01ParseResponse 1
361+
362+ attr AlexaCookie set02Name refresh
363+ attr AlexaCookie set02NoArg 1
364+ attr AlexaCookie set02Method POST
365+ attr AlexaCookie set02URL http://alexa-cookie-service:58080/api/refresh
366+ attr AlexaCookie set02Header1 x-auth-token: %%ACS_TOKEN%%
367+ attr AlexaCookie set02Header2 Content-Type: application/json
368+ attr AlexaCookie set02Data {}
369+ attr AlexaCookie set02ParseResponse 1
370+
371+ attr AlexaCookie get01Name loginUrl
372+ attr AlexaCookie get01URL http://alexa-cookie-service:58080/api/login/url
373+ attr AlexaCookie get01Header1 x-auth-token: %%ACS_TOKEN%%
374+
375+ attr AlexaCookie showMatched 1
376+ attr AlexaCookie showError 1
321377` ` `
322378
323- Wenn der Token nicht im Klartext in den Attributen stehen soll,
324- ist der Refresh-/Fetch-Ablauf über einen Perl-Block
325- oder ein kleines Shell-Skript in FHEM meist direkter als `HTTPMOD`.
379+ # ### 3. Verwendung
380+
381+ Der Login-/Proxy-Flow kann dann direkt aus FHEM gestartet werden :
382+
383+ ` ` ` text
384+ set AlexaCookie loginStart
385+ ` ` `
386+
387+ Die Antwort wird nur dann in Readings ausgewertet,
388+ wenn `set01ParseResponse 1` gesetzt ist.
389+ Danach stehen insbesondere `proxyUrl`, `message` oder `error` als Readings zur Verfuegung.
390+ Die URL aus `proxyUrl` muss anschliessend im Browser geoeffnet werden.
391+
392+ Alternativ kann die Proxy-URL explizit per `get` abgefragt werden :
393+
394+ ` ` ` text
395+ get AlexaCookie loginUrl
396+ ` ` `
397+
398+ Einen Refresh des bereits gespeicherten Zustands startet :
399+
400+ ` ` ` text
401+ set AlexaCookie refresh
402+ ` ` `
403+
404+ # ### 3a. Refresh per notify oder at ausloesen
405+
406+ Wenn `37_echodevice.pm` und `alexa-cookie-service` denselben Cache
407+ unter `/opt/fhem/cache/alexa-cookie.json` verwenden, kann ein `notify`
408+ direkt den HTTPMOD-Refresh ausloesen :
409+
410+ ` ` ` perl
411+ define n_AlexaCookieRefresh notify <DEIN_TRIGGER>:.* {
412+ fhem('set AlexaCookie refresh');
413+ }
414+ ` ` `
415+
416+ Wenn der Refresh nur periodisch laufen soll, ist ein `at`
417+ meist einfacher als ein `notify` :
418+
419+ ` ` ` perl
420+ define at_AlexaCookieRefresh at +*16:00:00 set AlexaCookie refresh
421+ ` ` `
422+
423+ Ein `notify` lohnt sich vor allem dann, wenn der Refresh
424+ durch ein anderes Event angestossen werden soll,
425+ z.B. durch ein Dummy, einen Schalter oder einen Fehlerzustand.
426+
427+ # ### 4. Hinweise fuer Docker-Setups
428+
429+ Wenn FHEM und `alexa-cookie-service` in Containern im selben Docker-Netz laufen, muss der Service-Name verwendet werden.
430+
431+ ` ` ` text
432+ http://alexa-cookie-service:58080
433+ ` ` `
434+
435+ Wichtig :
436+ - der API-Port des Services ist standardmaessig `58080`
437+ - der Browser-Login selbst laeuft ueber den Proxy-Port `58090`
438+ - fuer die Auswertung von `set`-Antworten ist `setXXParseResponse 1` noetig
326439
327- Ein minimales Shell-Beispiel liegt zusätzlich in `scripts/example_fhem_notify.txt`.
440+ Ein minimales Shell-Beispiel liegt zusaetzlich in `scripts/example_fhem_notify.txt`.
0 commit comments