This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
getToken.sh
executable file
·62 lines (60 loc) · 2.11 KB
/
getToken.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
clear
echo "This script will walk you through getting a Nest Token."
echo "The first thing you'll have to do is create a developer account."
echo "Please copy and paste this URL into the browser of your choice."
echo -e "\033[01;32m"
echo "https://developers.nest.com/nl/auth/new"
echo -e "\e[0m"
echo "Create a new devloper login by clicking on"
echo ""
echo "\"Don't have an account? Sign up>\""
echo ""
echo "After you sign up, log in then come back to this script for how to continue."
echo -n "Press any button to continue..."
read -n 1 -s
echo ""
echo ""
echo "Great! You have an account. Now click on \"Create cloud product\""
echo "Fill out every required section, along with \"Thermostat\" & \"Protect\" in the Permissions Section."
echo "You can make it read or read/write, it doesnt matter for this module."
echo "Click on Create Project and fill out any extra required fields you missed."
echo ""
echo "Almost there, now open up your project page and get ready to copy some of the"
echo "data on the right side to input here:"
echo ""
echo ""
echo -n "Input Product ID: "
read productID
echo -n "Input Product Secret: "
read productSecret
echo ""
echo ""
echo "Copy this URL into your browser, log in with your nest account info. After that you'll be given a PIN."
echo -e "\033[01;32m"
echo "https://home.nest.com/login/oauth2?client_id=$productID&state=goodState"
echo -e "\e[0m"
echo "Copy that PIN and paste it in this script when asked."
echo -n "Press any button to continue..."
read -n 1 -s
echo ""
echo -n "Please input the PIN that was provided: "
read PIN
IP=$(curl -s -X POST "https://api.home.nest.com/oauth2/access_token" -d "code=$PIN" -d "client_id=$productID" -d "client_secret=$productSecret" -d "grant_type=authorization_code") > /dev/null
echo ""
echo ""
echo "Place the following in your conifg.js file"
echo ""
echo " {"
echo " module: 'MMM-Nest',"
echo " position: 'top_left',"
echo " config: {"
echo -n " token:\""
echo -n "$IP" | sed -e 's/{"access_token":"//' -e 's/","expires_in":[0-9]*}//'
echo "\""
echo " }"
echo " }"
echo ""
echo ""
echo -n "Press any button to exit..."
read -n 1 -s