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,
|
app_id: installation_id,
|
||||||
}, 'post').then(({ID}) => {
|
}, 'post').then(({ID}) => {
|
||||||
localStorage.setItem('accessToken', ID);
|
localStorage.setItem('accessToken', ID);
|
||||||
|
localStorage.setItem('appId', installation_id);
|
||||||
this.setState({
|
this.setState({
|
||||||
registrationCheckComplete: true,
|
registrationCheckComplete: true,
|
||||||
justRegistered: true,
|
justRegistered: true,
|
||||||
|
|
|
@ -80,15 +80,22 @@ lbryio.call = function(resource, action, params, method='get') {
|
||||||
|
|
||||||
console.log('about to call xhr.open');
|
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') {
|
if (method == 'get') {
|
||||||
console.info('GET ', CONNECTION_STRING + resource + '/' + action, ' | params:', params);
|
console.info('GET ', CONNECTION_STRING + resource + '/' + action, ' | params:', fullParams);
|
||||||
xhr.open('get', CONNECTION_STRING + resource + '/' + action + '?' + querystring.stringify(params), true);
|
xhr.open('get', CONNECTION_STRING + resource + '/' + action + '?' + querystring.stringify(fullParams), true);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
} else if (method == 'post') {
|
} 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.open('post', CONNECTION_STRING + resource + '/' + action, true);
|
||||||
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
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