events: record source when user is using source to authenticate

This commit is contained in:
Jens Langhammer 2021-01-12 22:48:55 +01:00
parent 61d1407804
commit 36bc1dc020
2 changed files with 16 additions and 0 deletions

View File

@ -1,4 +1,6 @@
"""authentik events signal listener"""
from authentik.flows.planner import FlowPlan, PLAN_CONTEXT_SOURCE
from authentik.flows.views import SESSION_KEY_PLAN
from threading import Thread
from typing import Any, Dict, Optional
@ -46,6 +48,11 @@ class EventNewThread(Thread):
def on_user_logged_in(sender, request: HttpRequest, user: User, **_):
"""Log successful login"""
thread = EventNewThread(EventAction.LOGIN, request)
if SESSION_KEY_PLAN in request.session:
flow_plan: FlowPlan = request.session[SESSION_KEY_PLAN]
if PLAN_CONTEXT_SOURCE in flow_plan.context:
# Login request came from an external source, save it in the context
thread.kwargs["using_source"] = flow_plan.context[PLAN_CONTEXT_SOURCE]
thread.user = user
thread.run()

View File

@ -136,6 +136,15 @@ export class EventInfo extends LitElement {
// Action types which typically don't record any extra context.
// If context is not empty, we fall to the default response.
case "login":
if ("using_source" in this.event.context) {
return html`<div class="pf-l-flex">
<div class="pf-l-flex__item">
<h3>${gettext("Using source")}</h3>
${this.getModelInfo(this.event.context.using_source as EventContext)}
</div>
</div>`;
}
return this.defaultResponse();
case "logout":
if (this.event.context === {}) {
return html`<span>${gettext("No additional data available.")}</span>`;