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:
parent
5ee9a35f7d
commit
565c17df37
@ -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;
|
||||
|
34
ReactNativeClient/lib/parseUri.js
Normal file
34
ReactNativeClient/lib/parseUri.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user