Angular 2 with Magento Integration

336 views
Skip to first unread message

belyamani mohammed

unread,
Mar 18, 2017, 5:59:34 PM3/18/17
to Angular and AngularJS discussion

This is integration issue. Your help is very appreciated


I have both Angular2 and Magento2 (bitnami) installed locally. Magento conf was changed to have the right headers (See below) for CROS.

I'm calling Magento2  from Angular2 to get the token and I'm getting the following issue:

OPTIONS http://192.168.56.1:82/magento/index.php/rest/V1/integration/admin/token 400 (Bad Request)

XMLHttpRequest cannot load http://192.168.56.1:82/magento/index.php/rest/V1/integration/admin/token. Response for preflight has invalid HTTP status code 400

EXCEPTION: Response with status: 0  for URL: null

==================================================================================

Angular 2 side:

let headers = new Headers({'Content-type': 'application/json'});

 headers.append('Access-Control-Allow-Origin', '*');

 headers.append('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,PUT,DELETE');

 headers.append('Access-Control-Allow-Headers', 'Origin,Authorization,X-Auth-Token,Accept,Content-Type');

 headers.append('Access-Control-Allow-Credentials', 'true');

 let options = new RequestOptions({ headers: headers });

return this.http.post( 'http://192.168.56.1:82/magento/index.php/rest/V1/integration/admin/token',

                      JSON.stringify('{"username":"angUser", "password":"angUser2017"}'),

                      options)

                      .map(res => res.json());

 =================================

Magento2

angUser / angUser2017

Consumer Key:                                                 5bhvi7gjvyafcp35rajuxh0y4me2plga

Consumer secret:                            yh1nefyw1u80rd0ip1q6f8pijv9x72f1

Access Token:                                   g5plfwth2rhlwtuwfhhqp7mg6sebrxc3

Access Token Secret:                     i1f4t7j65oo8ydtnteub9xr7wrswe99c

 

Magento headers:

1.       Request URL:

http://192.168.56.1:82/magento/index.php/?SID=ffego0i8jdeb0co3tt0perqta1

2.       Request Method:

GET

3.       Status Code:

200 OK

4.       Remote Address:

192.168.56.1:82


2.       Response Headers

1.       Access-Control-Allow-Credentials:

True

2.       Access-Control-Allow-Headers:

Origin, Content-Type, Accept, Authorization

3.       Access-Control-Allow-Methods:

GET,POST,OPTIONS,PUT,DELETE

4.       Access-Control-Allow-Origin:

*

Sachin S

unread,
Sep 12, 2017, 2:40:09 AM9/12/17
to Angular and AngularJS discussion
Hi,

May be a run through my blog may help you with the issue:

Sander Elias

unread,
Sep 12, 2017, 5:04:54 AM9/12/17
to Angular and AngularJS discussion
Hi Belyamani,

This is not an Angular issue, but an issue with your server. you need to configure your server so it apply's CORS correctly.

Perhaps Sachin's blogs might help you too.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages