├── .gitignore ├── package.json ├── README.md ├── cli.js └── .github └── workflows └── node.js.yml /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | cli-* 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alexa-cookie-cli", 3 | "version": "5.0.1", 4 | "description": "Generate refresh_token for Alexa remote control", 5 | "author": { 6 | "name": "adn77", 7 | "email": "alex@loetzimmer.de" 8 | }, 9 | "contributors": [ 10 | { 11 | "name": "Apollon77", 12 | "email": "ingo@fischer-ka.de" 13 | } 14 | ], 15 | "homepage": "https://blog.loetzimmer.de/2021/09/alexa-remote-control-shell-script.html", 16 | "license": "MIT", 17 | "keywords": [ 18 | "alexa", 19 | "echo", 20 | "alexa remote control", 21 | "alexa.amazon.de" 22 | ], 23 | "dependencies": { 24 | "alexa-cookie2": "^5.0.1", 25 | "commander": "^11.1.0" 26 | }, 27 | "devDependencies": { 28 | "pkg": "^5.8.1" 29 | }, 30 | "repository": { 31 | "type": "git", 32 | "url": "git+https://github.com/adn77/alexa-cookie-cli.git" 33 | }, 34 | "bugs": { 35 | "url": "https://blog.loetzimmer.de/2021/09/alexa-remote-control-shell-script.html" 36 | }, 37 | "scripts": { 38 | "build-binaries": "pkg --targets node16-linux-x64,node16-win-x64,node16-macos-x64 cli.js" 39 | }, 40 | "main": "cli.js" 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # alexa-cookie-cli 2 | Binary of https://github.com/Apollon77/alexa-cookie (using pkg - https://github.com/vercel/pkg), get the [latest release here](https://github.com/adn77/alexa-cookie-cli/releases/latest). 3 | 4 | Without any further ado this will open a proxy of the Amazon login page on http://127.0.0.1:8080. 5 | 6 | **ATTENTION: without any options, the app is pre-programmed for a German Amazon account!** 7 | 8 | Once the login completes successfully, the command window will return the refresh_token required to run alexa_remote_control.sh. 9 | The token looks something like `Atnr|...` 10 | 11 | Additional options: 12 | ```` 13 | Usage: cli [options] 14 | 15 | Options: 16 | -q, --quiet Non-interactive, output refresh_token on StdOut and exit 17 | -d, --debug Turn on debug output to StdOut 18 | -A, --deviceAppName optional: Name of the Device registered with the Alexa app (default: alexa_cookie_cli) 19 | -p, --amazonPage optional: possible to use with different countries, default is "amazon.de" 20 | -b, --baseAmazonPage optional: Change the Proxy Amazon Page - all "western countries" directly use amazon.com! Change to amazon.co.jp for Japan 21 | -a, --amazonPageProxyLanguage optional: language to be used for the Amazon Sign-in page the proxy calls. default is "de_DE" 22 | -L, --acceptLanguage optional: webpage language, should match to amazon-Page, default is "de-DE" 23 | -u, --userAgent optional: own userAgent to use for all request, overwrites default one, should not be needed 24 | -H, --proxyOwnIp provide own IP(!) to later access the proxy. needed to setup all rewriting and proxy stuff internally (default: "127.0.0.1") 25 | -P, --proxyPort optional: use this port for the proxy, default is 8080 (default: 8080) 26 | -B, --proxyListenBind optional: set this to bind the proxy to a special IP, default is "0.0.0.0" 27 | -h, --help display help for command 28 | ```` 29 | 30 | For implementation in other projects, the session cookies can be obtained using the refresh_token like this: 31 | ```` 32 | POST /ap/exchangetoken/cookies HTTP/1.1 33 | x-amzn-identity-auth-domain: api.amazon.de 34 | 35 | requested_token_type=auth_cookies 36 | app_name=Amazon Alexa 37 | domain=www.amazon.de 38 | source_token_type=refresh_token 39 | source_token=Atnr|... 40 | ```` 41 | (make sure to URL-encode, etc. !) 42 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | const alexaCookie = require('alexa-cookie2'); 2 | const commander = require('commander'); 3 | const program = new commander.Command(); 4 | 5 | program 6 | .option('-q, --quiet', 'Non-interactive, output refresh_token on StdOut and exit') 7 | .option('-d, --debug') 8 | .option('-A, --deviceAppName ', 'optional: Name of the Device registered with the Alexa app', 'alexa_cookie_cli') 9 | .option('-p, --amazonPage ', 'optional: possible to use with different countries, default is "amazon.de"', 'amazon.de') 10 | .option('-b, --baseAmazonPage ', 'optional: Change the Proxy Amazon Page - all "western countries" directly use amazon.com! Change to amazon.co.jp for Japan', 'amazon.com') 11 | .option('-a, --amazonPageProxyLanguage ', 'optional: language to be used for the Amazon Sign-in page the proxy calls. default is "de_DE"', 'de_DE') 12 | .option('-L, --acceptLanguage ', 'optional: webpage language, should match to amazon-Page, default is "de-DE"', 'de-DE') 13 | .option('-H, --proxyOwnIp ', 'provide own IP(!) to later access the proxy. needed to setup all rewriting and proxy stuff internally', '127.0.0.1') 14 | .option('-P, --proxyPort ', 'optional: use this port for the proxy, default is 8080', 8080) 15 | .option('-B, --proxyListenBind ', 'optional: set this to bind the proxy to a special IP, default is "0.0.0.0"', '0.0.0.0') 16 | program.parse(); 17 | 18 | const config = program.opts(); 19 | config.setupProxy = true; 20 | config.proxyOnly = true; 21 | 22 | if ( config.debug ) { 23 | config.proxyLogLevel = 'warn'; 24 | config.logger = console.log; 25 | } 26 | 27 | alexaCookie.generateAlexaCookie( config, (err, result) => { 28 | if (result && result.refreshToken) { 29 | console.log("======================================================================="); 30 | console.log("Some of this data might be useful to you for additional token retrieval"); 31 | console.log(" Please store in a safe place ..."); 32 | console.log("======================================================================="); 33 | console.log(" macDms: " + JSON.stringify(result.macDms)); 34 | console.log(" ----------------------------------------------------------------------"); 35 | console.log(" deviceSerial: " + result.deviceSerial); 36 | console.log("======================================================================="); 37 | console.log(" refreshToken: " + result.refreshToken); 38 | console.log("======================================================================="); 39 | if (! program.opts().quiet) { 40 | while(true); 41 | } 42 | alexaCookie.stopProxyServer(); 43 | }else{ 44 | console.error( err + ' / ' + JSON.stringify(result)); 45 | } 46 | }); -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Deploy releases 5 | 6 | on: 7 | push: 8 | branches: 9 | - '*' 10 | tags: 11 | # normal versions 12 | - "v?[0-9]+.[0-9]+.[0-9]+" 13 | # pre-releases 14 | - "v?[0-9]+.[0-9]+.[0-9]+-**" 15 | jobs: 16 | deploy: 17 | 18 | # Trigger this step only when a commit on master is tagged with a version number 19 | if: | 20 | contains(github.event.head_commit.message, '[skip ci]') == false && 21 | github.event_name == 'push' && 22 | startsWith(github.ref, 'refs/tags/') 23 | 24 | runs-on: ubuntu-latest 25 | 26 | strategy: 27 | matrix: 28 | node-version: [16.x] 29 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 30 | 31 | steps: 32 | - uses: actions/checkout@v2 33 | - name: Use Node.js ${{ matrix.node-version }} 34 | uses: actions/setup-node@v2 35 | with: 36 | node-version: ${{ matrix.node-version }} 37 | 38 | - name: Extract the version and commit body from the tag 39 | id: extract_release 40 | # The body may be multiline, therefore we need to escape some characters 41 | run: | 42 | VERSION="${{ github.ref }}" 43 | VERSION=${VERSION##*/} 44 | VERSION=${VERSION##*v} 45 | echo "::set-output name=VERSION::$VERSION" 46 | BODY=$(git show -s --format=%b) 47 | BODY="${BODY//'%'/'%25'}" 48 | BODY="${BODY//$'\n'/'%0A'}" 49 | BODY="${BODY//$'\r'/'%0D'}" 50 | echo "::set-output name=BODY::$BODY" 51 | 52 | - name: Install dependencies 53 | run: npm ci 54 | 55 | - name: Create standalone binaries 56 | run: npm run build-binaries 57 | 58 | - name: Create Github Release 59 | id: create_release 60 | uses: actions/create-release@v1 61 | env: 62 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 63 | with: 64 | tag_name: ${{ github.ref }} 65 | release_name: Release v${{ steps.extract_release.outputs.VERSION }} 66 | draft: false 67 | # Prerelease versions create prereleases on Github 68 | prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }} 69 | body: ${{ steps.extract_release.outputs.BODY }} 70 | 71 | - name: Show directory contents 72 | run: ls -al 73 | 74 | - name: Upload Alexa-Cookie binary Windows 75 | id: upload-release-asset-windows 76 | uses: actions/upload-release-asset@v1 77 | env: 78 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 79 | with: 80 | upload_url: ${{ steps.create_release.outputs.upload_url }} 81 | asset_path: ./cli-win.exe 82 | asset_name: alexa-cookie-cli-win-x64.exe 83 | asset_content_type: application/vnd.microsoft.portable-executable 84 | 85 | - name: Upload Alexa-Cookie binary MacOS 86 | id: upload-release-asset-macos 87 | uses: actions/upload-release-asset@v1 88 | env: 89 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 90 | with: 91 | upload_url: ${{ steps.create_release.outputs.upload_url }} 92 | asset_path: ./cli-macos 93 | asset_name: alexa-cookie-cli-macos-x64 94 | asset_content_type: application/mac-binhex40 95 | 96 | - name: Upload Alexa-Cookie binary Linux 97 | id: upload-release-asset-Linux 98 | uses: actions/upload-release-asset@v1 99 | env: 100 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 101 | with: 102 | upload_url: ${{ steps.create_release.outputs.upload_url }} 103 | asset_path: ./cli-linux 104 | asset_name: alexa-cookie-cli-linux-x64 105 | asset_content_type: application/x-executable 106 | --------------------------------------------------------------------------------