commit b0461ea329a49b544ebe81165b287b171d248039 Author: doesnm Date: Fri Nov 22 12:52:48 2024 +0300 In the beginning... diff --git a/README.md b/README.md new file mode 100644 index 0000000..1729264 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Matrix auth plugin for PeerTube +Forked from LDAP plugin \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..5132f64 --- /dev/null +++ b/main.js @@ -0,0 +1,79 @@ +const fs = require('fs/promises') + + +async function register ({ + registerIdAndPassAuth, + registerSetting, + settingsManager, + peertubeHelpers +}) { + + registerSetting({ + name: 'url', + label: 'Domain', + type: 'input', + descriptionHTML: 'domain of matrix server', + private: true + }) + + + + registerIdAndPassAuth({ + authName: 'matrix', + getWeight: () => 500, + login: options => login(peertubeHelpers, settingsManager, options) + }) + + setWeight(500) + +} + +async function unregister () { + return +} + +module.exports = { + register, + unregister +} + +async function login (peertubeHelpers, settingsManager, options) { + const logger = peertubeHelpers.logger + + const settings = await settingsManager.getSettings([ + 'url', + ]) + // options.id, options.password + + const r = await fetch(`https://${settings.url}/_matrix/client/v3/login`, { + method: "POST", + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + type: "m.login.password", + identifier: { + type: "m.id.user", + user: options.id, + }, + password: options.password, + initial_display_name: "PeerTube" + })}).then(f => f.json()) + if(r.access_token){ + const r2 = fetch(`https://${settings.url}/_matrix/client/logout`, { + method: "POST", + headers: { + Authorization: r.access_token + } + }); + if(r2.statusCode == 200){ + return res( + options.id, + `${options.id}@0ut0f.space` + ) + } + + } + + +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..af4ebbc --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "peertube-plugin-auth-matrix", + "version": "0.0.14", + "description": "Add Matrix support to login form in PeerTube.", + "engine": { + "peertube": ">=2.2.0" + }, + "keywords": [ + "peertube", + "plugin", + "auth" + ], + "homepage": "https://framagit.org/framasoft/peertube/official-plugins/tree/master/peertube-plugin-auth-ldap", + "author": "Chocobozzz", + "bugs": "https://framagit.org/framasoft/peertube/official-plugins/issues", + "library": "./main.js", + "staticDirs": {}, + "css": [], + "clientScripts": [], + "translations": {}, + "dependencies": {} +}