robweber / xbmcbackup

Backup Addon for Kodi
MIT License
112 stars 48 forks source link

Trim Whitespace on Dropbox Auth #232

Closed robweber closed 5 months ago

robweber commented 5 months ago

Reminder: trim whitespace around Dropbox key, secret, and authorization code values in case extra spaces are introduced due to cut/paste.

rjclark99 commented 5 months ago

After going through the files it seems this enhancement can be made on lines 44, 45 and 96 in /resources/lib/authorizers.py.

self.APP_KEY = utils.getSetting('dropbox_key') self.APP_SECRET = utils.getSetting('dropbox_secret') code = xbmcgui.Dialog().input(utils.getString(30027) + ' ' + utils.getString(30103))

I'd make a pull request to make the the change myself but I'm not familiar with xbmc's modules so unsure whether wrapping in a str(utils.getSetting('dropbox_key')) .strip() would work for example. But I thought I'd try and be helpful and save you some time with the enhancement. Thank you again for helping me troubleshoot the issue I was having, I'd have given up without your help.

robweber commented 5 months ago

Sounds great - I'll watch for the PR. The utils.getSetting() call will return a string so no need to wrap it with str(). Should be pretty easy from there. Thanks!

rjclark99 commented 5 months ago

Upon attempting to recreate the initial bug, dropbox now correctly throws an error page indicating an invalid app key (strange). Furthermore attempting to add strip method at any point in the dropbox flow or prior to it causes the flow to fail and throw a type error: https://paste.kodi.tv/uvecaxojiw in line 373.

Not sure why this is throwing a type error seeing as the only modification I'm making to the code is adding .strip() to the aforementioned lines (didn't even touch the code variable yet). Tried adding it in various ways at various points in the flow all lead to the same error. The error seems to be being thrown when attempting to grab the token expiration datetime from tokens.json but that file shouldn't be created until after the flow has been authorised, nor should it be called at this point in the flow state so I'm confused as to why adding the strip method is causing an issue.

The modification now seems unnecessary as dropbox's API correctly rejects the app key if it contains any whitespace characters. Very confused as to how the initial error was occurring though as the issue was definitely down the having whitespace in my app key, as soon as I removed it it authorised first time with the authentication code and has every time since.

rjclark99 commented 5 months ago

Ok so it appears the issue was around the use of getSetting(). It simply returns a wrapper around the setting value without explicitly typing it. I'll make the PR tonight, all I've done is add a function in utils called getSettingStringStripped() which returns xbmcs _Addon.getSettingString().strip(). This correctly strips whitespace without throwing a type error and fully authorises the client.