# \[Solved\] Retrieve Basic auth header from webhook

**URL:** <https://forums.losant.com/t/solved-retrieve-basic-auth-header-from-webhook/433>\
**Category:** Help\
**Created:** [March 3, 2017, 2:59pm UTC](https://forums.losant.com/t/solved-retrieve-basic-auth-header-from-webhook/433 "2017-03-03T14:59:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rorpage](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/rorpage/32/288_2.png) [@rorpage](https://forums.losant.com/u/rorpage)\
**Post date:** [March 3, 2017, 2:59pm UTC](https://forums.losant.com/t/solved-retrieve-basic-auth-header-from-webhook/433/1 "2017-03-03T14:59:33Z")

</div>

I set up a webhook with basic auth and would like to retrieve the username and password sent for the request. I tried using a `Function` node to get the value but was unsuccessful.

Any thoughts or suggestions for me?

---

<div class="post-metadata">

**Author:** ![Michael\_Kuehl](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/michael_kuehl/32/99_2.png) [@Michael\_Kuehl](https://forums.losant.com/u/Michael_Kuehl)\
**Post date:** [March 8, 2017, 9:30pm UTC](https://forums.losant.com/t/solved-retrieve-basic-auth-header-from-webhook/433/2 "2017-03-08T21:30:59Z")

</div>

You were on the right track with the function node - because string splitting is involved, the easiest way is with a function node. I put together the following code that will work in a function node given a webhook triggered flow:

```javascript
if(!payload.data ||
   !payload.data.headers ||
   !payload.data.headers.authorization)
{ return; }

var parts = String(payload.data.headers.authorization).split(/\s+/);
if(parts.length !== 2)
{ return; }
if(parts[0].toLowerCase() !== 'basic')
{ return; }

var credentials = Buffer.from(parts[1], 'base64').toString();
var sep = credentials.indexOf(':');
if (sep === -1) { return; }

payload.data.username = credentials.slice(0, sep);
payload.data.password = credentials.slice(sep + 1);

```

If a valid basic auth header is sent along with the request, the above code in a function node will place the username at `data.username` and the password at `data.password`. Hope that helps!

---

<div class="post-metadata">

**Author:** ![rorpage](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/rorpage/32/288_2.png) [@rorpage](https://forums.losant.com/u/rorpage)\
**Post date:** [March 10, 2017, 5:09pm UTC](https://forums.losant.com/t/solved-retrieve-basic-auth-header-from-webhook/433/3 "2017-03-10T17:09:28Z")

</div>

Amazing, thank you so much!
