1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-18 23:07:45 +02:00

All: Resolves #1266: Add support for OneDrive for Business (#3433)

This commit is contained in:
jonath92
2020-08-08 01:35:30 +02:00
committed by GitHub
parent aa147bbcdc
commit 799a9e810d
4 changed files with 56 additions and 28 deletions

View File

@ -13,6 +13,7 @@ class OneDriveApi {
this.clientId_ = clientId;
this.clientSecret_ = clientSecret;
this.auth_ = null;
this.accountProperties_ = null;
this.isPublic_ = isPublic;
this.listeners_ = {
authRefreshed: [],
@ -73,14 +74,15 @@ class OneDriveApi {
}
async appDirectory() {
const r = await this.execJson('GET', '/drive/special/approot');
const driveId = this.accountProperties_.driveId;
const r = await this.execJson('GET', `/me/drives/${driveId}/special/approot`);
return `${r.parentReference.path}/${r.name}`;
}
authCodeUrl(redirectUri) {
const query = {
client_id: this.clientId_,
scope: 'files.readwrite offline_access',
scope: 'files.readwrite offline_access sites.readwrite.all',
response_type: 'code',
redirect_uri: redirectUri,
};
@ -320,6 +322,29 @@ class OneDriveApi {
throw new Error(`Could not execute request after multiple attempts: ${method} ${url}`);
}
setAccountProperties(accountProperties) {
this.accountProperties_ = accountProperties;
}
async execAccountPropertiesRequest() {
const response = await shim.fetch('https://graph.microsoft.com/v1.0/me/drive', {
method: 'GET',
headers: {
'Authorization': this.token(),
},
});
if (!response.ok) {
const text = await response.text();
throw new Error(`Could not retrieve account details (drive ID, Account type): ${response.status}: ${response.statusText}: ${text}`);
} else {
const data = await response.json();
const accountProperties = { accountType: data.driveType, driveId: data.id };
return accountProperties;
}
}
async execJson(method, path, query, data) {
const response = await this.exec(method, path, query, data);
const errorResponseText = await response.text();