Reputation: 79
Running Node v10 ibm-watson v5.1.0
Getting error when try to obtain token for speech-to-text.
{ "message": "Authenticator must be set.", "name": "Error", "stack": "Error: Authenticator must be set.\n at AuthorizationV1.BaseService (/nodejsAction/VuncPM95/node_modules/ibm-cloud-sdk-core/lib/base-service.js:66:19)\n at new AuthorizationV1 (/nodejsAction/VuncPM95/node_modules/ibm-watson/authorization/v1.js:44:28)\n at Object.token (/nodejsAction/VuncPM95/services/stt.js:17:32)\n at speech-to-text_token (/nodejsAction/VuncPM95/index.js:42:54)\n at Object.exec (/nodejsAction/VuncPM95/index.js:33:73)\n at Promise (/nodejsAction/VuncPM95/index.js:10:16)\n at new Promise ()\n at NodeActionRunner.main [as userScriptMain] (/nodejsAction/VuncPM95/index.js:9:12)\n at Promise (/nodejsAction/runner.js:73:35)\n at new Promise ()" }
When try with typescript 3.6.4
{ "message": "Authenticator must be set.", "name": "Error", "stack": "Error: Authenticator must be set.\n at t.e (eval at initializeActionHandler (/nodejsAction/runner.js:57:23), :22:45665)\n at new t (eval at initializeActionHandler (/nodejsAction/runner.js:57:23), :16:49145)\n at Object.token (eval at initializeActionHandler (/nodejsAction/runner.js:57:23), :22:44594)\n at speech-to-text_token (eval at initializeActionHandler (/nodejsAction/runner.js:57:23), :22:43617)\n at Object.exec (eval at initializeActionHandler (/nodejsAction/runner.js:57:23), :22:43498)\n at Promise (eval at initializeActionHandler (/nodejsAction/runner.js:57:23), :22:43038)\n at new Promise ()\n at NodeActionRunner.a [as userScriptMain] (eval at initializeActionHandler (/nodejsAction/runner.js:57:23), :22:43016)\n at Promise (/nodejsAction/runner.js:73:35)\n at new Promise ()" }
export const SpeechToText = {
token: (params: WatsonParams) => {
const sttCredentials = Object.assign(
{
username: params.speechToTextUsername, // or hard-code credentials here
password: params.speechToTextPassword,
iam_apikey: params.speechToTextIamApikey, // if using an RC service
url: params.speechToTextUrl ? params.speechToTextUrl : SpeechToTextV1.URL
},
vcapServices.getCredentials('speech_to_text') // pulls credentials from environment in bluemix, otherwise returns {}
);
const sttAuthService = new AuthorizationV1(sttCredentials);
return Observable.create((observer) => {
sttAuthService.getToken(function(err, response) {
if (err) {
console.log('Error retrieving token: ', err);
observer.error('Error retrieving token...');
} else {
const token = response.token || response;
if (params.speechToTextIamApikey) {
observer.next({ accessToken: token, url: sttCredentials.url });
} else {
observer.next({ token: token, url: sttCredentials.url });
}
observer.complete();
}
});
});
}
}
Expect it to return a token.
Upvotes: 0
Views: 407
Reputation: 597
Authentication changed in v5. See MIGRATION-V5
The SDK service constructors now accept
Authenticator
objects that are used to authenticate requests. The constructors no longer accept individual credentials likeusername
andpassword
.
Here's an example from the API reference.
const SpeechToTextV1 = require('ibm-watson/speech-to-text/v1');
const { IamAuthenticator } = require('ibm-watson/auth');
const speechToText = new SpeechToTextV1({
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
url: '{url}',
});
Upvotes: 2