Skip to content

Assistant2 CORS policy error. Access to XMLHttpRequest: No 'Access-Control-Allow-Origin' header. #884

Closed
@npacucci

Description

@npacucci

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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions