In the beginning...

This commit is contained in:
doesnm 2024-11-22 12:52:48 +03:00
commit b0461ea329
Signed by: doesnm
SSH key fingerprint: SHA256:fSXBOeK0SXxGqmbQ2pKhSvH3TF0kCijXZfzh3gHfQYM
3 changed files with 103 additions and 0 deletions

2
README.md Normal file
View file

@ -0,0 +1,2 @@
# Matrix auth plugin for PeerTube
Forked from LDAP plugin

79
main.js Normal file
View file

@ -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`
)
}
}
}

22
package.json Normal file
View file

@ -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": {}
}