-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth.sh
executable file
·51 lines (39 loc) · 1.04 KB
/
oauth.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
#!/usr/bin/env bash
source common.sh
clientID=$(pass strava.com/clientID)
clientSecret=$(pass strava.com/clientSecret)
scopes=(
read
read_all
profile:read_all
profile:write
activity:read
activity:read_all
activity:write
)
scopes_string=$(join_by , "${scopes[@]}")
params=(
"client_id=${clientID}"
response_type=code
redirect_uri=http://example.com
approval_prompt=force
"scope=${scopes_string}"
)
url=https://www.strava.com/oauth/authorize?$(join_by & "${params[@]}")
echo "$url"
echo
echo "Please follow above link and paste the resulting url after authorization:"
read -r response
: $(grep -o 'code=.*&' <<< "$response")
: ${_%&}
code=${_#code=}
auth_response=$(curl -X POST https://www.strava.com/api/v3/oauth/token \
-d "client_id=${clientID}" \
-d "client_secret=${clientSecret}" \
-d "code=${code}" \
-d grant_type=authorization_code)
refresh_token=$(jq <<< "${auth_response}" -r .refresh_token)
access_token=$(jq <<< "${auth_response}" -r .access_token)
echo "refresh_token: ${refresh_token}"
echo "access_token: ${access_token}"
exit