1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Mobile: Improved OneDrive login

This commit is contained in:
Laurent Cozic 2017-11-28 21:49:58 +00:00
parent 5ee9a35f7d
commit 565c17df37
2 changed files with 40 additions and 5 deletions

View File

@ -8,6 +8,7 @@ const { ScreenHeader } = require('lib/components/screen-header.js');
const { reg } = require('lib/registry.js');
const { _ } = require('lib/locale.js');
const { BaseScreenComponent } = require('lib/components/base-screen.js');
const parseUri = require('lib/parseUri');
class OneDriveLoginScreenComponent extends BaseScreenComponent {
@ -40,19 +41,19 @@ class OneDriveLoginScreenComponent extends BaseScreenComponent {
// doesn't exist, use this for now. The whole component is completely undocumented
// at the moment so it's likely to change.
const url = noIdeaWhatThisIs.url;
const parsedUrl = parseUri(url);
if (!this.authCode_ && url.indexOf(this.redirectUrl() + '?code=') === 0) {
Log.info('URL: ' + url);
if (!this.authCode_ && parsedUrl && parsedUrl.queryKey && parsedUrl.queryKey.code) {
Log.info('URL: ', url, parsedUrl.queryKey);
let code = url.split('?code=');
this.authCode_ = code[1];
this.authCode_ = parsedUrl.queryKey.code
try {
await reg.syncTarget().api().execTokenRequest(this.authCode_, this.redirectUrl(), true);
this.props.dispatch({ type: 'NAV_BACK' });
reg.scheduleSync(0);
} catch (error) {
alert(error.message);
alert('Could not login to OneDrive. Please try again\n\n' + error.message + '\n\n' + url);
}
this.authCode_ = null;

View File

@ -0,0 +1,34 @@
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
function parseUri (str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
};
parseUri.options = {
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};
module.exports = parseUri;