CORS Error when GET access_token by authorization_code

Created at 07 Jun 2020, 18:06
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
UR

uri.fung

Joined 06.05.2020

CORS Error when GET access_token by authorization_code
07 Jun 2020, 18:06


Dear all,

I would like to get access_token via OAuth 2.0 by "GET" method from my service but server reject with CORS error. The request URL is correct as docs https://connect.spotware.com/docs/open_api_2/getting_started_v2/open_authentication_v2 with authorization_code.

Bellow is my details:

GET Request:

      const headers = {
        "Content-Type": "application/json"
      };
      const host = "localhost:8080";
      const redirect_uri = "".concat("http://", host, "/accounts");
      const url = "".concat(
        "https://connect.spotware.com/apps/token?grant_type=authorization_code&code=",
        code,
        "&redirect_uri=",
        redirect_uri,
        "&client_id=",
        process.env.VUE_APP_CTRADER_CLIENT_ID,
        "&client_secret=",
        process.env.VUE_APP_CTRADER_CLIENT_SECRET
      );

      this.axios
        .get(url, { headers: headers })
        .then(response => console.log(response))
        .catch(e => {
          console.log("Error: ", e.response.data);
        });

 

Server Responsed:

.... from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

How can I get access_token or claim my domain?

Regards,


@uri.fung
Replies

PanagiotisCharalampous
09 Jun 2020, 09:43

Hi uri.fung,

Check this thread in case it is helpful.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous