Hi! I’m trying to send a POST from my Angular app to the Digital Ocean API, using the following endpoint:

https://cloud.digitalocean.com/v1/oauth/token?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&code=MY_CODE’&grant_type=authorization_code&redirect_uri=MY_APP_URL

On Chrome delevoper tools I can see an OPTIONS request is sent first, and returned with 404, so the POST is never sent.
When I try the same endpoint on https://apitester.com/, I get the response successfully.

Any idea? Thanks!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

If your network request is failed. due to the CORS issue, then you should use node module CORS and configure the CORS object on the server.

The way CORS works is that if it gets the request from an unknown host or domain, then it will give you an error saying that cross-site origin request: access denied.

Which means that you are unknown to the server or, in this case, malicious actor.

It is the security feature of browsers.

If you are working with Authentication in Angular 10 app, then you have to send a post request to the server, and then if all the data is valid, it will store the user credentials to the database.

When a user tries to login for the first time, the server will return a jwt token, and that token will be saved on the clientside.

Every time the user to try to access the server resource, it will check for the token, and if it finds, it sends the proper response; otherwise, it will throw the error.

In your case, maybe DigitalOcean API can not verify the token, or you have not configured the CORS object on the backend language.

Configure the CORS object and whitelist your domain and try again.

I hope this helps,

Best Regards,

edited by bobbyiliev
Submit an Answer