30 May 2018 01:02 PM - last edited on 30 Sep 2022 01:33 PM by MaciejNeumann
Our usernames are sent with every client requests in a X-AuthenticationToken header.
This header contains a base64 encoded Json Web Token. We would like to extract the "uid" field from this token and use it for user tagging.
Has anyone already encountered this use-case?
30 May 2019 07:53 PM
I just got this ask. Were you able to find anything on this?
30 May 2019 10:25 PM
There is no option to make base64 decode in Dynatrace request attributes post production settings. Only regexes and similar options are there. For now still it is impossible to accomplish such task.
Sebastian
30 May 2019 10:36 PM
Looking into this some more, using the JavaScript API to put in our own JS code I'm wondering if it is possible. Taking a function from Stack Overflow on decoding base64. Then use another function to extract just the username from the decrypted token and set it using dtrum.identifyUser(username).
I'm not sure if this would add extra response time to the transaction or even work.. but just an idea.
Example:
<script type="text/javascript">
function parseJwt (token) {
var base64Url = token.split('.')[1];
var base64 = decodeURIComponent(atob(base64Url).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
var username = extractUsername(base64);
dtrum.identifyUser(username);
};
function extractUsername(decryptedToken) {
..... (this code we'd need to figure out, how to get the username out of the JSON or XML or whatever format it's in)
return (username)
};
</script>
31 May 2019 05:40 AM
In general if you have option to modify code of your application you can always decode JWT and store result in global JS variable, cookie or send via JavaScript api to dynatrace directly. It’s quite simple code but you should be sure to pick place where it will be executed for all users and only once (for example on first page after signin). This important to not add extra and not necessary code just for monitoring on every pageload 🙂
Sebastian
31 May 2019 03:39 PM
Thanks Sebastian, will keep that in mind 🙂
26 Apr 2022 06:20 PM
Hello Support
Still not possible to convert the jwt ?
12 Jun 2023 08:17 PM
Is there any update regarding JWT? Can we decode value on the fly?