# HTTP Request - Persistent authorization token

**URL:** <https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175>\
**Category:** General\
**Tags:** http-request\
**Created:** [13 October 2021 17:24 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175 "2021-10-13T17:24:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zuasive](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zuasive](https://discourse.nodered.org/u/zuasive)\
**Post date:** [13 October 2021 17:24 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175/1 "2021-10-13T17:24:42Z")

</div>

Hello good people, I'm hoping for an assist here. I've been trying to get a flow working for some time now and keep hitting a road block. The goal is to be able to do a lookup on a separate REST service using 3 posts w/json which are; login, lookup, logoff. There is a random token in the headers, at least that is what I have identified with Postman code.

I have tried using a change node and a function node. Does anyone know a way to use a token with the request? I've seen it with hosting in tutorials but passing that token taken from the first call through the next two calls is proving a challenge.

The token is basically a cached session ID but is only referred to in headers.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [13 October 2021 21:08 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175/2 "2021-10-13T21:08:22Z")

</div>

if you are using the HTTP Request node.  
you can supply a `headers` object.

1. Store the header value from the resulting call (presumably login)

2. Use the value later.

```auto
{
  "payload": {...},
  "method":"POST",
  "url": "yourURL",
  "headers": {
    "Content-Type": "application/json",
    "Header-Name": "Stored-Value"
  }
}

```

---

<div class="post-metadata">

**Author:** ![zuasive](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zuasive](https://discourse.nodered.org/u/zuasive)\
**Post date:** [14 October 2021 01:29 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175/3 "2021-10-14T01:29:44Z")

</div>

I've been able to separate out the session value into an object using the change node and yes it is definitely the HTTP request node. I'm assuming this would be used in a template node correct? I've not tried coding the json headers and body together I've just been using the change node for the headers. I'll work around with this and see what I can do. Thanks!

---

<div class="post-metadata">

**Author:** ![zuasive](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zuasive](https://discourse.nodered.org/u/zuasive)\
**Post date:** [14 October 2021 05:38 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175/4 "2021-10-14T05:38:57Z")

</div>

Alright, so the problem here is I don't know what the token will be until the login occurs. I want to automate this request in the flow so I don't have to manually input the token which expires after 2 minutes.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [14 October 2021 05:55 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175/5 "2021-10-14T05:55:26Z")

</div>

After you have done your login, store the token in global context using a change node.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96cb9952162c49b57d6887e0eed92c55f2c68b98.png)

Then later, you can call back into the stored global.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/df4146f097e394df30f11e22ea22f388d6c0c305.png)

You can do this with functions nodes also. (my first example)

---

<div class="post-metadata">

**Author:** ![zuasive](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zuasive](https://discourse.nodered.org/u/zuasive)\
**Post date:** [14 October 2021 14:02 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175/6 "2021-10-14T14:02:47Z")

</div>

Thanks for being so granular. I verified I am storing the token properly and it is coming across in the global as you described. I'm still getting a failure response from their service on the second request after login not being authenticated even with "keep-alive" enabled.

I'll re-verify what is being sent by my flow vs. the 3rd party requirement. Unfortunately I'm dealing with an IIS service.

---

<div class="post-metadata">

**Author:** ![zuasive](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zuasive](https://discourse.nodered.org/u/zuasive)\
**Post date:** [14 October 2021 14:06 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175/7 "2021-10-14T14:06:42Z")

</div>

I think I found it. The site is using a bearer token.

---

<div class="post-metadata">

**Author:** ![zuasive](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zuasive](https://discourse.nodered.org/u/zuasive)\
**Post date:** [14 October 2021 14:22 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175/8 "2021-10-14T14:22:59Z")

</div>

Well I stand corrected, I just tried manually injecting the login process, getting the session/token and then copied into the bearer token in the http request. I still get an authorization error so their service is quite frustrating.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 October 2021 14:23 UTC](https://discourse.nodered.org/t/http-request-persistent-authorization-token/52175/9 "2021-10-28T14:23:23Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
