fhqvst / avanza

A JavaScript client for the unofficial Avanza API
MIT License
229 stars 59 forks source link

Authenticate: Bad request with 'ö' in username #43

Closed davidsoederberg closed 3 years ago

davidsoederberg commented 4 years ago

The authenticate function returns bad request if you have 'ö' in your username. I changed username to one without 'ö' and then it worked fine.

I do not know if this can be fixed, but atleast we could add a warning if someone tries to authenticate with 'å', 'ä' or 'ö' in their username.

davidsoederberg commented 4 years ago

I did some investigation and found out that it must be something wrong with the request function in index.js. I am not an expert in encoding, but I edited to this in the header 'Content-Type': 'application/json;charset=utf-8', and it still did not work.

I then tried with axios instead of https.request (changed from request to axios on line 405 in index.js) and then it worked fine with 'ö'.

Does someone have a solution for this problem with https.request or should we switch to axios on line 405 so you can have special chars in your username? (There might be other places where the nordic special letters gives us problem though)

stoffeastrom commented 4 years ago

My guess is that you get the wrong Content-Length e.g change https://github.com/fhqvst/avanza/blob/master/lib/index.js#L53 to 'Content-Length': Buffer.byteLength(data)

davidsoederberg commented 4 years ago

@stoffeastrom It works fine with having usernames with nordic letters after your simple change. I made a pull request #44, might need some more testing .

fhqvst commented 3 years ago

44 now merged, thanks!