0

I need to store a JWT token to use it through several instances of the same orchestration in BizTalk Server 2013 R2.

How can I store it and call it in each instances? Local storage? Registry key? anywhere else?

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
Davon
  • 121
  • 2
  • 9
  • Any reason why you want to do it in the Orchestration? Usually for authentication tokens I use a Custom Endpoint Behavior on the Send Port that gets and caches authentication tokens. – Dijkgraaf Jun 17 '21 at 01:22
  • I don't want to store or get the token in the orchestration. I am developing an endpoint behavior to do this. I would like to know where/how to store it to re use it. My token is valid during 1 hour so, for example, if ESB receive a request, it gets the token then process the request and terminate his first process, then if I receive another request 20 minutes after the first one, I want to re use the token as it still valid. That's why I want to store it somewhere. – Davon Jun 17 '21 at 21:28
  • There should be a way of just persisting it in the End Point Behaviour without an external storage, that is how a Salesforce OAuth Behavior that I've used works. When I get a chance I'll see how it is doing it and post an answer. – Dijkgraaf Jun 18 '21 at 00:06

1 Answers1

0

What you need to do is have a token manager class that is a Static class. Once that is instantiated it will can retain your JWT token in it's private variable and persist as long as you don't restart the host instance. You will also want to hold the time the token was last fetched and fetch a new one if it has expired.

Below is a mock example of what it would look like.

public static class TokenManager
    {
        private static DateTime _sessionLastRefreshDate = DateTime.Now;
        private static string _JWTToken = string.Empty;
  
        public static string GetSession(...)
        {

            //get current date time
            DateTime now = DateTime.Now;
            //get the difference from the last time the token was fetched
            TimeSpan diff = now.Subtract(_sessionLastAccessDate);

            if (_sessionId == string.Empty || (diff.TotalMinutes >= *TokenTimeOut*)
            {
               // Fetch JWT Token here
                        _sessionId = *NewJWTToken*;
                        _sessionLastRefreshDate = DateTime.Now;
            }

            //give the session ID to the caller
            return _sessionId;
        }
    }
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54