botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Direct Line] Not able to generate refresh Token and getting error message

Open JeevaJose opened this issue 9 years ago • 7 comments

I have used rest API service to generate token . I pass the web chat secret key as given below.

https://directline.botframework.com/v3/directline/tokens/generate Authorization Bearer xxxxxxxxxxxxxxxxxx

I am able to generate the token and got the following response

{
  "conversationId": "xxxxxx",
  "token": "xxxxxxxxxxxxxx.wYsv_1ktrrW-xxx__SgGRFQbxxxxW_IuPAtY",
  "expires_in": 1800
}

After getting this token I passed to following url to generate the refresh token after the post method I am getting following error message as given below.

Post : https://directline.botframework.com/v3/directline/tokens/refresh Authorization Bearer "xxxxxxxxxxxxxx.wYsv_1ktrrW-xxx__SgGRFQbxxxxW_IuPAtY",

Error Message

{
  "error": {
    "code": "ServiceError",
    "message": "This method can only be used to renew an existing token"
  }
}

I have used post man service to test the rest API service. There is any timeline like before 5 minute expire only call the refresh token or can I call any time to generate refresh token.

Could you please help me to fix this issue.

JeevaJose avatar May 24 '17 06:05 JeevaJose

@JeevaJose are you using .NET or Node SDK?

nwhitmont avatar May 24 '17 15:05 nwhitmont

I am able to fix the issue. hence I am closing this issue.

JeevaJose avatar May 24 '17 17:05 JeevaJose

@JeevaJose thanks for the update.

nwhitmont avatar May 24 '17 21:05 nwhitmont

@JeevaJose Hey I am facing the same issue please tell me how to fix this issue

Sid245439 avatar May 29 '17 11:05 Sid245439

First you have to generate a token and once that token is ready pass to the conversation then will generate a new token. Pass that token and generate a refresh token. https://directline.botframework.com/v3/directline/conversations

without conversation you can’t generate a refresh token. I hope this post will help you to fix the issue.

JeevaJose avatar May 29 '17 15:05 JeevaJose

  1. If you are working in C# you can generate your token using following C# code:
            var token = string.Empty;
            var clnt = new HttpClient();
            clnt.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Your_Directline_Secret");

            var rsp = clnt.PostAsync("https://directline.botframework.com/v3/directline/tokens/generate", new StringContent(string.Empty, Encoding.UTF8, "application/json")).Result;

            if (rsp.IsSuccessStatusCode)
            {
                var str = rsp.Content.ReadAsStringAsync().Result;
                var obj = JsonConvert.DeserializeObject<DirectlineRsp>(str);
                token = obj.token;
            }

At this stage token is ready to use. After a while you can refresh your token using https://directline.botframework.com/v3/directline/tokens/refresh

shahbazkhurram avatar Oct 16 '17 17:10 shahbazkhurram

Could you help me work something out?

We are not using web-chat, we have built our own react front end and using directlineJs.

We have an API that retrieves a token through https://directline.botframework.com/v3/directline/conversations. Upon API response we connect to DirectLine.

Everything works fine, however the token dies in 30 minutes and the conversation locks up.

What we are now trying to do is send a refresh message to https://directline.botframework.com/v3/directline/tokens/refresh passing in our original token, we get a new token back but are unsure what to do next?

morrisond91 avatar Jul 24 '18 12:07 morrisond91