cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

User tagging based on JWT value

denis_vanrijke1
Inactive

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?

7 REPLIES 7

Steiner
Dynatrace Contributor
Dynatrace Contributor

I just got this ask. Were you able to find anything on this?


skrystosik
DynaMight Guru
DynaMight Guru

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


Regards, Sebastian

Steiner
Dynatrace Contributor
Dynatrace Contributor

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).

https://www.dynatrace.com/support/help/shortlink/user-tagging#user-tagging-via-the-dynatrace-javascr...

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>


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


Regards, Sebastian

Steiner
Dynatrace Contributor
Dynatrace Contributor

Thanks Sebastian, will keep that in mind 🙂


fernandosilva
Participant

Hello Support
Still not possible to convert the jwt ?

Vakho
Helper

Is there any update regarding JWT? Can we decode value on the fly?

Featured Posts