[feat] support webfinger
This commit is contained in:
parent
a5d7d4bdf8
commit
2a0eaef2d0
1 changed files with 47 additions and 1 deletions
48
app.py
48
app.py
|
@ -1,11 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Creatr App"""
|
||||
from flask import Flask, request
|
||||
from flask import Flask, Response, request, Request, abort, jsonify
|
||||
from demo.utils.checker import inbox_prechecker
|
||||
from demo import config
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def is_ap_requested(request: Request) -> bool:
|
||||
accept_str = request.headers.get("accept")
|
||||
if accept_str is None:
|
||||
return False
|
||||
for i in {
|
||||
"application/activity+json",
|
||||
"application/ld+json",
|
||||
}:
|
||||
if accept_str.startswith(i):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""Show index page"""
|
||||
|
@ -19,3 +33,35 @@ def inbox():
|
|||
if is_verify:
|
||||
return "STUB"
|
||||
return "STUB"
|
||||
|
||||
|
||||
@app.route("/.well-known/webfinger")
|
||||
def wellknown_webfinger() -> Response:
|
||||
"""Exposes servers WebFinger data."""
|
||||
resource = request.args.get("resource")
|
||||
|
||||
if resource not in [f"acct:{config.USERNAME}@{config.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
|
||||
|
|
Loading…
Reference in a new issue