Auth0
This tutorial describes how to configure Auth0 as an identity provider (IdP). Using this Auth0 configuration your application users can query your Fauna database. This example discusses the minimum configuration steps required to accept a JWT from Auth0 to execute a query.
Successful acceptance of a JWT for authentication requires that your Fauna database configuration and the Auth0 configuration agree on the following details:
-
The
audienceURL. Auth0 needs this field to create JWTs that Fauna can accept. When you create an AccessProvider document, Fauna creates a uniqueaudienceURL for your database. -
The
issuerURL. This tells Fauna which IdP is permitted to send a JWT that should authorize a query to be executed.Use an exact copy of your IdP
issuerURL, including a trailing slash if it exists. URL differences could prevent acceptance of your IdP JWT tokens. -
The
jwks_uriURL. This is URL for the JSON Web Key Set endpoint. This endpoint serves the IdP-managed public key. Services such as Fauna can use the endpoint to verify or decrypt a JWT and confirm its validity. By convention, this URL is theissuerURL with.well-known/jwks.jsonappended.
Prerequisites
The following is a list of preparatory steps. Do a step only if you haven’t already done so:
-
Sign up for a Fauna account.
-
Create a database.
-
Sign up for an Auth0 account.
-
Create a
Roleto define the access privileges to apply to authenticated Auth0 users.
In the case of an IdP, users are stored in the IdP rather than Fauna. As a
result, Fauna only applies the role privileges and ignores any membership
it may also have.
Step 1 - Start Fauna configuration
This section configures an Access Provider in your Fauna database. An AccessProvider document allows you to define one or more roles to apply, to grant externally authenticated users access.
Do these steps in a new browser tab:
-
Log in to the Fauna Preview Dashboard.
-
Choose the database that should accept authenticated users from Auth0.
-
Choose the Access Providers menu item in the lower panel and click the CREATE ACCESS PROVIDER button to create an access provider or + icon to add an access provider.
-
In the Audience field, click the copy icon to copy the URL. Save the URL.
Don’t close this tab while configuring Auth0 in the next step. Fauna configuration continues in Step 3 - Complete Fauna configuration, creating the access provider.
Step 2 - Configure Auth0
This section shows how to configure an API in Auth0 using the Audience URL you saved in Step 1 - Start Fauna configuration.
Open a new browser tab for the following steps:
-
Log in to Auth0.
-
Choose APIs in the left navigation pane.
-
Click the + Create API button.
-
Enter a name for the API in the Name field to help you identify this API. The name should include a
Faunaprefix, such asFauna-my_app. -
Paste the saved Audience URL from Step 1 - Start Fauna configuration in the Identifier field.
-
Choose the RS256 Signing Algorithm.
-
Click the Create button.
-
Click the Test tab to display the Auth0 API Test page:
-
Find the
--urlvalue in the curl example and copy the URL, omitting theoauth/tokenpart of the URL. Save this URL making sure to include the trailing slash (/).This is the API URL used to populate the
issuerandjwks_urifields in Step 3 - Complete Fauna configuration.
Step 3 - Complete Fauna configuration
This section completes Fauna access provider configuration begun in Step 1 - Start Fauna configuration. An AccessProvider document allows you to define one or more roles to apply, to grant access to externally authenticated users.
-
Go to the Step 1 - Start Fauna configuration browser tab.
-
Enter a name in the Name field to help you identify this access provider. The preferred name is
Auth0. -
Enter the Auth0 API URL saved in Step 2 - Configure Auth0 in the Issuer field.
-
Enter the same Auth0 API URL in the JWKS endpoint field and append
.well-known/jwks.jsonto the URL. For example, the savedhttps://dev—nozpv3z.us.auth0.com/should be entered ashttps://dev—nozpv3z.us.auth0.com/.well-known/jwks.jsonin the JWKS endpoint field. -
Click the CREATE button.
The Auth0 access provider is added to the database
Access Providerslist. -
If you don’t have a role defined, use the shell to create a role to assign to the access provider similar to this create role example.
-
Use the shell to add the role to the access provider instance. In this example, the management team role is added to the
Auth0access provider:{ name: "Auth0", coll: AccessProvider, ts: Time("2023-09-18T21:13:06.645Z"), audience: "https://db.fauna.com/db/ywp9xrp6gyyre", roles: "mgmtTeam", jwks_uri: "https://dev—nozpv3z.us.auth0.com/.well-known/jwks.json ", issuer: "https://db.fauna.com/db/ywp9xrp6gyyre" }
Verify the configuration
Your Fauna database and your Auth0 API are configured to exchange authentication information using a JWT. To verify that the configuration works, follow these steps:
-
In the Auth0 Test browser tab, make sure that the
cURLtab is selected. -
Copy the
cURLcode example, which begins withcurl --request POST \. -
Open a terminal.
-
Paste the code sample in the terminal, and enter Return.
-
The output should be similar to:
{"access_token":"eyJhbGcIqiJSUzI1N5IsInR5cCi6IkpXVCIsImTpZCI6ilNCZTczWmFyOWpKU3h ueG44QlNTSqJ9eyJpc3MiOiJQdHRwczovL2R6di0tbm96cHYzei51cy5hdXRoMC5jb20vIiwic3ViIjo ibDZ2SlM4UXZIQzJMbWlHUmFPVGlFMTZnaXZ1dWZSMjJAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vZGI uZmF1bmEuY29tL2RiL3l4eGY1eDl3MXlieW4iLCJpYXQiOjE2MDU1MDI2NDgsImV4cCI6MTYwNTU4OTA 0OCwiYXpwIjoibDZ2SlM4UXZIQzJMbWlHUmFPVGlFMTZnaXZ1dWZSMjIiLCJndHkiOiJjbGllbnQtY3J lZG.udGlhbHMif6 pdnzxME8gaQkyxsWhurgVzQcakcnMRUJEGcb83f_lgd0tWaE-VcFcfb-SXLCFX3IcJkls9woQVcFM91 UCHRN_qSKjEzB1vOrFqQ73FSq33dLviGM_8E195R_zJVmCsb__ADhQCaWTYM-vO8ZSA7lC2WzVejLAg CJhOXwP7WGeG_FDfqVDM0InaJdVOoUwXF4SzZ00DVjJxSoKnsiRgwpPyaV3rGAQGVlijyYe1mea7D3g jHO2a-yUV-yT75xglTyjwC5WKHySXgu-iXq7x6N5JIRAcBh2-ka6sS5o61JHR35sFfXYpUiSiPj45XL nGhB7wbVwvq4mA3ur1bePg","expires_in":86400,"token_type":"Bearer"}
The value of the access_token field can be used in place of the secret
from a database token or key. This token identifies your user account in
Auth0.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!