Skip to content

Instantly share code, notes, and snippets.

@asessa
Created February 22, 2017 11:52
Show Gist options
  • Save asessa/ee096da2d46a0eeb7d317ef72c3cf610 to your computer and use it in GitHub Desktop.
Save asessa/ee096da2d46a0eeb7d317ef72c3cf610 to your computer and use it in GitHub Desktop.
Retreive SoundCloud access_token via Bash
#!/bin/bash
echo -n "Client ID: "
read CLIENT_ID
echo -n "Client Secret: "
read -s CLIENT_SECRET
echo
echo -n "Username: "
read username
echo -n "Password: "
read -s password
echo
echo -n | openssl s_client -connect soundcloud.com:443 -showcerts 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >/tmp/soundcloud.pem
TOKEN="$(curl -s -X POST --cacert /tmp/soundcloud.pem \
-F 'client_id='$CLIENT_ID \
-F 'client_secret='$CLIENT_SECRET \
-F 'grant_type=password' \
-F 'username='$username \
-F 'password='$password \
-F 'scope=non-expiring' \
'https://api.soundcloud.com/oauth2/token' | cut -d\" -f4)"
rm /tmp/soundcloud.pem
echo "Access Token: ${TOKEN}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment