Last active
August 10, 2023 15:23
-
-
Save dumbmoron/2a4864dc68f510bffedfebd201dea5dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| RAND=$(uuidgen) | |
| CHALLENGE=$(echo -en "$RAND" | sha256sum | cut -d' ' -f1) | |
| INIT_DATA=$(curl -X POST 'https://api.nordvpn.com/v1/users/oauth/login'\ | |
| -H 'Content-Type: application/json'\ | |
| -d '{"preferred_flow": "login", "challenge": "'$CHALLENGE'"}' \ | |
| ) | |
| REDIRECT_URI=$(echo "$INIT_DATA" | jq -r .redirect_uri) | |
| ATTEMPT=$(echo "$INIT_DATA" | jq -r .attempt) | |
| echo "Open the following URL in your browser: $REDIRECT_URI" | |
| echo -en "After logging in, copy the "exchange_token" from the URL and paste it here: " | |
| read EXCH_TOKEN | |
| OAUTH_RESULT=$(curl "https://api.nordvpn.com/v1/users/oauth/token?attempt=$ATTEMPT&exchange_token=$EXCH_TOKEN&verifier=$RAND" \ | |
| -H 'accept: application/json' \ | |
| -H 'content-type: application/json' \ | |
| --compressed) | |
| OAUTH_TOKEN=$(echo "$OAUTH_RESULT" | jq -r .token) | |
| B64_TOKEN=$(echo "token:$OAUTH_TOKEN" | base64 | tr -d \\n) | |
| CREDENTIALS=$(curl 'https://api.nordvpn.com/v1/users/services/credentials' \ | |
| -H 'accept: application/json' \ | |
| -H 'authorization: Basic '"$B64_TOKEN" | |
| ) | |
| echo "$CREDENTIALS" | jq . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment