Generating a Shared Secret
You can generate a shared secret in the terminal using the following command:Set the shared secret in the PowerSync instance Client Auth configuration
Base64url Encode the Shared Secret
Once you’ve generated the shared secret, you’ll need to base64url encode it before setting it in the PowerSync instance Client Auth configuration. You can use the following command to base64url encode the shared secret:PowerSync Cloud Dashboard
- Go to the PowerSync Cloud Dashboard and select your project and instance.
- Go to the Client Auth view.
- Find the section labeled HS256 Authentication Tokens (ADVANCED) and click + button to add a new token.
- Set the KID to a unique identifier for the token (You’ll use the same KID to sign the token). Set the Shared Secret to the base64url encoded shared secret.
- Click Save and Deploy.
PowerSync Self-Hosted Setup
- Add the shared secret to your PowerSync Service configuration file, e.g.:
powersync.yaml
- Restart the PowerSync Service.
Generate a new JWT token using the KID and shared secret
Using your newly created shared secret, you can generate JWT tokens using the same KID you set in the PowerSync Service configuration. Here’s a function using thejose library:
fetchCredentials() function and should retrieve the token from your custom authentication service.