-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
The current auth flow is as follows:
- DID signs a consent message to unlock a
contextusing the private key for the DID (this happens in the Vault). - 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.
- 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:
- As a
Verida VaultI can sign a consent message using my private key to obtain arefresh tokenandaccess tokento gain access to a storage node server for a givenapplication context. - As a
Verida VaultI can store therefresh token, linked to a givenapplication contextandVerida dAppso that I can track all the applications I have logged into - As a
Verida dAppI can send a message to theVerida Vaultand receive arefresh tokenandaccess tokenso that I can gain access to a storage node server for a givenapplication context - As a
Verida dAppI can use theaccess tokento make requests to the storage node server so that I can manage databases - As a
Verida dAppI can use theaccess tokento make requests directly to CouchDB so that I can read / write database data - As a
Verida dAppI can use therefresh tokento obtain a new access token if it expires so that the user isn't logged out of the application - As a
Verida dAppI can use therefresh tokento obtain a new refresh token if it is getting close to expire so that the user isn't logged out of the application - As a
Verida VaultI can revoke arefresh token, linked to a givenapplication contextandVerida dAppso that I can revoke database access to an application
The proposed new flow is as follows:
- DID signs a consent message to unlock a
contextusing the private key for the DID (this happens in the Vault). - The Vault sends the signed consent message to the storage node, which generates a storage node
refresh tokenandaccess tokenvia a newauthenticate()endpoint - The
refresh tokenexpires after (30?) days - The Vault stores the refresh token in a
app_connectionsdatabase, linked to theapplication contextanddomain namethat made the SSO request - The Vault returns both tokens to the web browser.
- The web browser can use the
access tokenmake requests to the storage node or the couchdb server - The web browser can use the
refresh tokento obtain a newaccess token/refresh tokenfrom the storage node server, if theaccess token/refresh tokenexpires - The Vault can revoke a
refresh tokengranted to anyVerida dAppat 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:
generateAuthJwt(did:string, contextName: string)-- Begin the auth flow. Storage node generates a JWT containing a unique string that must be signed by the DID to complete authentication. Expires after 60 seconds.authenticate(authJwt: string, did: string, contextName: string, signature: string, deviceId: string)-- Authenticate access to the storage node and couchdb server. Verifies a signature is signed for a given contextName and contains the unique string from a valid JWT. Returns a newrefresh tokenandaccess token. Stores therefresh tokenon the server.get(contextName: string, refreshToken: string)-- Update the existingget()method to accept a refresh token and return an access token with the database hostname.invalidateDeviceId(deviceId: string)-- Invalidates all refresh tokens that have been generated for a givendeviceId. This allows the Vault to sign out a particular device.regenerateRefreshToken(refreshToken: string, contextName: string)-- Invalidates an existing refresh token and generates a new one. This enables an application to update the refresh token with a more recent expiry.request validatormiddleware must be updated to validate all requests against a suppliedaccess token.- Garbage collection of expired refresh tokens
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request