Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synthesize method does not honor access_token from IAM API Key #92

Closed
jeancarl opened this issue Oct 31, 2018 · 1 comment
Closed

Synthesize method does not honor access_token from IAM API Key #92

jeancarl opened this issue Oct 31, 2018 · 1 comment

Comments

@jeancarl
Copy link
Contributor

In SDK v.0.36 with Firefox 60.3.0esr (64-bit), using the new IAM API Key authentication for Text to Speech, the synthesize method filters out the access_token parameter.

var params = {
  text: "Hello",
  voice: "en-US_MichaelVoice",
  access_token: "<ACCESS_TOKEN>"
};

stream = WatsonSpeech.TextToSpeech.synthesize(params);

The requested URI resource doesn't include this access token and the watson-token parameter is undefined, returning a CORS error.

https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_MichaelVoice&text=Hello&watson-token=**undefined**

Fix

https://github.com/watson-developer-cloud/speech-javascript-sdk/blob/master/dist/watson-speech.js#L12127

Add access_token to the QUERY_PARAMS_ALLOWED array.

var QUERY_PARAMS_ALLOWED = ['voice', 'X-WDC-PL-OPT-OUT', 'X-Watson-Learning-Opt-Out', 'text', 'watson-token', 'accept', 'customization_id', 'access_token'];

There should also be a check that token parameter is defined, given it's either token or access_token.

module.exports = function synthesize(options) {
  if (!options || (!options.token && !options.access_token)) {
    throw new Error('Watson TextToSpeech: missing required parameter: options.token (CF) or options.access_token (RC)');
  }
  options['watson-token'] = options.token;
  delete options.token;
  var audio = options.element || new Audio();

Fix

module.exports = function synthesize(options) {
  if (!options || (!options.token && !options.access_token)) {
    throw new Error('Watson TextToSpeech: missing required parameter: options.token (CF) or options.access_token (RC)');
  }
  if(options.token) {
    options['watson-token'] = options.token;
    delete options.token;
  }
  var audio = options.element || new Audio();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants