Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: moved .well-known assets to separate router file, added basic we…
…bfinger implementation added tests for webfinger controller
- Loading branch information
Showing
6 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
const nconf = require('nconf'); | ||
|
||
const user = require('../user'); | ||
const privileges = require('../privileges'); | ||
|
||
const Controller = module.exports; | ||
|
||
Controller.webfinger = async (req, res) => { | ||
const { resource } = req.query; | ||
const { hostname } = nconf.get('url_parsed'); | ||
|
||
if (!resource || !resource.startsWith('acct:') || !resource.endsWith(hostname)) { | ||
return res.sendStatus(400); | ||
} | ||
|
||
const canView = await privileges.global.can('view:users', req.uid); | ||
console.log('canView', canView, req.uid); | ||
if (!canView) { | ||
return res.sendStatus(403); | ||
} | ||
|
||
// Get the slug | ||
const slug = resource.slice(5, resource.length - (hostname.length + 1)); | ||
|
||
const uid = await user.getUidByUserslug(slug); | ||
if (!uid) { | ||
return res.sendStatus(404); | ||
} | ||
|
||
const response = { | ||
subject: `acct:${slug}@${hostname}`, | ||
aliases: [ | ||
`${nconf.get('url')}/uid/${uid}`, | ||
`${nconf.get('url')}/user/${slug}`, | ||
], | ||
links: [ | ||
{ | ||
rel: 'http://webfinger.net/rel/profile-page', | ||
type: 'text/html', | ||
href: `${nconf.get('url')}/user/${slug}`, | ||
}, | ||
], | ||
}; | ||
|
||
res.status(200).json(response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = function (app, middleware, controllers) { | ||
app.use('/.well-known/change-password', (req, res) => { | ||
res.redirect('/me/edit/password'); | ||
}); | ||
|
||
app.get('/.well-known/webfinger', controllers['well-known'].webfinger); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters