webfinger / AP user

This commit is contained in:
lesion
2019-07-29 01:27:47 +02:00
parent 37895087c0
commit f98820dafe
9 changed files with 136 additions and 6 deletions

View File

@@ -102,7 +102,7 @@ api.get('/event/:month/:year', eventController.getAll)
// api.get('/event/:month/:year', eventController.getAfter)
// mastodon oauth auth
api.post('/settings/getauthurl', jwt, isAuth, isAdmin, settingsController.getAuthURL)
api.get('/settings/oauth', jwt, isAuth, isAdmin, settingsController.code)
//api.post('/settings/getauthurl', jwt, isAuth, isAdmin, settingsController.getAuthURL)
//api.get('/settings/oauth', jwt, isAuth, isAdmin, settingsController.code)
module.exports = api

View File

@@ -0,0 +1,30 @@
const express = require('express')
const router = express.Router()
const { user: User } = require('../api/models')
const config = require('config')
router.get('/u/:name', async (req, res) => {
const name = req.params.name
if (!name) return res.status(400).send('Bad request.')
const user = await User.findOne({where: { username: name }})
if (!user) return res.status(404).send(`No record found for ${name}`)
const domain = 'local'
const ret = {
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1'
],
'id': `${config.baseurl}/federation/u/${name}`,
'type': 'Person',
'preferredUsername': name,
'inbox': `${config.baseurl}/federation/inbox`,
'followers': `${config.baseurl}/federation/u/${name}/followers`,
'publicKey': {
'id': `${config.baseurl}/federation/u/${name}#main-key`,
'owner': `${config.baseurl}/federation/u/${name}`,
'publicKeyPem': user.pubkey
}
}
res.json(ret)
})
module.exports = router

View File

@@ -0,0 +1,27 @@
const express = require('express')
const router = express.Router()
const { user: User } = require('../api/models')
const config = require('config')
router.get('/', async (req, res) => {
const resource = req.query.resource
if (!resource || !resource.includes('acct:')) {
return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.')
}
const name = resource.replace('acct:', '')
const domain = 'localhoasf'
const user = await User.findOne({where: { username: name } })
if (!user) return res.status(404).send(`No record found for ${name}`)
const ret = {
subject: `acct:${name}:${domain}`,
links: [
{
rel: 'self',
type: 'application/activity+json',
href: `${config.baseurl}/federation/u/${name}`
}
]
}
res.json(ret)
})
module.exports = router

View File

@@ -3,6 +3,7 @@ const path = require('path')
const express = require('express')
const consola = require('consola')
const morgan = require('morgan')
const cors = require('cors')
const { Nuxt, Builder } = require('nuxt')
// Import and Set Nuxt.js options
@@ -24,12 +25,15 @@ async function start() {
}
// configurable favicon && logo
app.use('/favicon.ico', express.static(path.resolve(config.favicon)))
app.use('/favicon.ico', express.static(path.resolve(config.favicon || 'assets/favicon.ico')))
app.use(morgan('dev'))
app.use('/media/', express.static(config.upload_path))
app.use('/api', require('./api/index'))
app.use('/.well-known/webfinger', cors(), require('./federation/webfinger'))
app.use('/federation', cors(), require('./federation'))
// Give nuxt middleware to express
app.use(nuxt.render)

View File

@@ -0,0 +1,29 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn('users', 'username', {
type: Sequelize.STRING,
index: true,
allowNull: false,
defaultValue: ''
})
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
},
down: (queryInterface, Sequelize) => {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.dropTable('users');
*/
}
};

View File

@@ -0,0 +1,26 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn('users', 'display_name', {
type: Sequelize.STRING
})
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
},
down: (queryInterface, Sequelize) => {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.dropTable('users');
*/
}
};