diff --git a/main.js b/main.js index d649ae7..8fbb4b4 100644 --- a/main.js +++ b/main.js @@ -16,7 +16,13 @@ async function register ({ private: true }) - + registerSetting({ + name: 'mail', + label: 'Mail', + type: 'input', + descriptionHTML: 'mail domain for each matrix user', + private: true + }) registerIdAndPassAuth({ authName: 'matrix', @@ -24,7 +30,6 @@ async function register ({ login: options => login(peertubeHelpers, settingsManager, options) }) - setWeight(500) } @@ -42,6 +47,7 @@ async function login (peertubeHelpers, settingsManager, options) { const settings = await settingsManager.getSettings([ 'url', + 'mail' ]) // options.id, options.password @@ -60,20 +66,19 @@ async function login (peertubeHelpers, settingsManager, options) { initial_display_name: "PeerTube" })}).then(f => f.json()) if(r.access_token){ - const r2 = fetch(`https://${settings.url}/_matrix/client/v3/logout`, { + const r2 = await fetch(`https://${settings.url}/_matrix/client/v3/logout`, { method: "POST", headers: { - Authorization: r.access_token + Authorization: `Bearer ${r.access_token}` } }); - if(r2.statusCode == 200){ - return res( - options.id, - `${options.id}@0ut0f.space` - ) + if(r2.status == 200){ + return { + username: options.id, + email: `${options.id}@${settings.mail}` + } + }else{ + logger.warn(`Logout of session failed with code ${r2.status}: ${await r2.text()}`); } - } - - } diff --git a/package.json b/package.json index af4ebbc..776e1e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "peertube-plugin-auth-matrix", - "version": "0.0.14", + "version": "0.0.17", "description": "Add Matrix support to login form in PeerTube.", "engine": { "peertube": ">=2.2.0"