This commit is contained in:
UKDTOM 2021-01-03 23:52:02 +01:00
parent b451253451
commit 724975b999
5 changed files with 71 additions and 2 deletions

View file

@ -42,6 +42,8 @@
// Will show servers not owned by you
"showNotOwned": true,
// For ET, show levels starting with the word 'dev'
"showDevLevels": true
"showDevLevels": true,
// Use your token if you have enabled 2FA instead of the password
"X-Plex-Token": "Your Token"
}
}

View file

@ -28,7 +28,8 @@ function createWindow () {
// Create the browser window.
win = new BrowserWindow({ width: 1024, height: 768, icon: __dirname + "../src/assets/WebTools-512.png", webPreferences: {
nodeIntegration: true,
webSecurity: false
webSecurity: false,
enableRemoteModule: true
} })
if (process.env.WEBPACK_DEV_SERVER_URL) {

View file

@ -76,6 +76,14 @@ export default {
},
}
},
created() {
if (this.$store.getters.getAuthToken != ''){
log.verbose(`We have an Auth Token from cli or dev option`)
store.dispatch('loginToPlexWithToken', {
token: this.$store.getters.getAuthToken
})
}
},
methods: {
onEnter: function() {
this.plexLogin();

View file

@ -37,6 +37,30 @@ log.info(`Running on ${wtutils.RunningOS}`)
log.info(`Log level set to ${log.transports.file.level}`)
// Logging ended
// Log Commandline Params
// This will handle any commandline params that we use
const params = require('electron').remote.process.argv;
params.forEach(param => {
// log.verbose(`Param is: ${param}`);
if (param.toLowerCase().startsWith("x-plex-token"))
{
// SECURITY ISSUE...Do not enable next line, except when debugging
// log.verbose(`Found Token as: ${param.split('=')[1]}`)
store.commit("UPDATE_AUTHTOKEN", param.split('=')[1]);
}
});
// Handles dev stuff from Json
const token = wtconfig.get('Developer.X-Plex-Token', '');
if ( token != ''){
log.verbose(`Logging in with Dev Token`)
store.commit("UPDATE_AUTHTOKEN", token);
}
// Prepopulate config file with defaults
if (wtconfig.get("general.version", "") != wtutils.AppVersion){
// Config file out of date, so prepopulate with default values if missing

View file

@ -136,6 +136,40 @@ const actions = {
log.error('loginToPlex: ' + error.message)
}})
},
loginToPlexWithToken({ commit }, payload){
log.info("loginToPlex called, using a Token")
const url = 'https://plex.tv/users/sign_in.json?X-Plex-Token=' + payload.token;
axios({
method: 'POST',
url: url,
headers: wtutils.PMSHeader
})
.then(function (response) {
log.debug('loginToPlex: Response from fetchPlexServers recieved')
commit('UPDATE_AUTHTOKEN', response.data.user.authToken)
commit('UPDATE_AUTHENTICATED', true)
commit('UPDATE_AVATAR', response.data.user.thumb)
commit('UPDATE_PLEXNAME', response.data.user.username)
router.replace({name: "home"});
})
.catch(function (error) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
log.error('loginToPlex: ' + error.response.status);
log.error('loginToPlex: ' + JSON.stringify(error.response.data));
alert(error.response.data.error)
//this.danger(error.response.status, error.response.data.error);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
log.error('loginToPlex: ' + error.request)
} else {
// Something happened in setting up the request that triggered an Error
log.error('loginToPlex: ' + error.message)
}})
},
updatingServerAddress({ commit}, status){
commit('UPDATE_PLEX_SELECTED_SERVER_STATUS', status)
}