You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
All: Open the connection screen when a SAML session has expired
This commit is contained in:
@@ -78,7 +78,7 @@ export default class SyncTargetJoplinServer extends BaseSyncTarget {
|
|||||||
return super.fileApi();
|
return super.fileApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async checkConfig(options: FileApiOptions, syncTargetId: number = null) {
|
public static async checkConfig(options: FileApiOptions, syncTargetId: number = null, fileApi: FileApi|null = null) {
|
||||||
const output = {
|
const output = {
|
||||||
ok: false,
|
ok: false,
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
@@ -86,10 +86,9 @@ export default class SyncTargetJoplinServer extends BaseSyncTarget {
|
|||||||
|
|
||||||
syncTargetId = syncTargetId === null ? this.id() : syncTargetId;
|
syncTargetId = syncTargetId === null ? this.id() : syncTargetId;
|
||||||
|
|
||||||
let fileApi = null;
|
if (!fileApi) {
|
||||||
try {
|
try {
|
||||||
fileApi = await newFileApi(syncTargetId, options);
|
fileApi = await newFileApi(syncTargetId, options);
|
||||||
fileApi.requestRepeatCount_ = 0;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If there's an error it's probably an application error, but we
|
// If there's an error it's probably an application error, but we
|
||||||
// can't proceed anyway, so exit.
|
// can't proceed anyway, so exit.
|
||||||
@@ -97,7 +96,12 @@ export default class SyncTargetJoplinServer extends BaseSyncTarget {
|
|||||||
if (error.code) output.errorMessage += ` (Code ${error.code})`;
|
if (error.code) output.errorMessage += ` (Code ${error.code})`;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const previousRequestRepeatCount = fileApi.requestRepeatCount_;
|
||||||
|
fileApi.requestRepeatCount_ = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
// First we try to fetch info.json. It may not be present if it's a new
|
// First we try to fetch info.json. It may not be present if it's a new
|
||||||
// sync target but otherwise, if it is, and it's valid, we know the
|
// sync target but otherwise, if it is, and it's valid, we know the
|
||||||
// credentials are valid. We do this test first because it will work
|
// credentials are valid. We do this test first because it will work
|
||||||
@@ -131,6 +135,9 @@ export default class SyncTargetJoplinServer extends BaseSyncTarget {
|
|||||||
output.errorMessage = error.message;
|
output.errorMessage = error.message;
|
||||||
if (error.code) output.errorMessage += ` (Code ${error.code})`;
|
if (error.code) output.errorMessage += ` (Code ${error.code})`;
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
fileApi.requestRepeatCount_ = previousRequestRepeatCount;
|
||||||
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ export const authenticateWithCode = async (code: string) => {
|
|||||||
//
|
//
|
||||||
// Based on the regular Joplin Server sync target.
|
// Based on the regular Joplin Server sync target.
|
||||||
export default class SyncTargetJoplinServerSAML extends SyncTargetJoplinServer {
|
export default class SyncTargetJoplinServerSAML extends SyncTargetJoplinServer {
|
||||||
|
|
||||||
|
private lastFileApiOptions_: FileApiOptions|null = null;
|
||||||
|
|
||||||
public static override id() {
|
public static override id() {
|
||||||
return 11;
|
return 11;
|
||||||
}
|
}
|
||||||
@@ -65,7 +68,16 @@ export default class SyncTargetJoplinServerSAML extends SyncTargetJoplinServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override async isAuthenticated() {
|
public override async isAuthenticated() {
|
||||||
return Setting.value('sync.11.id') !== '';
|
if (!Setting.value('sync.11.id')) return false;
|
||||||
|
|
||||||
|
// We check that the file API has been initialized at least once, otherwise the below check
|
||||||
|
// will always fail and it will be impossible to login.
|
||||||
|
if (this.lastFileApiOptions_) {
|
||||||
|
const check = await SyncTargetJoplinServer.checkConfig(null, null, await this.fileApi());
|
||||||
|
return check.ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static override requiresPassword() {
|
public static override requiresPassword() {
|
||||||
@@ -111,11 +123,12 @@ export default class SyncTargetJoplinServerSAML extends SyncTargetJoplinServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override async initFileApi() {
|
protected override async initFileApi() {
|
||||||
return initFileApi(SyncTargetJoplinServerSAML.id(), this.logger(), {
|
this.lastFileApiOptions_ = {
|
||||||
path: () => Setting.value('sync.11.path'),
|
path: () => Setting.value('sync.11.path'),
|
||||||
userContentPath: () => Setting.value('sync.11.userContentPath'),
|
userContentPath: () => Setting.value('sync.11.userContentPath'),
|
||||||
username: () => '',
|
username: () => '',
|
||||||
password: () => '',
|
password: () => '',
|
||||||
});
|
};
|
||||||
|
return initFileApi(SyncTargetJoplinServerSAML.id(), this.logger(), this.lastFileApiOptions_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { utils, CommandRuntime, CommandDeclaration, CommandContext } from '../se
|
|||||||
import { _ } from '../locale';
|
import { _ } from '../locale';
|
||||||
import { reg } from '../registry';
|
import { reg } from '../registry';
|
||||||
import Setting from '../models/Setting';
|
import Setting from '../models/Setting';
|
||||||
|
import NavService from '../services/NavService';
|
||||||
|
|
||||||
export const declaration: CommandDeclaration = {
|
export const declaration: CommandDeclaration = {
|
||||||
name: 'synchronize',
|
name: 'synchronize',
|
||||||
@@ -35,7 +36,18 @@ export const runtime = (): CommandRuntime => {
|
|||||||
return 'auth';
|
return 'auth';
|
||||||
}
|
}
|
||||||
|
|
||||||
reg.logger().error('Not authenticated with sync target - please check your credentials.');
|
const error = new Error('Not authenticated with sync target - please check your credentials.');
|
||||||
|
|
||||||
|
utils.store.dispatch({
|
||||||
|
type: 'SYNC_REPORT_UPDATE',
|
||||||
|
report: { errors: [error] },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Setting.value('sync.target') === 11) {
|
||||||
|
await NavService.go('JoplinServerSamlLogin');
|
||||||
|
}
|
||||||
|
|
||||||
|
reg.logger().error(error);
|
||||||
return 'error';
|
return 'error';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user