Tweak the IndieAuth log

This commit is contained in:
Thomas Sileo 2019-05-08 13:19:31 +02:00
parent 713eb6acac
commit 1d0d5fa8b1
2 changed files with 22 additions and 2 deletions

19
app.py
View file

@ -2183,6 +2183,18 @@ def indieauth_flow():
return redirect(red) return redirect(red)
def _get_ip():
ip = request.headers.get("X-Forwarded-For", request.remote_addr)
geoip = None
if request.headers.get("Broxy-Geoip-Country"):
geoip = (
request.headers.get("Broxy-Geoip-Country")
+ "/"
+ request.headers.get("Broxy-Geoip-Region")
)
return ip, geoip
@app.route("/indieauth", methods=["GET", "POST"]) @app.route("/indieauth", methods=["GET", "POST"])
def indieauth_endpoint(): def indieauth_endpoint():
if request.method == "GET": if request.method == "GET":
@ -2214,6 +2226,8 @@ def indieauth_endpoint():
redirect_uri = request.form.get("redirect_uri") redirect_uri = request.form.get("redirect_uri")
client_id = request.form.get("client_id") client_id = request.form.get("client_id")
ip, geoip = _get_ip()
auth = DB.indieauth.find_one_and_update( auth = DB.indieauth.find_one_and_update(
{ {
"code": code, "code": code,
@ -2226,6 +2240,8 @@ def indieauth_endpoint():
"verified": True, "verified": True,
"verified_by": "id", "verified_by": "id",
"verified_at": datetime.now().timestamp(), "verified_at": datetime.now().timestamp(),
"ip_address": ip,
"geoip": geoip,
} }
}, },
) )
@ -2258,6 +2274,7 @@ def token_endpoint():
client_id = request.form.get("client_id") client_id = request.form.get("client_id")
now = datetime.now() now = datetime.now()
ip, geoip = _get_ip()
# This query ensure code, client_id, redirect_uri and me are matching with the code request # This query ensure code, client_id, redirect_uri and me are matching with the code request
auth = DB.indieauth.find_one_and_update( auth = DB.indieauth.find_one_and_update(
@ -2273,6 +2290,8 @@ def token_endpoint():
"verified": True, "verified": True,
"verified_by": "code", "verified_by": "code",
"verified_at": now.timestamp(), "verified_at": now.timestamp(),
"ip_address": ip,
"geoip": geoip,
} }
}, },
) )

View file

@ -9,8 +9,9 @@
<ul style="list-style-type:none;padding:0;"> <ul style="list-style-type:none;padding:0;">
{% for action in indieauth_actions %} {% for action in indieauth_actions %}
<li style="margin-bottom:15px;"><span class="lcolor">{{action.ts|format_ts}}</span> <li style="margin-bottom:15px;"><span class="lcolor">{{action.ts|format_ts}}</span>
<strong>{% if action.verified_by == "login" %}Authorization{% else %}Token{% endif %}</strong> <strong>{% if action.verified_by == "login" %}Authentication {% else %}Authorization {% endif %}</strong>
requested by <a style="font-weight:bold" href="{{ action.client_id }}">{{ action.client_id }}</a> request by <a style="font-weight:bold" href="{{ action.client_id }}">{{ action.client_id }}</a>
/ {{action.ip_address}} {% if action.geoip %}({{action.geoip}}){% endif %}
as <a style="font-weight:bold;" href="{{action.me}}">{{action.me}}</a> as <a style="font-weight:bold;" href="{{action.me}}">{{action.me}}</a>
({% if action.scope %}scope=<code>{{action.scope}}</code>,{% endif %}redirect_uri={{action.redirect_uri}}). ({% if action.scope %}scope=<code>{{action.scope}}</code>,{% endif %}redirect_uri={{action.redirect_uri}}).
{% if action.token_expires %} {% if action.token_expires %}