Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@jeancarl

Description

@jeancarl

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions