diff --git a/endpoints/trackhelper.py b/endpoints/trackhelper.py index 7635d2a19..cf0fad65d 100644 --- a/endpoints/trackhelper.py +++ b/endpoints/trackhelper.py @@ -4,7 +4,8 @@ import random from app import analytics, app, userevents from data import model from flask import request -from auth.auth_context import get_authenticated_user, get_validated_token, get_validated_oauth_token +from auth.auth_context import (get_authenticated_user, get_validated_token, + get_validated_oauth_token, get_grant_user_context) logger = logging.getLogger(__name__) @@ -22,6 +23,11 @@ def track_and_log(event_name, repo, analytics_name=None, analytics_sample=1, **k authenticated_oauth_token = get_validated_oauth_token() authenticated_user = get_authenticated_user() authenticated_token = get_validated_token() if not authenticated_user else None + granted_username = get_grant_user_context() + + # TODO: Fix this to support OAuth tokens as well. + if granted_username is not None: + authenticated_user = model.user.get_user(granted_username) logger.debug('Logging the %s to Mixpanel and the log system', event_name) if authenticated_oauth_token: