# Multi-factor authentication for synthetics

**URL:** <https://community.dynatrace.com/t/multi-factor-authentication-for-synthetics/20939>\
**Category:** Synthetic Monitoring\
**Tags:** sso, browser-monitors\
**Created:** [November 30, 2020, 1:43pm UTC](https://community.dynatrace.com/t/multi-factor-authentication-for-synthetics/20939 "2020-11-30T13:43:31Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![hannahmac](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/hannahmac/32/41823_2.png) [@hannahmac](https://community.dynatrace.com/u/hannahmac)\
**Post date:** [March 18, 2022, 11:59am UTC](https://community.dynatrace.com/t/multi-factor-authentication-for-synthetics/20939/9 "2022-03-18T11:59:06Z")

</div>

You can use the fetch from herehttps://www.dynatrace.com/support/help/how-to-use-dynatrace/synthetic-monitoring/browser-monitors/browser-clickpath-events?\_ga=2.7450162.1463168231.1647250461-719377197.1594986249#expand–example-2-get-a-random-first-name-last-name-from-an-api-endpoint-and-set-it-during-a-sign-up-process–4&nbsp;to get your token. If you need to add headers, you could do it like this:

```c-mrkdwn__pre
api.startAsyncSyntheticEvent();
fetch('<yoururl>', {
    method: 'POST',
    headers: {
        'content-type': 'application/json',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': 'X-Requested-With'
    }
}).then(function(response) {
        if (!response.ok) {
            throw Error(response.status + ":" + response.statusText);
        }
        return response;
   }).then(response => response.text()).then(text => {
        try {
            api.info('Resp length: ' + text.length);
            if (text.indexOf('code') >= 0) {
                <your code to retrieve token>
                api.setValue("token", token);
                api.finish();
            } else {
                api.fail("Invalid Response");
            }
        } catch (err) {
            api.fail("Failed to Execute");
        }
   }).catch(function(error) {
        api.fail(error); 
   });

```

You can then use the variable token later, either by calling&nbsp;api.getValue(token) in a javaScript event or {token} in a field. More info [here](https://www.dynatrace.com/support/help/shortlink/id-brower-clickpath-events#javascript-event-api)

---

_[View the full topic](https://community.dynatrace.com/t/multi-factor-authentication-for-synthetics/20939)._
