Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.03k stars 1.19k forks source link

Not able to programmatically authenticate to LUIS using subscription key #3936

Closed v-jaswel closed 5 years ago

v-jaswel commented 5 years ago

Is your feature request related to a problem? Please describe. I'm not able to authenticate to LUIS using either ms-rest-azure.CognitiveServicesCredentials or @azure/ms-rest-js.ApiKeyCredentials. One or the other of these has previously worked for me with other Cognitive Services (QnAMaker, Custom Search, etc).

// Using CognitiveServicesCredentials
const LUIS = require("@azure/cognitiveservices-luis-authoring");
const msRest = require("ms-rest-azure");
const creds = new msRest.CognitiveServicesCredentials(subscription_key);
const client = new LUIS.LUISAuthoringClient (creds, endpoint);
// Using ApiKeyCredentials
const LUIS = require("@azure/cognitiveservices-luis-authoring");
const msRest = require("@azure/ms-rest-js");
const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscription_key } });
const client = new LUIS.LUISAuthoringClient (creds, endpoint);

With either of these, I get the same error:

C:\Users\<user>\Documents\Quickstarts20190604\LUIS_Node>node 1.js
C:\Users\<user>\node_modules\@azure\ms-rest-js\dist\msRest.node.js:3298
            throw new Error("credentials argument needs to implement signRequest method");
            ^

Error: credentials argument needs to implement signRequest method
    at LUISAuthoringClient.ServiceClient (C:\Users\<user>\node_modules\@azure\ms-rest-js\dist\msRest.node.js:3298:19)
    at LUISAuthoringClientContext [as constructor] (C:\Users\<user>\node_modules\@azure\cognitiveservices-luis-authoring\dist\cognitiveservices-luis-authoring.js:9759:28)
    at new LUISAuthoringClient (C:\Users\<user>\node_modules\@azure\cognitiveservices-luis-authoring\dist\cognitiveservices-luis-authoring.js:9788:32)
    at Object.<anonymous> (C:\Users\<user>\Documents\Quickstarts20190604\LUIS_Node\1.js:44:16)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)

I'm not finding any useful information about the "credentials argument needs to implement signRequest method" error. All the sample code I've found for authenticating to Cognitive Services seems to involve using interactive logon.

Describe the solution you'd like As I understand it I should be able to authenticate to a given Cognitive Service with an Azure subscription key (just as I would if I used the REST API), but I'm not sure what credential class I should be using.

Describe alternatives you've considered I've been searching for several hours and haven't found any sample code that seems relevant to my problem.

Additional context Please let me know if I can provide any additional information. Thank you!

praries880 commented 5 years ago

Thank you for opening this issue! We are routing it to the appropriate team for follow up.

v-jaswel commented 5 years ago

Please disregard. This was happening because I had the constructor parameters reversed. I should have used: const client = new LUIS.LUISAuthoringClient (endpoint, creds); Thank you!

wiazur commented 4 years ago

I tested this again, and now the const client = new LUIS.LUISAuthoringClient (endpoint, creds); gives the error, and it's flip of params does not: const client = new LUIS.LUISAuthoringClient (creds, endpoint);