mIRC Homepage
Posted By: Sjoepele Spotify oAuth refresh token - Sockets. - 09/02/15 05:57 PM
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 ^_^
Posted By: Loki12583 Re: Spotify oAuth refresh token - Sockets. - 09/02/15 06:56 PM
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)
Posted By: Sjoepele Re: Spotify oAuth refresh token - Sockets. - 09/02/15 07:21 PM
Loki you are my hero blush
Posted By: Sjoepele Re: Spotify oAuth refresh token - Sockets. - 10/02/15 11:56 PM
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
what's the value of %delsong
Posted By: Sjoepele Re: Spotify oAuth refresh token - Sockets. - 11/02/15 02:07 AM
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
© mIRC Discussion Forums