Skip to content

Commit c76cbc2

Browse files
authored
Enhance Bifrost authentication documentation
Clarified details about the Bifrost authentication service, including token issuance and structure. Updated sections on session creation, token renewal, and security considerations.
1 parent 8eea089 commit c76cbc2

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

docs/developer/auth.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pagination_prev: null
55
---
66
# Bifrost Authentication Service
77

8-
Bifrost is an authentication service that enables secure communication between external applications and the Sourceful Energy App (SEA). It serves as a bridge that facilitates safe authentication without requiring users to install external wallets on multiple devices.
8+
Bifrost is an authentication service that enables secure communication between external applications and the Sourceful Energy App (SEA). It serves as a bridge that facilitates safe authentication without requiring users to install external wallets on multiple devices. Basically Bifrost allows exchange of a delegation token that gives the token owner permission to access some of the users resources.
99

1010
> **Security by Design**: Bifrost only handles public keys, never private keys. All private keys remain securely within either the SEA or the external application, ensuring that sensitive cryptographic material is never exposed to the bridge service.
1111
@@ -61,7 +61,7 @@ sequenceDiagram
6161
1. **Session Creation**: External application generates a private key and sends its public key and an attributes object to Bifrost
6262
2. **Session Validity**: Sessions are valid for a maximum of 3 minutes
6363
3. **User Approval**: During this time, the user must approve the session in SEA
64-
4. **Token Issuance**: Upon approval, a signed JWT is returned to the external application
64+
4. **Token Issuance**: Upon approval, a JWT signed by the user is returned to the external application
6565
5. **API Access**: The JWT can then be used for authentication with the Sourceful Energy API
6666

6767
## JWT Delegate Token Structure
@@ -88,20 +88,16 @@ JWT tokens issued by Bifrost follow this structure:
8888
```
8989

9090
Where:
91-
- **issuer**: The user's public key whose corresponding private key signs the JWT in SEA
92-
- **delegatedKey**: The public key of the external application whose generated private key can be used to sign messages
93-
- **attributes**: Additional attributes that describe the token, currently `name`, `nonce`, and `permissions` are supporte by the SEA and API Backend. Permissions are of particular interest and are documented in its own section, but basically describe what the token is allowed to do with defined resources. The `nonce` attribute is added by bifrost automatically.
91+
- **issuer**: The user's public key whose corresponding private key signs the JWT in SEA in base58 format
92+
- **delegatedKey**: The public key of the external application whose generated private key can be used to sign messages in base58 format
93+
- **attributes**: Additional attributes that describe the token, currently `name`, `nonce`, and `permissions` are supporte by the SEA and API Backend. Permissions are of particular interest and are documented in its own section, but basically describe what the token is allowed to do with defined resources. The `nonce` attribute is added by Bifrost automatically and must NOT be changed in the token exchange.
9494

9595
In an application it makes sense to show the issuer public key so the user understands what wallet is logged in, but at the same time make it clear that this is a delegatge token based authentication. It does not make sense to show the delegatedKey as this is only used internally in the application and JWT token. Also note that the expiration time can be changed, as of now the default time to live is 12h.
9696

9797
### Permissions
9898
TODO: Document the permissions here.
9999

100100

101-
### Future Enhancements
102-
103-
The JWT structure allows for extensibility. In future versions, additional fields can be added to the payload to provide fine-grained access rights, enabling more nuanced permission controls. The time to live can also be customized by either the protocl or the user in future versions.
104-
105101
## Security Considerations
106102

107103
```mermaid
@@ -133,6 +129,7 @@ To mitigate these risks, Bifrost implements:
133129
- External application's private key remains in the external application
134130
- User's private key remains in the SEA
135131
- Bifrost only handles public keys and signed tokens
132+
5. **No tokens Saved**: Bifrost does only save metadata regarding the delegate token, not the token itself. It is the responsibility of the external application to maintain its delegate token and private key.
136133

137134
## API Endpoints
138135

@@ -146,6 +143,7 @@ Creates a new authentication session for key exchange between an external applic
146143
```json
147144
{
148145
"delegatedKey": "5LubpwhZzwkKW49a2b5GwfFJdep1xtMDsuVeMGeBvJfx"
146+
"attributes": {...}
149147
}
150148
```
151149
- **Response**:
@@ -223,12 +221,15 @@ The full OpenAPI documentation is available at:
223221
https://bifrost.srcful.dev/docs
224222
```
225223

224+
The Bifrost endpoints requires authentication in the form of a token. See the Bifrost documentation above for details.
225+
226226
## Token Renewal
227-
In general the delegate token is short lived and cannot be renewed without involving signing by the issuer wallet in general this involves a user interaction. This poses a problem for usability in some applications and problems when working with automations and integrations that are long lived.
227+
In general the delegate token is short lived and cannot be renewed without involving signing by the issuer wallet in this ofteninvolves a user interaction. This poses a problem for usability in some applications and issues when working with automations and integrations that are long lived.
228228

229229
A delegate token can be marked for renewal (has `renew`: true, in the attributes). In this case an application can ask bifrost for a renewal certificate. This certificate allows the client (as identified by the delegateKey) to create it's own delegateToken. This renew token has the following structure:
230230

231231
### JWT Renew Token Structure
232+
This is a token that is built by the client application and basically consists of a renew certificate token.
232233

233234
JWT renew tokens follow this structure:
234235

@@ -244,15 +245,14 @@ JWT renew tokens follow this structure:
244245
**Payload**:
245246
```json
246247
{
247-
"delegate": the original delegate token jwt (signed by the issuer)
248-
"cert": the renew cert token (signed by bifrost)
248+
"cert": "the renew cert token in base64 (signed by bifrost)"
249249
}
250250
```
251251

252252
Where:
253253
- **cert**: The certificate token signed by bifrost. Importantly it contains new created and expiration times as well as the nonce of the original delegate token and a bifrost key id.
254254

255-
Note the subtype (styp) in the header is set to renew.
255+
Note the subtype (`styp`) in the header is set to `renew`.
256256

257257
A client application will periodically ask Bifrost for a new certificate token and build its own renew token based on this. This can then be used in the backend API calls according to the permissions of the original token. If the original token is revoked by the user, bifrost will not issue a new certificate.
258258

@@ -273,7 +273,7 @@ Bifrost creates the renew certificate and signs it with its internal private key
273273
"iss": "7f3a9b2e",
274274
"created": "2025-04-28T08:50:41Z",
275275
"expiration": "2025-04-28T09:10:41Z",
276-
**dtoken**: The original delegate token signed by the issuer
276+
"dtoken": "The original delegate token signed by the issuer in base64"
277277
"nonce": "b88b45e1-fc5a-4cb1-b689-0d8f7f4cba04"
278278
}
279279
```

0 commit comments

Comments
 (0)