Preparing for Mopidy-Spotify 3.1.0 client credentials; Additional debug examples

This commit is contained in:
James Barnsley
2017-06-13 08:58:10 +12:00
parent 58c08608e4
commit 164d8ecbeb
3 changed files with 43 additions and 9 deletions

View File

@ -446,11 +446,24 @@ class IrisCore(object):
def refresh_spotify_token(self, data):
url = 'https://accounts.spotify.com/api/token'
authorization = 'YTg3ZmI0ZGJlZDMwNDc1YjhjZWMzODUyM2RmZjUzZTI6ZDdjODlkMDc1M2VmNDA2OGJiYTE2NzhjNmNmMjZlZDY='
## TODO: See if we can use the credentials used by Mopidy-Spotify 3.1.0
# Currently this returns 'invalid_client' error
# Use client_id and client_secret from config
# This was introduced in Mopidy-Spotify 3.1.0
#if 'spotify' in self.config and 'client_id' in self.config['spotify']:
# authorization = str(self.config['spotify']['client_id']+':'+self.config['spotify']['client_secret'])
# authorization = authorization.encode('base64').replace('\n', '')
# Mopidy-Spotify is old version, so just use basic authorization code
#else:
# authorization = 'YTg3ZmI0ZGJlZDMwNDc1YjhjZWMzODUyM2RmZjUzZTI6ZDdjODlkMDc1M2VmNDA2OGJiYTE2NzhjNmNmMjZlZDY='
authorization = 'YTg3ZmI0ZGJlZDMwNDc1YjhjZWMzODUyM2RmZjUzZTI6ZDdjODlkMDc1M2VmNDA2OGJiYTE2NzhjNmNmMjZlZDY='
url = 'https://accounts.spotify.com/api/token'
headers = {'Authorization' : 'Basic ' + authorization}
data = {'grant_type': 'client_credentials'}
data_encoded = urllib.urlencode( data )
req = urllib2.Request(url, data_encoded, headers)
@ -465,5 +478,12 @@ class IrisCore(object):
})
return self.get_spotify_token({})
except urllib2.HTTPError as e:
return e
error = json.loads(e.read())
return {
'type': 'error',
'message': 'Could not refresh token: '+error['error'],
'source': 'refresh_spotify_token'
}

View File

@ -25,7 +25,7 @@ class Debug extends React.Component{
this.state = {
mopidy_call: 'playlists.asList',
mopidy_data: '{}',
pusher_data: '{"method":"broadcast","data":{"type":"browser_notification","title":"Testing","body":"This is my message"}}'
pusher_data: '{"method":"get_config"}'
}
}
@ -151,6 +151,22 @@ class Debug extends React.Component{
<h4 className="underline">Pusher</h4>
<form onSubmit={(e) => this.callPusher(e)}>
<div className="field">
<div className="name">Examples</div>
<div className="input">
<select onChange={ e => this.setState({ pusher_data: e.target.value })}>
<option value='{"method":"get_config"}'>Get config</option>
<option value='{"method":"get_version"}'>Get version</option>
<option value='{"method":"get_connections"}'>Get connections</option>
<option value='{"method":"get_radio"}'>Get radio</option>
<option value='{"method":"get_queue_metadata"}'>Get queue metadata</option>
<option value='{"method":"broadcast","data":{"type":"browser_notification","title":"Testing","body":"This is my message"}}'>Broadcast to all clients</option>
<option value='{"method":"deliver_message","data":{"to":"CONNECTION_ID_HERE","message":{"type":"browser_notification","title":"Testing","body":"This is my message"}}}'>Broadcast to one client</option>
<option value='{"method":"refresh_spotify_token"}'>Refresh Spotify token</option>
<option value='{"method":"perform_upgrade"}'>Perform upgrade (beta)</option>
</select>
</div>
</div>
<div className="field">
<div className="name">Data</div>
<div className="input">

View File

@ -13,7 +13,8 @@ input[type="text"],
input[type="email"],
input[type="number"],
input[type="email"],
input[type="date"] {
input[type="date"],
select {
padding: 10px 14px;
background: #FFFFFF;
color: #000000;
@ -304,7 +305,6 @@ input[type="submit"] {
&.radio,
&.checkbox {
input{
display: none;
}
@ -324,7 +324,6 @@ input[type="submit"] {
}
&.radio {
input + .label:before {
content: ' ';
display: inline-block;
@ -355,7 +354,6 @@ input[type="submit"] {
}
&.checkbox {
input + .label:before {
font-family: FontAwesome;
font-size: 8px;