Search code examples
blockchaintronweb

Tronweb authentication


I want to build a webapp that uses the wallet address as account, but yet I want to store the user in my db to allow specifying a nickname.
The problem I'm dealing with is that I want to call different apis, where the user needs to be authenticated / authorized in order to gain access .

Since the authentication happens 100% client side in my case (through the tronlink extension and TronWeb), I don't see another way as to add supplementary authentication for my webapp specifically.
If the user logs in to my app with a different password (not using the private key of the wallet), it seems like bad user experience as the user needs to authenticate twice (through Tronweb AND my webapp with a password).

How do you solve this problem?


Solution

  • It seems that the way to handle this is to foresee a separate login flow for the web app after all. Even when the user already has logged in into Tronlink, it needs to obtain a token to authenticate rest calls.

    The way it would appear to work is by generating a random nonce and storing this nonce along with the public key in the User table. The login flow then consists of signing the nonce in the front-end, and verifying the signature in the backend after which the token will be generated and returned.