locked
problems in getting access tokens RRS feed

  • Question

  • Hello,

    After some research I discovered that the appid access to translator services is no longer supported
    and we need to get azure access token in order to access the translator service. However, it seems that there are some issues while getting the access token from an ajax call (it always ends up with a 'parsererror' message), also, there is no documentation available about how to get the access token from a pure javascript call. I solicit your help in
    this issue, find the details below.

     
    I'm trying to get an access token first, using this method
     
    /***********************************************************************************************************/
    $.ajax(
    {
    type: 'POST',
    crossDomain: true,
    url:
    'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13',
    dataType: 'jsonp',
    contentType: 'application/x-www-form-urlencoded',
    jsonp: 'oncomplete',
    jsonpCallback: 'ajaxTranslateCallback',
    data: {
    'grant_type': encodeURIComponent('client_credentials').toString(),
    'client_id': encodeURIComponent('ed8f22b0-8ff8-4f8b-9797-44c0465e1202').toString(),
    'client_secret':
    encodeURIComponent('dnRdPYUr9841UL/1hKI7CumIjEB9toe8ELxYdRGx36s=').toString(),
    'scope': encodeURIComponent('http://api.microsofttranslator.com')
    },
    complete: function (request, status)
    {
    debugger;
    alert('complete: ' +
    status);
    },
    success: function (data, textStatus)
    {
    debugger;
    alert(data);
    },
    error: function (request, a, b)
    {
    debugger;
    }
     
    }
    );
     
    function ajaxTranslateCallback(response) {
    alert('ajaxTranslateCallback(' +
    response + ')');
    }
     

    Some
    sites , suggest that the recommended way is to host a server code to get the
    access token, this is not possible in my case as i'm going to host
    a javascript page in an MS-CRM 2011 application. is it not possible to make a
    POST call from anywhere (using only javascript) to get the access token , or
    there is some bug in my code.

    ANOTHER BIGGER PROBLEM :

    I copied the sample console application programme to generate the auth code, and provided my clientid,clientsecret parameters, it failed with this message. 

    "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel"

    PLZ
    HELP..
    Saturday, November 10, 2012 10:33 AM

All replies

  • It's definitely worth trying to find a way to do it server-side, because otherwise your Client ID and Client Secret are provided in-the-clear for anyone to steal and eat your quota. For that reason alone, we don't support JS-only calls.

    While I've never tried it directly in JS, but looking at your code, I see a couple of potential gotchas:

    1. What does encodeURIComponent do? Have you checked to see if it is encoding things correctly?

    2. I notice that you post the contents using JSON. I am not sure if that will work. My recommendation would be to first implement the code in something like ASP.NET (there's an example here: http://blogs.msdn.com/b/translation/p/gettingstarted2.aspx) and take a look at the HTTP headers it generates. Then, use JavaScript to generate headers in the same structure, and try them....

    Laurence 

    Monday, November 12, 2012 6:03 PM