AnsweredAssumed Answered

How can I log in from another domain using Javascript?

Question asked by Tim Tim on Mar 28, 2014
Latest reply on May 21, 2014 by Harald Kuske
I have searched the whole internet and I can't find a working way to log in to SugarCRM with Javascript.  This is as close as I've gotten:

var params = { 
   user_auth:{  
      user_name:'jim',   
     password:'jim',   
     encryption:'PLAIN' 
   }, 
   application_name: 'SugarCRM RestAPI Example'
}
var restdata = JSON.stringify(params);

$.ajax({ 
   type: "POST", 
   url: "http://alzjgk0569.trial.sugarcrm.com/service/v4/rest.php?jsoncallback=?"
   data: {
      method: "login",
      input_type: "JSON",
      response_type: "JSON",
      rest_data: restData
   }, 
   dataType:"jsonp", 
   success: function(result) {alert("result: " + JSON.stringify(result));},
   failure: function() {alert("failed");}
});

Anyone have any ideas?

Thanks.

p.s. I should mention that the following works just fine:
<form action="https://alzjgk0569.trial.sugarcrm.com/rest/v10/oauth2/token" method="post">       
grant_type: <input type="text" name="grant_type" value="password"><br>
client_id: <input type="text" name="client_id" value="sugar"><br>
client_secret: <input type="text" name="client_secret" value=""><br>
username: <input type="text" name="username" value="jim"><br>
password: <input type="text" name="password" value="jim"><br>
platform: <input type="text" name="platform" value="base"><br>
<input type="submit" value="Submit">
</form>
--
Tim

Outcomes