You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(Authorization): Speech to Text WebSockets recognize (#717)
This PR addresses the issues users were having with STT, specifically using streaming operations with IAM authentication.
Authenticating with an IAM API key requires requests to be made in order to get an access token. These request interrupt the stream and cause the streaming operation to fail. My solution for this is to give users an option (an option, but it's required for IAM and streams to work) to pre-authenticate and receive a `ready` flag that tells them they are good to proceed with the request. It is not the cleanest solution but I have not thought of a better way.
What this function does is make any IAM requests, if necessary. When the user makes their service request, the code will see that an access token is already stored and will launch the request without any delays that would interrupt the stream.
This line:
```js
const authHeader = { Authorization: 'Bearer ' + token };
this._options.headers = extend(authHeader, this._options.headers);
```
is for `createRecognizeStream`, which looks for an authorization header in `this._options.headers`.
An example of using this method:
```js
stt.preAuthenticate(function(ready) {
if (!ready) {
return;
}
stt.recognize(params, function(err, res) {
if (err) {
console.log(err);
} else {
console.log(JSON.stringify(res, null, 2));
}
});
});
```
We can definitely change the name too. Happy to take any suggestions.
TODO:
- [ ] Run tests
- [ ] Add a section about this in the README
0 commit comments