Authentication for my API on separate domain

I am trying to create an API that I can leverage for multiple client applications (web, mobile, etc..) I am hosting the API on Heroku, so the API address will be something like

I want to serve all requests through this, but I also want to have a separate web client to interact with it, say,

Right now, I have authentication over HTTPS using cookies working well on the API's domain, but how do I authenticate requests from the web client ( to the API ( since it is on a separate domain?


If you use cookie based authentication in you can change the scope of the cookie to be this way CORS requests with withCredentials from will send the cookie.

One problem I see though, is that is not YOURS. Someone else could create an application in heroku, redirect your users there and stole the cookie. Then they will be able to call your api with the stolen cookie. So, I will strongly recommend you to buy a domain, otherwise do not use this approach.

Another approach that works very well for this case is to use JSON Web Tokens check Cookies vs Tokens.

Need Your Help

CodeIgniter not sending email in localhost

php forms codeigniter email

I'm trying to send an email from the contact form of my website.

iPhone Development - Making sure we have a fresh location

iphone timestamp cllocation

How does this condition work? I'm unable to comprehend this.