Description
Hi,
I'm trying to use the Assistant2 APIs inside my Web Application (Angular CLI project) with the suggested Webpack Configuration .
I followed the official docs to use the APIs on pure Client scenario, as described here:
- https://cloud.ibm.com/docs/services/assistant?topic=assistant-api-client&programming_language=javascript&locale=en
- https://cloud.ibm.com/apidocs/assistant-v2?locale=it&code=node#authentication
Overview
I want to authenticate by iam_apikey, so my configuration is something like this:
import * as Assistant2 from 'ibm-watson/assistant/v2';
const assistant = new Assistant2({
version: '2019-02-28',
iam_apikey: '****************',
url: 'https://gateway-lon.watsonplatform.net/assistant/api'
});
assistant.createSession({
assistant_id: '***************'
})
.then(res => {
console.log(JSON.stringify(res, null, 2));
})
.catch(err => {
console.log(err);
});
Debugging at runtime, after the Assistant2 initialization and before the createSession method execution, the assistant object looks like this:
assistant : {
tokenManager: {
iamApikey: '****************',
iamUrl: 'https://iam.cloud.ibm.com/identity/token',
tokenInfo: { }
},
_options: {
iam_apikey: '****************',
qs: {
version: '2019-02-28'
},
rejectUnauthorized: true,
url: 'https://gateway-lon.watsonplatform.net/assistant/api',
version: '2019-02-28'
}
}
But executing the createSession method, I get the following errors:
Refused to set unsafe header "Accept-Encoding" (xhr.js:126).
Access to XMLHttpRequest at 'https://iam.cloud.ibm.com/identity/token' from origin 'http://localhost:5001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
It seems that the IAM server that should generate the access token is not working.
As quoted here by @germanattanasio .
Expected behavior
The Assistant2 support CORS so I expected to simply call the APIs authenticating by the iam_apikey.
Actual behavior
CORS policy error.
SDK Version
ibm-watson: 4.1.1