verida / storage-node

ISC License
3 stars 5 forks source link

Support refresh tokens #18

Open tahpot opened 2 years ago

tahpot commented 2 years ago

The current auth flow is as follows:

  1. DID signs a consent message to unlock a context using the private key for the DID (this happens in the Vault).
  2. The signed consent message is sent to the storage node to perform all CRUD operations to manage their databases. This consent message is the "key" to unlock all database operation and never expires. This key is sent back to the web browser by the Vault, giving the web browser never-ending access. This needs to be fixed.
  3. The signed consent message is sent to the storage node to obtain a CouchDB auth token (with a fixed expiry) that is used to actually read / write from the DID's databases.

The key issue is at step (2).

We require the following capabilities:

The proposed new flow is as follows:

  1. DID signs a consent message to unlock a context using the private key for the DID (this happens in the Vault).
  2. The Vault sends the signed consent message to the storage node, which generates a storage node refresh token and access token via a new authenticate() endpoint
  3. The refresh token expires after (30?) days
  4. The Vault stores the refresh token in a app_connections database, linked to the application context and domain name that made the SSO request
  5. The Vault returns both tokens to the web browser.
  6. The web browser can use the access token make requests to the storage node or the couchdb server
  7. The web browser can use the refresh token to obtain a new access token / refresh token from the storage node server, if the access token / refresh token expires
  8. The Vault can revoke a refresh token granted to any Verida dApp at any time

Note: access tokens can't be revoked in couchdb, so we don't support revoking them at all. Instead they are short lived (5 minutes).

This requires the following updates to storage node:

tahpot commented 2 years ago

The following endpoints are implemented with working unit tests:

The request validator has been updated.

Endpoints remaining:

Other remaining:

tahpot commented 2 years ago

Other changes also made that require client-ts updates:

tahpot commented 2 years ago
tahpot commented 2 years ago