# Store credentials from backend code

**URL:** <https://discourse.nodered.org/t/store-credentials-from-backend-code/35259>\
**Category:** Developing Nodes\
**Created:** [3 November 2020 06:49 UTC](https://discourse.nodered.org/t/store-credentials-from-backend-code/35259 "2020-11-03T06:49:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnoldpistorius](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@arnoldpistorius](https://discourse.nodered.org/u/arnoldpistorius)\
**Post date:** [3 November 2020 06:49 UTC](https://discourse.nodered.org/t/store-credentials-from-backend-code/35259/1 "2020-11-03T06:49:14Z")

</div>

Hi,

I'm trying to store a refresh token of the Microsoft Graph API as a credential. I can store the tenant id and client id from the html page (Node-RED is taking care of that), but the refresh token is generated by backend code (my-config-node.js file). In the documentation I see this paragraph under [Advanced credential use](https://nodered.org/docs/creating-nodes/credentials) and I analyzed the [twitter node source](https://github.com/node-red/node-red-nodes/blob/master/social/twitter/27-twitter.js), but as far as I can tell the Twitter node does not actually save a credential from the backend javascript.

> Whilst the credential system outlined above is sufficient for most cases, in some circumstances it is necessary to store more values in credentials than just those that get provided by the user. For example, for a node to support an OAuth workflow, it must retain server-assigned tokens that the user never sees. The Twitter node provides a good example of how this can be achieved.

I've tried to just assign the value to `this.credentials.refreshToken` but that value is lost after Node-RED is stopped.

Can you help me out with my use case?

Thank you,  
Arnold

---

<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:** [2 January 2021 06:49 UTC](https://discourse.nodered.org/t/store-credentials-from-backend-code/35259/2 "2021-01-02T06:49:20Z")

</div>

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