2

When I do a request from curl it works, but when I try to do the same thing from AngularJS it returns:

XMLHttpRequest cannot load https://www.example.com/oauth/token Response for preflight is invalid (redirect)

This is the curl query:

curl -v https://www.example.com/oauth/token -d "client_id=1&client_secret=1&code=1"

This is my AngularJS code:

                 $http({
                        method: "post",
                        url: "https://www.example.com/oauth/token",
                        data: "client_id=" + clientID + "&client_secret=" + clientSecret + "&code=" + requestToken,
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded',
                            'Access-Control-Allow-Origin': '*'
                        }
                    })
                    .success(function (data) {
                        console.log(data);
                        //  deferred.resolve(data);
                    })
                    .error(function (data, status) {
                        console.log(data);
                        //deferred.reject("Problem authenticating");
                    })
                    .finally(function () {
                        //                  setTimeout(function () {
                        //                      browserRef.close();
                        //                  }, 10);
                    });

What can be the problem?

Also, I tried all the solution from the possible duplicate page, and they didn't work.

I tried to do the request on a local nodejs webserver and it returns the result. From the client I make the request to the nodejs webserver, and I have the same issue, even though the request is on http.

Andrei
  • 7,509
  • 7
  • 32
  • 63
  • Did you read the error message, it's pretty clear. For whatever reason, the preflight is getting a redirect response. – CollinD Jul 23 '16 at 21:00
  • 2
    Possible duplicate of [Why my $.ajax showing "preflight is invalid redirect error"?](http://stackoverflow.com/questions/33645511/why-my-ajax-showing-preflight-is-invalid-redirect-error) – CollinD Jul 23 '16 at 21:00
  • If you don't control the remote domain you will need to use a proxy on your server or third party service. Secret keys should be kept secret anyway – charlietfl Jul 23 '16 at 21:02
  • I understand this, but can you please elaborate on how to approach this issue in my case? – Andrei Jul 23 '16 at 21:08
  • curl is command line, so you are not sending your request against a registered domain. If you did register your domain with the provider, you need to make your request on the domain.. – Dave Alperovich Jul 23 '16 at 21:32
  • I did register the domain with the provider – Andrei Jul 23 '16 at 21:37
  • but your curl request is coming from curl. that's not a domain request, it's a command line request with no domain, and not a secure request. another problem is https cannot be queried by non-https client. Again, curl command line is not being sent from secure client. This must be done from your domain client in https – Dave Alperovich Jul 23 '16 at 21:37
  • I understand that, how can I do it in angularjs – Andrei Jul 23 '16 at 21:38
  • make the same request with http call. make sure your client is in SSL – Dave Alperovich Jul 23 '16 at 21:43
  • Right, can you please point me on how to do that from my angularjs client – Andrei Jul 23 '16 at 21:48

0 Answers0