-1

i have implemented AngularJS application that is using https://developers.google.com/+/web/signin/server-side-flow

The problem is that my AngularJS is on one server and Rest Api is at the other server. When I tried to login everything goes ok until my callback function calls rest api.

This is the error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://liveboard-dev.locastic.com/api/v1/login. This can be fixed by moving the resource to the same domain or enabling CORS.

There is no problem with server as I can call this method from any part of code except when i am sending auth response directly from google which I got after popup window is closed.

My angularjs code for calling api is:

        $http.post(applicationSettings.authenticationAPIUrl, authResult['code'], {headers: {'Content-Type': 'application/octet-stream; charset=utf-8'}}).success(function (response) {

        identityService.setIdentity(response);
        deferred.resolve(response);

    }).error(function (error) {

        deferred.reject(error);
    });
Antonio Peric
  • 246
  • 1
  • 2
  • 13

1 Answers1

1

Enabling CORS in Angular side

var myApp = angular.module('myApp', [
    'myAppApiService']);

myApp.config(['$httpProvider', function($httpProvider) {
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];
    }
]);
Narek Mamikonyan
  • 4,601
  • 2
  • 24
  • 30