Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client_id to analytics events #736

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Dfe.Analytics.AspNetCore;

namespace TeacherIdentity.AuthServer.Infrastructure.Middleware;

public class AppendAuthorizationInfoToAnalyticsEventsMiddleware
{
private readonly RequestDelegate _next;

public AppendAuthorizationInfoToAnalyticsEventsMiddleware(RequestDelegate next)
{
_next = next;
}

public Task Invoke(HttpContext context)
{
var analyticsEvent = context.GetWebRequestEvent();
var clientRedirectInfo = context.GetClientRedirectInfo();

if (context.TryGetAuthenticationState(out var authenticationState))
{
if (!string.IsNullOrEmpty(authenticationState.SessionId))
{
analyticsEvent.AddData("session_id", authenticationState.SessionId);
}

if (authenticationState.TryGetOAuthState(out var oAuthState))
{
analyticsEvent.AddData("client_id", oAuthState.ClientId);
}
}
else if (clientRedirectInfo is not null)
{
analyticsEvent.AddData("client_id", clientRedirectInfo.ClientId);
}

return _next(context);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public static async Task Main(string[] args)
a =>
{
a.UseDfeAnalytics();
a.UseMiddleware<Infrastructure.Middleware.AppendSessionIdToAnalyticsEventsMiddleware>();
a.UseMiddleware<Infrastructure.Middleware.AppendAuthorizationInfoToAnalyticsEventsMiddleware>();
});
}

Expand Down
Loading