Genius access_token in URL instead of headers

This commit is contained in:
James Barnsley
2018-08-16 16:47:42 +12:00
parent 240ebf9391
commit d48cdd9f45
9 changed files with 13912 additions and 10614 deletions

View File

@ -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
));
*/
}
);
}

View File

@ -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
}
}