mIRC Home    About    Download    Register    News    Help

Print Thread
Spotify oAuth refresh token - Sockets. #251095 09/02/15 05:57 PM
Joined: Mar 2014
Posts: 42
S
Sjoepele Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Hi glorious people of the forums. Ive been trying to mess around with a spotify-songrequest kind of thing and part of that is authorization. to obtain a refresh token (which are used to prevent access tokens from expiring) i need to POST to spotify's account server as explained on the 4th step of https://developer.spotify.com/web-api/authorization-guide/

basically they want you to add the body parameters 'grant_type' 'code' and 'redirect_url' and i have no idea how to do that.

so far i have this and its returning 500's
Code:
on *:sockopen:oauth: { 
  msg #sjoepele  [DEBUG] oauth initialized
  sockwrite -n $sockname POST /api/token HTTP/1.1
  sockwrite -n $sockname Host: accounts.spotify.com
  sockwrite -n $sockname Authorization: Basic <base64 encoded client secret:clientid censored>
  sockwrite -n $sockname Accept-Encoding: compress
  sockwrite -n $sockname Accept: application/json
  sockwrite -n $sockname Connection: close
  sockwrite -n $sockname 
  sockwrite -n $sockname grant_type=authorization_code
  sockwrite -n $sockname code= <authorization code censored>
  sockwrite -n $sockname redirect_uri=http://localhost/
}


tl;dr have to add body parameters and don't know how

If someone could help me out that would be greatly appreciated ^_^

Re: Spotify oAuth refresh token - Sockets. [Re: Sjoepele] #251101 09/02/15 06:56 PM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
Code:
var %data = $+(grant_type=,%grant_type,&code=,%code,&redirect_url=,%redirect_url)

sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
sockwrite -n $sockname Content-Length: $len(%data)
sockwrite -n $sockname $+($crlf,%data)

Re: Spotify oAuth refresh token - Sockets. [Re: Loki12583] #251102 09/02/15 07:21 PM
Joined: Mar 2014
Posts: 42
S
Sjoepele Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Loki you are my hero blush

Re: Spotify oAuth refresh token - Sockets. [Re: Loki12583] #251145 10/02/15 11:56 PM
Joined: Mar 2014
Posts: 42
S
Sjoepele Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Hmm now im trying to send JSON in the same way but
Code:
var %tracks = $+({ "tracks": [{ "uri": " $+ %delsong $+ " }] })

this returns
Code:
"status": 400,
"message": "JSON body does not adhere to the defined endpoint parameters: \"tracks\": [{ \"uri\": \"spotify:track:5eWgDlp3k6Tb5RD8690s6I\" }]"

mind that it doesnt show the opening bracket in the error description, which makes me think it dropped that for some reason and thinks its part of the code? So i tried using $chr(123) but this:

Code:
var %tracks = $+( $chr(123) "tracks": [{ "uri": " $+ %delsong $+ " }] })

returns 'malformed JSON Body'

I wonder whats the best way to go about this

Re: Spotify oAuth refresh token - Sockets. [Re: Sjoepele] #251150 11/02/15 01:26 AM
Joined: Apr 2010
Posts: 921
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 921
what's the value of %delsong


I am SReject
My Stuff
Re: Spotify oAuth refresh token - Sockets. [Re: FroggieDaFrog] #251154 11/02/15 02:07 AM
Joined: Mar 2014
Posts: 42
S
Sjoepele Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
a spotify ID, but i found the problem.
when i sent it to a testserver i noticed that it had dropped ALL the brackets :P So i changed stuff around a bit.

Code:
var %tracks = $+($chr(123) "tracks": [{ "uri": " $+ %delsong $+ " }] $chr(125))


now it looks like that, don't know why it works, but it does. Thanks though laugh