Javascript - Backendless.UserService.loginWithGooglePlusSdk Access-Control-Allow-Origin

I am getting the following error using backendless v3 with Chrome (not tested with other browser).

login.html:1 XMLHttpRequest cannot load https://api.backendless.com/v1/users/social/googleplus/login/84CE58E3-4799-2AAC-FF97-B489BAF23F00. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://foo.azurewebsites.net’ is therefore not allowed access. The response had HTTP status code 404.
login.html:158 Uncaught ReferenceError: createPopup is not defined
at gotError (login.html:158)
at Async.fault (backendless.js:631)
at backendless.js:1969
at Async.fault (backendless.js:631)
at XMLHttpRequest. (backendless.js:197)

Hey Barry,

The problem is with the https://foo.azurewebsites.net domain, I believe: it should return a proper Access-Control-Allow-Origin header since this is a cross-domain request.
You can read more on it here and here.

I agree but I think it is the api.backendless.com web server that is not returning the proper Access-Control-Allow-Origin header since this is a cross-domain request. Javascript is all client side.

If you provide me with a working example, I will test it using my server using custom domain.

Are you trying to login on a Standalone or Online version of Backendless?
Also, how did you manage to write the login code (it seems that there’s no documentation)?

I am trying to login using online v3 . Getting the code to work was a weekend of trial and error. 











<script src="[url=https://apis.google.com/js/api.js]https://apis.google.com/js/api.js"></script>[/url];
gapi.load('client:auth2', initClient);
    function initClient() {
    gapi.client.init({
    apiKey: 'apiKey',
    discoveryDocs: ["[url=https://people.googleapis.com/$discovery/rest?version=v1]https://people.googleapis.com/$discovery/rest?version=v1"[/url];],
    clientId: 'XYZ.apps.googleusercontent.com',
    scope: 'profile'
    })
    }
$('#gplus_login').on('click', function () {

var fieldsMapping = {
"email": "email",
"given_name": "firstname",
"family_name": "lastname",
"client_id": "XYZ.apps.googleusercontent.com"
}
var stayLoggedIn = true;


Backendless.UserService.loginWithGooglePlusSdk(fieldsMapping, stayLoggedIn, new Backendless.Async(userLoggedInStatus, gotError));
});

backendless.js file

loginWithGooglePlusSdk: function (fieldsMapping, stayLoggedIn, async) {
 if (!gapi) {
 throw new Error("Google Plus SDK not found");
 }
 if (stayLoggedIn instanceof Async) {
 async = stayLoggedIn;
 stayLoggedIn = false;
 }
 var me = this;
 gapi.auth.authorize({
 client_id: fieldsMapping.client_id,
 scope: "[url=https://www.googleapis.com/auth/plus.login]https://www.googleapis.com/auth/plus.login"[/url];
 }, function (response) {
 delete response['g-oauth-window'];
 me._sendSocialLoginRequest(me, response, "googleplus", fieldsMapping, stayLoggedIn, async);
 });
 },