This project is an example showing how your application can connect a user to their Verida Vault and grant your application access to user data and other AI related APIs.
Install dependencies and start server:
yarn
yarn start
Once the server is started, it should open http://localhost:8080/
in your web browser.
You can then select the scopes you wish to access and click the Connect Verida
button to be redirected to grant consent to your local application. Once you consent, an auth token is returned to your application and an example API request is made.
The connection flow is as follows:
- Generate an authentication request URL that includes the requested
scopes
andredirectUrl
(your application page that handles a successful authentication request) - Redirect the user to the authentication request URL
- If the user grants access, they are returned to your application with
auth_roken
in the query parameters - Save the
auth_token
in the local browser or your own database against the user account - Make API requests to the Verida API's setting the
Authorization
header toBearer ${authToken}
See the buildConnectUrl() for an example of building a connect URL that has an array of requested scopes
and a redirectUrl
that returns to your application once the auth token is generated.
See main.ts for an example of making an API request with the returned API key:
$.get({
url: `${API_ENDPOINT}/search/universal?keywords=meeting+agenda`,
headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json"
},
success: (response) => {
console.log(response)
// ...
}
})
It's possible to obtain a list of scopes from the /auth/scopes
endpoint:
$.get({
url: `${API_ENDPOINT}/auth/scopes`,
success: (response) => {
console.log(response)
// ...
}
})