This doesn't work by default because you would be making the API request from your endpoint to the Identity Management endpoint /id/api/v1/publisher/login. This login mechanism does not directly affect the user's frontend.
However, you can set up a __utp cookie with our token which you got from the Public API before. Afterward, the Identity Management JavaScript functions will work.