Genius access_token in URL instead of headers
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -98,7 +98,7 @@
|
||||
|
||||
// Release details
|
||||
// These are automatically injected to built HTML
|
||||
var build = "1534318748";
|
||||
var build = "1534364832";
|
||||
var version = "3.23.2";
|
||||
|
||||
// Construct the script tag
|
||||
|
||||
@ -21,6 +21,7 @@ class GeniusAuthenticationFrame extends React.Component{
|
||||
|
||||
componentDidMount(){
|
||||
let self = this;
|
||||
this.props.geniusActions.getMe();
|
||||
|
||||
// Listen for incoming messages from the authorization popup
|
||||
window.addEventListener('message', function(event){
|
||||
@ -54,7 +55,7 @@ class GeniusAuthenticationFrame extends React.Component{
|
||||
// No errors? We're in!
|
||||
} else {
|
||||
this.props.geniusActions.authorizationGranted(data)
|
||||
this.props.geniusActions.getMe()
|
||||
this.props.geniusActions.getMe();
|
||||
}
|
||||
|
||||
// Turn off our authorizing switch
|
||||
|
||||
@ -202,7 +202,7 @@ class Services extends React.Component{
|
||||
}
|
||||
|
||||
renderGenius(){
|
||||
var user_object = (this.props.genius.user ? this.props.core.users["genius:user:"+this.props.genius.user.id] : null);
|
||||
var user_object = (this.props.genius.me ? this.props.core.users["genius:user:"+this.props.genius.me.id] : null);
|
||||
if (user_object){
|
||||
var user = (
|
||||
<span className="user">
|
||||
@ -225,7 +225,7 @@ class Services extends React.Component{
|
||||
|
||||
return (
|
||||
<div>
|
||||
{this.props.genius.user ? <div className="field current-user">
|
||||
{this.props.genius.me ? <div className="field current-user">
|
||||
<div className="name">Current user</div>
|
||||
<div className="input">
|
||||
<div className="text">
|
||||
|
||||
@ -20,19 +20,22 @@ export function set(data){
|
||||
* @param data mixed = request payload
|
||||
* @return Promise
|
||||
**/
|
||||
const sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) => {
|
||||
|
||||
var sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
// create our ajax request config
|
||||
var config = {
|
||||
method: method,
|
||||
url: 'https://api.genius.com/'+endpoint,
|
||||
cached: true,
|
||||
url: 'https://api.genius.com/'+endpoint+'?access_token='+getState().genius.access_token,
|
||||
dataType: 'jsonp',
|
||||
timeout: 30000,
|
||||
crossDomain: true,
|
||||
async: true,
|
||||
headers: {
|
||||
Authorization: 'Bearer '+ response,
|
||||
Accept: 'application/json'
|
||||
// We can't use headers as this seems to trigger CORS issues. Instead we have to post as URL params
|
||||
// Authorization: 'Bearer '+ getState().genius.access_token,
|
||||
Accept: 'application/json',
|
||||
"Access-Control-Allow-Origin": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,14 +49,14 @@ const sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false)
|
||||
}
|
||||
|
||||
// add reference to loader queue
|
||||
var loader_key = helpers.generateGuid()
|
||||
dispatch(uiActions.startLoading(loader_key, 'genius_'+endpoint))
|
||||
var loader_key = helpers.generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, 'genius_'+endpoint));
|
||||
|
||||
$.ajax(config).then(
|
||||
response => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
|
||||
if (response.meta.status >= 200 && response.meta.status < 300 && response.response){
|
||||
if (response.meta && response.meta.status >= 200 && response.meta.status < 300 && response.response){
|
||||
resolve(response.response);
|
||||
} else {
|
||||
reject({
|
||||
@ -66,7 +69,6 @@ const sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false)
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
|
||||
reject({
|
||||
config: config,
|
||||
xhr: xhr,
|
||||
@ -74,9 +76,8 @@ const sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false)
|
||||
error: error
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -108,14 +109,17 @@ export function getMe(){
|
||||
response => {
|
||||
dispatch({
|
||||
type: 'GENIUS_ME_LOADED',
|
||||
user: response.user
|
||||
me: response.user
|
||||
});
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
/*
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not load your Genius profile',
|
||||
error
|
||||
));
|
||||
*/
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -6,27 +6,28 @@ export default function reducer(genius = {}, action){
|
||||
return Object.assign({}, genius, action.data)
|
||||
|
||||
case 'GENIUS_ME_LOADED':
|
||||
return Object.assign({}, genius, {user: action.user})
|
||||
return Object.assign({}, genius, {
|
||||
me: action.me
|
||||
})
|
||||
|
||||
case 'GENIUS_AUTHORIZATION_GRANTED':
|
||||
return Object.assign({}, genius, {
|
||||
authorizing: false,
|
||||
authorizing: false,
|
||||
authorization: action.data,
|
||||
authorization_code: action.data.authorization_code,
|
||||
access_token: action.data.access_token
|
||||
})
|
||||
|
||||
case 'GENIUS_AUTHORIZATION_REVOKED':
|
||||
return Object.assign({}, genius, {
|
||||
return Object.assign({}, genius, {
|
||||
authorizing: false,
|
||||
authorization_code: false,
|
||||
access_token: false,
|
||||
me: false
|
||||
authorization: null,
|
||||
authorization_code: null,
|
||||
access_token: null,
|
||||
me: null
|
||||
});
|
||||
|
||||
default:
|
||||
return genius
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ var helpers = require('../../helpers');
|
||||
* @param params = string, the url params to send
|
||||
* @params signed = boolean, whether we've got a signed request with baked-in api_key
|
||||
**/
|
||||
const sendRequest = (dispatch, getState, params, signed = false) => {
|
||||
var sendRequest = (dispatch, getState, params, signed = false) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
var loader_key = helpers.generateGuid();
|
||||
@ -27,7 +27,7 @@ const sendRequest = (dispatch, getState, params, signed = false) => {
|
||||
url: 'https://ws.audioscrobbler.com/2.0/?format=json&'+params
|
||||
}
|
||||
|
||||
// Signed requests don't need our api_key as the proxy has it's own
|
||||
// Signed requests don't need our api_key as the proxy has it's own
|
||||
if (!signed){
|
||||
config.url += '&api_key=4320a3ef51c9b3d69de552ac083c55e3';
|
||||
} else {
|
||||
@ -460,4 +460,4 @@ export function scrobble(track){
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'PUSHER_CONNECTED':
|
||||
helpers.setStorage(
|
||||
'pusher',
|
||||
'pusher',
|
||||
{
|
||||
connection_id: action.connection_id
|
||||
}
|
||||
@ -42,7 +42,7 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'PUSHER_SET_PORT':
|
||||
helpers.setStorage(
|
||||
'pusher',
|
||||
'pusher',
|
||||
{
|
||||
port: action.port
|
||||
}
|
||||
@ -51,7 +51,7 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'PUSHER_USERNAME_CHANGED':
|
||||
helpers.setStorage(
|
||||
'pusher',
|
||||
'pusher',
|
||||
{
|
||||
username: action.username
|
||||
}
|
||||
@ -60,7 +60,7 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'MOPIDY_URISCHEMES_FILTERED':
|
||||
helpers.setStorage(
|
||||
'mopidy',
|
||||
'mopidy',
|
||||
{
|
||||
uri_schemes: action.data
|
||||
}
|
||||
@ -75,11 +75,11 @@ const localstorageMiddleware = (function(){
|
||||
var authorization = action.data;
|
||||
}
|
||||
helpers.setStorage(
|
||||
'spotify',
|
||||
'spotify',
|
||||
{
|
||||
authorization: authorization,
|
||||
access_token: authorization.access_token,
|
||||
refresh_token: authorization.refresh_token,
|
||||
access_token: authorization.access_token,
|
||||
refresh_token: authorization.refresh_token,
|
||||
token_expiry: authorization.token_expiry
|
||||
}
|
||||
);
|
||||
@ -87,11 +87,11 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_REVOKED':
|
||||
helpers.setStorage(
|
||||
'spotify',
|
||||
'spotify',
|
||||
{
|
||||
authorization: false,
|
||||
access_token: false,
|
||||
refresh_token: false,
|
||||
authorization: false,
|
||||
access_token: false,
|
||||
refresh_token: false,
|
||||
token_expiry: false
|
||||
}
|
||||
);
|
||||
@ -99,7 +99,7 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'SPOTIFY_TOKEN_REFRESHED':
|
||||
helpers.setStorage(
|
||||
'spotify',
|
||||
'spotify',
|
||||
{
|
||||
access_token: action.data.access_token,
|
||||
token_expiry: action.data.token_expiry,
|
||||
@ -110,17 +110,36 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'SPOTIFY_ME_LOADED':
|
||||
helpers.setStorage(
|
||||
'spotify',
|
||||
'spotify',
|
||||
{
|
||||
me: action.data
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case 'LASTFM_AUTHORIZATION_GRANTED':
|
||||
helpers.setStorage(
|
||||
'lastfm',
|
||||
{
|
||||
session: action.data.session
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case 'LASTFM_AUTHORIZATION_REVOKED':
|
||||
helpers.setStorage(
|
||||
'lastfm',
|
||||
{
|
||||
session: null
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case 'GENIUS_AUTHORIZATION_GRANTED':
|
||||
helpers.setStorage(
|
||||
'genius',
|
||||
'genius',
|
||||
{
|
||||
authorization: action.data,
|
||||
authorization_code: action.data.authorization_code,
|
||||
access_token: action.data.access_token
|
||||
}
|
||||
@ -129,10 +148,11 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'GENIUS_AUTHORIZATION_REVOKED':
|
||||
helpers.setStorage(
|
||||
'genius',
|
||||
'genius',
|
||||
{
|
||||
me: null,
|
||||
authorization_code: null,
|
||||
authorization: null,
|
||||
authorization_code: null,
|
||||
access_token: null
|
||||
}
|
||||
);
|
||||
@ -140,28 +160,28 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'CORE_SET':
|
||||
helpers.setStorage(
|
||||
'core',
|
||||
'core',
|
||||
action.data
|
||||
);
|
||||
break
|
||||
|
||||
case 'UI_SET':
|
||||
helpers.setStorage(
|
||||
'ui',
|
||||
'ui',
|
||||
action.data
|
||||
);
|
||||
break
|
||||
|
||||
case 'MOPIDY_SET':
|
||||
helpers.setStorage(
|
||||
'mopidy',
|
||||
'mopidy',
|
||||
action.data
|
||||
);
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_SET':
|
||||
helpers.setStorage(
|
||||
'spotify',
|
||||
'spotify',
|
||||
action.data
|
||||
);
|
||||
break;
|
||||
@ -177,31 +197,13 @@ const localstorageMiddleware = (function(){
|
||||
suppressed_broadcasts.push(action.key);
|
||||
|
||||
helpers.setStorage(
|
||||
'ui',
|
||||
'ui',
|
||||
{
|
||||
suppressed_broadcasts: suppressed_broadcasts
|
||||
}
|
||||
);
|
||||
break
|
||||
|
||||
case 'LASTFM_AUTHORIZATION_GRANTED':
|
||||
helpers.setStorage(
|
||||
'lastfm',
|
||||
{
|
||||
session: action.data.session
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case 'LASTFM_AUTHORIZATION_REVOKED':
|
||||
helpers.setStorage(
|
||||
'lastfm',
|
||||
{
|
||||
session: null
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
/**
|
||||
* Experimental saving of stores to localStorage
|
||||
* This uses way too much storage space (ie 10MB+) so won't work. We need
|
||||
@ -233,4 +235,4 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
})();
|
||||
|
||||
export default localstorageMiddleware
|
||||
export default localstorageMiddleware
|
||||
|
||||
Reference in New Issue
Block a user