2

I have been using working on an Applicaion in angularjs, and While getting response of 2nd request for the token, I am getting following an error.

Illegal Request You have sent us an Illegal URL or an improperly formatted request.

and it shows 400 Bad Request

My code is as below.

var url = 'https://login.salesforce.com/services/oauth2/token',
            params = {
                code:'dfdfsdsd',
                grant_type:'authorization_code',
                client_id:'23232',
                client_secret:'weewew',
                redirect_uri: redirectURL
            };
    $http({
        method: 'POST',
        url: url,
        data: params,
        transformRequest: function(data){
            var fd = new FormData();
            for ( i in data){
                if(data.hasOwnProperty(i))
                    fd.append(i, data[i]);
            }
            return fd;
        },
        headers: {'Content-Type': 'multipart/form-data','Accept': "*/*"}

My request payload is

------WebKitFormBoundarybowCNKs3dC85tBTV
Content-Disposition: form-data; name="code"

dfdfsdsd
------WebKitFormBoundarybowCNKs3dC85tBTV
Content-Disposition: form-data; name="grant_type"

authorizatidon_code
------WebKitFormBoundarybowCNKs3dC85tBTV
Content-Disposition: form-data; name="client_id"

2323zK
------WebKitFormBoundarybowCNKs3dC85tBTV
Content-Disposition: form-data; name="client_secret"

232
------WebKitFormBoundarybowCNKs3dC85tBTV
Content-Disposition: form-data; name="redirect_uri"

http://redirect url
------WebKitFormBoundarybowCNKs3dC85tBTV--

What should be the problem ?

Thanks ! :)

5
  • Your payload example has the "redirect_uri" set to http://redirect url which is not a valid URL. Are you sure you are sending a valid URL for the OAUTH logic to call back to?
    – Keith C
    Jul 12, 2014 at 14:35
  • I am sending redirect_uri: 'localhost/app/#/salesforce' Jul 12, 2014 at 18:17
  • 1
    I have only done OAUTH2 on the server-side so am not clear on what a purely client-side implementation looks like. But as localhost means "this computer", by passing that string you are not supplying the IP address of your client (that it looks like your are trying to do). I suggest you Google to find examples of a purely client-side approach and if you can't post a new question on what s the best starting point to do that.
    – Keith C
    Jul 13, 2014 at 11:33
  • Keith C..I tried with ip address. but, It does not work. When I tried to save redirect url in developer account of salesforce, It does not allow. I will do more googoe. Thanks for your reply. Jul 14, 2014 at 16:52
  • If you can't figure it out a good person to try to get in touch with on this is @metadaddy (salesforce.stackexchange.com/users/67/metadaddy).
    – Keith C
    Jul 14, 2014 at 17:03

1 Answer 1

1

I fixed this problem myself.

I required to decode my code

params = {
    code:decodeURIComponent(authCode),
    grant_type:'authorization_code',
    client_id:'23232',
    client_secret:'weewew',
    redirect_uri: redirectURL
};

It works fine for me.

Thanks ! :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .