Add auth to lbryio.js
This commit is contained in:
parent
1dbbf8fc01
commit
70d2f7c823
2 changed files with 12 additions and 4 deletions
|
@ -104,6 +104,7 @@ var App = React.createClass({
|
|||
app_id: installation_id,
|
||||
}, 'post').then(({ID}) => {
|
||||
localStorage.setItem('accessToken', ID);
|
||||
localStorage.setItem('appId', installation_id);
|
||||
this.setState({
|
||||
registrationCheckComplete: true,
|
||||
justRegistered: true,
|
||||
|
|
|
@ -80,15 +80,22 @@ lbryio.call = function(resource, action, params, method='get') {
|
|||
|
||||
console.log('about to call xhr.open');
|
||||
|
||||
// For social media auth:
|
||||
//const accessToken = localStorage.getItem('accessToken');
|
||||
//const fullParams = {...params, ... accessToken ? {access_token: accessToken} : {}};
|
||||
|
||||
// Temp app ID based auth:
|
||||
const fullParams = {app_id: localStorage.getItem('appId'), ...params};
|
||||
|
||||
if (method == 'get') {
|
||||
console.info('GET ', CONNECTION_STRING + resource + '/' + action, ' | params:', params);
|
||||
xhr.open('get', CONNECTION_STRING + resource + '/' + action + '?' + querystring.stringify(params), true);
|
||||
console.info('GET ', CONNECTION_STRING + resource + '/' + action, ' | params:', fullParams);
|
||||
xhr.open('get', CONNECTION_STRING + resource + '/' + action + '?' + querystring.stringify(fullParams), true);
|
||||
xhr.send();
|
||||
} else if (method == 'post') {
|
||||
console.info('POST ', CONNECTION_STRING + resource + '/' + action, '| params: ', params);
|
||||
console.info('POST ', CONNECTION_STRING + resource + '/' + action, '| params: ', fullParams);
|
||||
xhr.open('post', CONNECTION_STRING + resource + '/' + action, true);
|
||||
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
xhr.send(querystring.stringify(params));
|
||||
xhr.send(querystring.stringify(fullParams));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue