mirror of
https://github.com/thorsten-gehrig/alexa-remote-control.git
synced 2025-03-31 15:53:14 +02:00
Implemented refresh_token cookie exchange
This commit is contained in:
parent
d6a8b57531
commit
8309a07a16
@ -70,6 +70,8 @@
|
|||||||
# 2021-09-02: v0.19 Playing TuneIn works again using new entertainment API endpoint
|
# 2021-09-02: v0.19 Playing TuneIn works again using new entertainment API endpoint
|
||||||
# Added playmusic (Alexa.Music.PlaySearchPhrase) as command, for available channels use "-c"
|
# Added playmusic (Alexa.Music.PlaySearchPhrase) as command, for available channels use "-c"
|
||||||
# Note: playmusic is not multi-room capable, doing so might lead to unexpected results
|
# Note: playmusic is not multi-room capable, doing so might lead to unexpected results
|
||||||
|
# 2021-09-13: v0.20 implemented device registration refresh_token cookie exchange flow as an alternative
|
||||||
|
# to logging in
|
||||||
#
|
#
|
||||||
###
|
###
|
||||||
#
|
#
|
||||||
@ -88,6 +90,10 @@ SET_MFA_SECRET=''
|
|||||||
# something like:
|
# something like:
|
||||||
# 1234 5678 9ABC DEFG HIJK LMNO PQRS TUVW XYZ0 1234 5678 9ABC DEFG
|
# 1234 5678 9ABC DEFG HIJK LMNO PQRS TUVW XYZ0 1234 5678 9ABC DEFG
|
||||||
|
|
||||||
|
# this can be obtained by doing the device registration login flow
|
||||||
|
# e.g. from here: https://github.com/Apollon77/alexa-cookie/
|
||||||
|
SET_REFRESH_TOKEN=''
|
||||||
|
|
||||||
SET_LANGUAGE='de,en-US;q=0.7,en;q=0.3'
|
SET_LANGUAGE='de,en-US;q=0.7,en;q=0.3'
|
||||||
#SET_LANGUAGE='en-US'
|
#SET_LANGUAGE='en-US'
|
||||||
|
|
||||||
@ -143,6 +149,7 @@ SET_VOLMAXAGE="1"
|
|||||||
EMAIL=${EMAIL:-$SET_EMAIL}
|
EMAIL=${EMAIL:-$SET_EMAIL}
|
||||||
PASSWORD=${PASSWORD:-$SET_PASSWORD}
|
PASSWORD=${PASSWORD:-$SET_PASSWORD}
|
||||||
MFA_SECRET=${MFA_SECRET:-$SET_MFA_SECRET}
|
MFA_SECRET=${MFA_SECRET:-$SET_MFA_SECRET}
|
||||||
|
REFRESH_TOKEN=${REFRESH_TOKEN:-$SET_REFRESH_TOKEN}
|
||||||
AMAZON=${AMAZON:-$SET_AMAZON}
|
AMAZON=${AMAZON:-$SET_AMAZON}
|
||||||
ALEXA=${ALEXA:-$SET_ALEXA}
|
ALEXA=${ALEXA:-$SET_ALEXA}
|
||||||
LANGUAGE=${LANGUAGE:-$SET_LANGUAGE}
|
LANGUAGE=${LANGUAGE:-$SET_LANGUAGE}
|
||||||
@ -231,7 +238,7 @@ usage()
|
|||||||
while [ "$#" -gt 0 ] ; do
|
while [ "$#" -gt 0 ] ; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--version)
|
--version)
|
||||||
echo "v0.19"
|
echo "v0.20"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
-d)
|
-d)
|
||||||
@ -500,6 +507,7 @@ rm -f ${DEVLIST}
|
|||||||
rm -f ${COOKIE}
|
rm -f ${COOKIE}
|
||||||
rm -f ${TMP}/.alexa.*.list
|
rm -f ${TMP}/.alexa.*.list
|
||||||
|
|
||||||
|
if [ -z "${REFRESH_TOKEN}" ] ; then
|
||||||
#
|
#
|
||||||
# get first cookie and write redirection target into referer
|
# get first cookie and write redirection target into referer
|
||||||
#
|
#
|
||||||
@ -548,6 +556,20 @@ if [ -z "$(grep 'Location: https://alexa.*html' ${TMP}/.alexa.header2)" ] ; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f "${TMP}/.alexa.login"
|
||||||
|
rm -f "${TMP}/.alexa.header"
|
||||||
|
rm -f "${TMP}/.alexa.header2"
|
||||||
|
rm -f "${TMP}/.alexa.postdata"
|
||||||
|
rm -f "${TMP}/.alexa.postdata2"
|
||||||
|
else
|
||||||
|
${CURL} ${OPTS} -s -X POST --data "app_name=Amazon%20Alexa&requested_token_type=auth_cookies&domain=www.${AMAZON}&source_token_type=refresh_token" --data-urlencode "source_token=${REFRESH_TOKEN}" -H "x-amzn-identity-auth-domain: api.${AMAZON}" https://api.${AMAZON}/ap/exchangetoken/cookies | jq -r '.response.tokens.cookies | to_entries[] | .key as $domain | .value[] | map_values(if . == true then "TRUE" else . end) | .Expires |= ( strptime("%d %b %Y %H:%M:%S %Z") | mktime | strftime("%s") ) | [(if .HttpOnly=="TRUE" then ("#HttpOnly_" + $domain) else $domain end), "TRUE", .Path, .Secure, .Expires, .Name, .Value] | @tsv' > ${COOKIE}
|
||||||
|
|
||||||
|
if [ -z "$(grep ".${AMAZON}.*at-acbde" ${COOKIE})" ] ; then
|
||||||
|
echo "ERROR: cookie retrieval with refresh_token didn't work"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# get CSRF
|
# get CSRF
|
||||||
#
|
#
|
||||||
@ -569,12 +591,6 @@ if [ -z "$(grep ".${AMAZON}.*csrf" ${COOKIE})" ] ; then
|
|||||||
https://${ALEXA}/api/devices-v2/device?cached=false > /dev/null
|
https://${ALEXA}/api/devices-v2/device?cached=false > /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "${TMP}/.alexa.login"
|
|
||||||
rm -f "${TMP}/.alexa.header"
|
|
||||||
rm -f "${TMP}/.alexa.header2"
|
|
||||||
rm -f "${TMP}/.alexa.postdata"
|
|
||||||
rm -f "${TMP}/.alexa.postdata2"
|
|
||||||
|
|
||||||
if [ -z "$(grep ".${AMAZON}.*csrf" ${COOKIE})" ] ; then
|
if [ -z "$(grep ".${AMAZON}.*csrf" ${COOKIE})" ] ; then
|
||||||
echo "ERROR: no CSRF cookie received"
|
echo "ERROR: no CSRF cookie received"
|
||||||
exit 1
|
exit 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user