2.4 KiB
2.4 KiB
Show
Nodeinfo
from flask import Flask, Response, jsonify
from config import BASE_URL #http://coscup.localhost
app = Flask(__name__)
@app.route("/.well-known/nodeinfo")
def well_known_nodeinfo() -> Response:
"""Return nodeinfo path."""
return jsonify(
{
"links": [
{
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
"href": f"{BASE_URL}/nodeinfo/2.0",
}
]
}
)
@app.get("/nodeinfo/2.0")
def nodeinfo() -> Response:
"""Return nodeinfo."""
return jsonify(
{
"version": "2.0",
"software": {
"name": "COSCUP-demo",
"version": "0.0.1",
},
"protocols": ["activitypub"],
"services": {"inbound": [], "outbound": []},
"usage": {"users": {"total": 1}},
"openRegistrations": False,
"metadata": {},
},
)
GET http://coscup.localhost/.well-known/nodeinfo
GET http://coscup.localhost/nodeinfo/2.0
WebFinger
from flask import Flask, abort, request, Response, jsonify
from config import USERNAME, DOMAIN, ID
#USERNAME = "show"
#DOMAIN = "coscup.localhost"
#ID = f"http://{DOMAIN}/meow/{USERNAME}"
@app.route("/.well-known/webfinger")
def wellknown_webfinger() -> Response:
"""Exposes servers WebFinger data."""
resource = request.args.get("resource")
if resource not in [f"acct:{USERNAME}@{DOMAIN}", config.ID]:
abort(404)
resp = jsonify(
{
"subject": f"acct:{config.USERNAME}@{config.DOMAIN}",
"aliases": [config.ID],
"links": [
{
"rel": "http://webfinger.net/rel/profile-page",
"type": "text/html",
"href": config.ID,
},
{
"rel": "self",
"type": "application/activity+json",
"href": config.ID,
},
],
},
)
resp.headers["Access-Control-Allow-Origin"] = "*"
resp.headers["Content-Type"] = "application/jrd+json; charset=utf-8"
return resp
GET http://coscup.localhost/.well-known/webfinger?resource=acct:show@coscup.localhost