microsoft / botbuilder-js

Welcome to the Bot Framework SDK for JavaScript repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using JavaScript.
https://github.com/Microsoft/botframework
MIT License
680 stars 276 forks source link

I have a problem with starting my bot from emulator - BotFrameworkAdapter.processActivity(): 401 ERROR - NotBeforeError: jwt not active #845

Closed montacerdk closed 5 years ago

montacerdk commented 5 years ago

I am developing a bot with Microsoft Bot Framework for Node.js.

I changed the LUIS App in the .bot file wit ha new one and then I generated a new botFileSecret, I tested my bot locally with the Bot Framework Emulator and everything just worked fine.

Then, I got this error:

Error finding key for token.
Available keys: -----BEGIN RSA PUBLIC KEY-----
jwtTokenExtractor.ts:132
MIIBCgKCAQEAt3J1hnS4aRZaZGq5JUw1iKsHynCUV9lMBe2MDArXGeQlN+w8Xw9v
U6InqmPVvJsUVyUkKE0jzn4dYLcwbTuttQ0hmN+lzNfGol04KKMIVdtTs1P0wo/+
VyJ88EuWM3lvDxyTw1PLim14UJ1856zdp2/kZLOSy+B46K96ENJ8b2yCP/VHRTd3
...
-----END RSA PUBLIC KEY-----
JwtTokenExtractor.getIdentity:err!
jwtTokenExtractor.ts:69
NotBeforeError {name: "NotBeforeError", message: "jwt not active", date: Tue Apr 02 2019 09:58:08 GMT+0200 (Romance Dayligh…, stack: "NotBeforeError: jwt not active
    at Object.modul…"}
jwtTokenExtractor.ts:69
BotFrameworkAdapter.processActivity(): 401 ERROR - NotBeforeError: jwt not active
botFrameworkAdapter.ts:555
(node:1888) UnhandledPromiseRejectionWarning: Error: NotBeforeError: jwt not active
warning.js:18
    at BotFrameworkAdapter.processActivity (c:\Users\SP-Montassar\Desktop\quicktext\zoe2\node_modules\botbuilder\src\botFrameworkAdapter.ts:556:19)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
(node:1888) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
warning.js:18
(node:1888) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

After a research, I found this article on Bot Framework Docs explaining how to resolve the bot authentication.

I followed up the steps ..

First step, I verified the App ID and the App Password from the Azure Portal. Then, I deleted the APP ID and the App PWD, I verified that the bot starts fine. I sent a this HTTP request via commandLine to check authentication:

curl -X POST \
  https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials&client_id=<APP_ID>&client_secret=<APP_PWD>&scope=https%253A%252F%252Fapi.botframework.com%252F.default'

I got this response:

  -d : The term '-d' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:3
+   -d 'grant_type=client_credentials&client_id=f4f4bfea-...
+   ~~
    + CategoryInfo          : ObjectNotFound: (-d:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

-H : The term '-H' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:2 char:3
+   -H 'Content-Type: application/x-www-form-urlencoded' \
+   ~~
    + CategoryInfo          : ObjectNotFound: (-H:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token : The term
'https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:3 char:3
+   https://login.microsoftonline.com/botframework.com/oauth2/v2.0/toke ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (https://login.m...uth2/v2.0/token:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Invoke-WebRequest : A parameter cannot be found that matches parameter name 'X'.
At line:4 char:6
+ curl -X POST \
+      ~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Any help for this issue please ?

jwiley84 commented 5 years ago

Investigating

montacerdk commented 5 years ago

Hi, here is some more details,

I just changed the LUIS App in the .bot file with these steps:

I tested the new LUIS app after starting the bot, and everything is alright. Suddenly, I got the Error above when I tried to test the bot with Emulator. it indicated a trouble with authentication (microsoftAppId and microsoftAppPassword).

I followed the instructions in this tutorial from the Bot Framework Docs Troubleshooting Bot Framework authentication.

As a first step, If I delete the microsoftAppId and microsoftAppPassword from the .bot file and make their values null in the index.js file, the error disappears and I can test the bot from Emulator without any issue.

const adapter = new BotFrameworkAdapter({
  appId: null,
  appPassword: null
});

Then, in the second step, I sent this this request in order to check the validity of the appId and appPassword:

curl -X POST \
  https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials&client_id=<APP_ID>&client_secret=<APP_PWD>&scope=https://api.botframework.com/.default'

Then, I found out the the appId and appPassword are valid because I received the access token.

Response:

{
    "token_type": "Bearer",
    "expires_in": 3600,
    "ext_expires_in": 3600,
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGGAKI..."
}

However, I was blocked in the third steps because the same error persists.

For now, the bot starts fine when I run it from VSCode, as shown in this picture.

image

Then, If I start the emulator and it tries to connect the bot I get the same error …

image

I hope that this explantion would be helpful to understand the issue.

Thanks,

montacerdk commented 5 years ago

@jwiley84, this issue is resolved just by generating a new botFileSecret.

CoHealer commented 5 years ago

Closing as resolved

kaushalWa commented 3 months ago

@jwiley84, this issue is resolved just by generating a new botFileSecret.

How to do this?