-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetToken.sh
executable file
·74 lines (73 loc) · 2.71 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
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
clear
echo -e "\033[00;37m"
echo " _ _ _ "
echo "| \ | | | | "
echo "| \| | ___ ___| |_ "
echo "| . \` |/ _ \/ __| __|"
echo "| |\ | __/\__ \ |_ "
echo "|_| \_|\___||___/\__|"
echo -e "\e[0m"
echo ""
echo "This script will walk you through getting a Nest access token which you will need to use this module."
echo "The first thing you'll have to do is create a developer account with Nest (it's free)."
echo "Copy and paste this URL into the browser of your choice:"
echo -e "\033[00;34m"
echo "https://console.developers.nest.com/nl/auth/new"
echo -e "\e[0m"
echo "Create a new developer account by clicking on:"
echo ""
echo "\"Don't have an account? Sign up\""
echo ""
echo "After you have finished signing up, come back to this script to continue."
echo ""
echo -n "Press any button to continue ..."
read -n 1 -s
clear
echo -e "\033[00;37m"
echo " _ _ _ "
echo "| \ | | | | "
echo "| \| | ___ ___| |_ "
echo "| . \` |/ _ \/ __| __|"
echo "| |\ | __/\__ \ |_ "
echo "|_| \_|\___||___/\__|"
echo -e "\e[0m"
echo ""
echo "After setting up your account, it is now time to create a new OAuth client which is what you'll need to get your access token."
echo "Click on \"Create new OAuth client\" to begin."
echo ""
echo "Fill out every section that's required at the top, then move to the \"Permissions\" section at the bottom to grant access to your Thermostat and Smoke Detectors."
echo "(It doesn't matter whether you set the permissions to read only or read/write.)"
echo ""
echo "Click on \"Create\" to finish setting up your OAuth client."
echo ""
echo "Go to the \"Overview\" for your brand-new client and copy the following values:"
echo -e "\033[00;37m"
echo -n "Input Client ID: "
read productID
echo -n "Input Client Secret: "
read productSecret
echo -e "\e[0m"
echo "Copy the URL below into your browser and log in with your Nest account info. After that you'll be given a PIN."
echo -e "\033[00;34m"
echo "https://home.nest.com/login/oauth2?client_id=$productID&state=STATE"
echo -e "\e[0m \033[00;37m"
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 -e "\e[0m"
echo "You're all done! Place the following in your MagicMirror /config/config.js file:"
echo ""
echo "{"
echo " module: \"mmm-nest-cameras\","
echo " position: \"bottom_bar\","
echo " config: {"
echo -n " token: "
echo -n "\"$IP\"" | sed -e 's/{"access_token":"//' -e 's/","expires_in":[0-9]*}//'
echo " }"
echo "}"
echo ""
echo ""
echo -n "That's it! Press any button to exit this script ..."
read -n 1 -s
echo ""