question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Technical Questions] How to consistently expire directline token?

See original GitHub issue

Hello!

I have been working with botframework-webchat and directline-js for almost a year.

In our project we have implemented token renewal on connection status change to ExpiredToken. But I have not been able to expire it consistently to be able to deploy changes to production as the I do not understand the behavior.

Subscribed to connection status changes:

const directLineOptions: DirectLineOptions = {
      webSocket: config.webSocket,
      token: config.token,
      domain: config.domain,
    };
directLine = createDirectLine(directLineOptions);
directLine!.connectionStatus$.subscribe(connectionStatusObserver);

const connectionStatusObserver = (status: ConnectionStatus) => {
  switch (status) {
    case ConnectionStatus.ExpiredToken:
      // here i'm renewing conversation through server side with secret
      // I have not found a way for directline to wait for the async
      // token renewal before it immediately goes into Ended status.
      store.dispatch(renewTokenRequest()); 
      break;

    case ConnectionStatus.Ended:
        // indication that direct-line has disconnected/ended
        store.dispatch(setDirectLineDisconnected(true));
        // after that I try to re-create directline connection
      break;
  }
};

DirectlineJS documentation in readme file:

If your app created your DirectLine object by passing a token, DirectLine will refresh that token every 15 minutes. Should your client lose connectivity (e.g. close laptop, fail to pay Internet access bill, go under a tunnel), connectionStatus$ will change to ConnectionStatus.ExpiredToken. Your app can request a new token from its server, which should call the Reconnect API. The resultant Conversation object can then be passed by the app to DirectLine.

By turning off internet connection for my PC the only thing in Chrome Developer Console is the bellow error message. Directline in this case does not trigger ExpiredToken status at all.

ajax.js:129 OPTIONS https://europe.directline.botframework.com/v3/directline/tokens/refresh net::ERR_INTERNET_DISCONNECTED

To manually trigger the status I fiddle with directline object in memory by setting its’ token and conversation id to an old one (> few days). On next user activity directline does change to ExpiredToken status.

I have read the whole documentation of directline V3 and I haven’t found the answers there.

Project setup:

  • Create React App (boilerplate) + Redux + Redux Persist
  • .NET MVC server side
  • BotFramework-WebChat

The questions I have are:

  1. How long does a conversation stay available?
  2. How long does a conversation token live? What is the time period when it expires?
  3. How to expire the token from a user perspective consistently?

Best regards

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
v-kydelacommented, Dec 16, 2019

@avilde - I have access to the token service source code, so asking me is as good as asking a bot service developer.

You’ve shown me that 403 errors are being encountered when calling the v3/directline/tokens/refresh endpoint, but there are quite a few ways that a 403 error could be encountered when calling that endpoint. To know what specifically is going on, we’d need to know the message that came with the 403:

  1. “Missing token or secret”
  2. “Token has expired”
  3. “Invalid token or secret”
  4. “Invalid token or secret, siteKey null”
  5. “Invalid token or secret, bad conversationid or token type”
  6. “Site missing”
  7. “Site disabled”
  8. “Bot is missing”
  9. “Bot is disabled”
  10. “Bot not allowed”
  11. “Origin not allowed”
  12. “Invalid secret or token”
  13. “This method can only be used to renew an existing token”
0reactions
v-kydelacommented, Dec 23, 2019

Closing due to inactivity

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle directline Tokens and their "expires_in" - Stack Overflow
If you plan on using tokens, then automate the call to refresh the token before it expires. Then swap the token out for...
Read more >
Direct Line Authentication in Azure Bot Service - Microsoft Learn
A Direct Line token is a key that can be used to access a single conversation. A token expires but can be refreshed....
Read more >
Embed a bot in a web page using Web Chat - Bot Framework
The Direct Line secret can be used to access all of the bot's conversations; it doesn't expire. The Direct Line token can only...
Read more >
botframework-directlinejs - npm
If your app created your DirectLine object by passing a token, DirectLine will refresh that token every 15 minutes. Should your client lose ......
Read more >
Guidance Manual for Administrative Officers and ACOS ...
VA Technology Transfer office and as a signatory on the VA Certification form ... question.1 The VA definition of research is consistent with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found