Authentication
Learn how to authenticate with the SAVA BaaS API.
New Authentication Model
The new authentication model ensures that private keys are maintained by the end-user. The overall process of creating and exchanging credentials is as follows:
- End user generates a nkey pair (seed and public key)
- End user shares the public portion of the keypair
- SAVA generates a jwt which will be required for connecting to the nats server
- End user creates a creds files combining the seed and jwt used to connecting
- End user uses the creds file to connect to the nats server
Installing NSC
NSC can be installed using the following command:
NB: python can be replaced with python3 if required depending on your system configuration
nsc must be added to your $PATH env for the following commands to work. The above command will output the instructions.
Here is an example to add to using bash:
NB: Note that /root in the above example will be replaced with the current user's home directory
Generate an NKey Pair
Generate an Nkey pair using the following command:
This will generate a Nkey pair consisting of a seed token and a public key as follows:
The line starting with SU denotes that it is a seed token for a user. Keep this token for future use. Losing this will render the jwt useless
Share the public key with SAVA, who will generate and return a jwt which will complete the credentials.
Creating a creds file for connecting
Once the JWT is returned from SAVA, a creds file must be created in order to connect to the server. This is a simple text file, usually denoted with a .creds extension. The format of the file is as follows:
Replace the contents between -----BEGIN NATS USER JWT----- and ------END NATS USER JWT------ with the provided JWT
Additionally replace the contents between -----BEGIN USER NKEY SEED----- and ------END USER NKEY SEED------.
NB: note that this file format is very specific and the spacing should not be adjusted. To minimize the errors we suggest copying this template below and replacing the annotated sections.
Creds template
Connecting
Connecting to the server remains the same as stated in the documentation.
Authenticating Requests
Once connected, every service request must also carry your JWT as a token header on the NATS message. See Using the JWT in API Essentials for the details and an example.