For a quick way to get started before implementing custom auth, Development Tokens can be used instead.
- The client authenticates the user using the app’s authentication provider and typically gets a session token — either a third-party authentication provider or a custom one.
- The client makes a backend call (authenticated using the above session token), which generates and signs a JWT for PowerSync.
- For example implementations of this backend endpoint, see Custom Backend Examples
- The client connects to the PowerSync Service using the above JWT.
- PowerSync verifies the JWT.
- The URL must be a public URL in the JWKS format.
- We have an example endpoint available here; ensure that your response looks similar.
- Supported signature schemes: RSA, EdDSA and ECDSA.
- Key type (
kty):RSA,OKP(EdDSA) orEC(ECDSA). - Algorithm (
alg):RS256,RS384orRS512for RSAEdDSAfor EdDSAES256,ES384orES512for ECDSA
- Curve (
crv) - only relevant for EdDSA and ECDSA:Ed25519orEd448for EdDSAP-256,P-384orP-512for ECDSA
- A
kidmust be specified and must match thekidin the JWT.
- The JWT must be signed using a key in the JWKS URL.
- JWT must have a
kidmatching the key in the JWKS URL. - The
audof the JWT must match the PowerSync instance URL.- To get the instance URL of a PowerSync instance when using PowerSync Cloud: In the project tree on the PowerSync dashboard, click on the “Copy instance URL” icon.
- Alternatively, specify a custom audience in the instance settings.
- The JWT must expire in 60 minutes or less. Specifically, both
iatandexpfields must be present, with a difference of 3600 or less between them. - The user ID must be used as the
subof the JWT. - Additional fields can be added which can be referenced in Sync Rules parameter queries.
Rotating Keys
If a private key is compromised, rotate the key on the JWKS endpoint. PowerSync refreshes the keys from the endpoint every couple of minutes, after which old tokens will not be accepted anymore. There is a possibility of false authentication errors until PowerSync refreshes the keys. These errors are typically retried by the client and will have little impact. However, to periodically rotate keys without any authentication failures, follow this process:- Add a new key to the JWKS endpoint.
- Wait an hour (or more) to make sure PowerSync has the new key.
- Start signing new JWT tokens using the new key.
- Wait until all existing tokens have expired.
- Remove the old key from the JWKS endpoint.