Neon DB
Authenticate with NeonDB api using JSON Web Tokens
You can configure UseGrant as a auth provider in NeonDB and use the generated access token to authenticate with the NeonDB api.
Follow the steps below to configure UseGrant as a auth provider in NeonDB.
- Go to the NeonDB console and navigate to the "Settings" page.
- Click on the
Authorizetab. - Click on the
Setup authentication providerbutton. - Enter the jwk url of your UseGrant application. If you have a custom domain,
you can also use that domain instead of the default one.
- Example:
https://MY_PROJECT_URL_ID.usegrant.dev/.well-known/jwks
- Example:
- Add the audience of your UseGrant application.
- Example:
api.neon.techor whatever you set in theaudiencefield while creating the client.
- Example:
- Click on the
Savebutton.
Once you have completed the steps above, you should be able to authenticate with the NeonDB api using the generated access token.
Follow the NeonDB docs for more information on how to use the NeonDB api. A typical example would look like this:
import { neon } from '@neondatabase/serverless';
const ugClient = new UseGrant(process.env.USEGRANT_API_TOKEN);
const getToken = async () => {
const token = await ugClient.createToken('providerId', 'clientId');
return token;
};
const sql = neon(process.env.DATABASE_AUTHENTICATED_URL, {
authToken: async () => {
const token = await getToken();
return token;
},
});
await sql(`select * from todos`);