LightningWeb.API.CredentialController (Lightning v2.15.0-pre5)
View SourceAPI controller for credential management.
Handles creation, retrieval, and deletion of credentials. Credentials are used to authenticate with external services and can be associated with multiple projects.
Security
- Credential bodies are excluded from responses for security
- Users can only delete credentials they own
- Project access is required to view project credentials
Examples
GET /api/credentials
GET /api/credentials?project_id=a1b2c3d4-...
POST /api/credentials
DELETE /api/credentials/a1b2c3d4-...
Summary
Functions
Creates a new credential and optionally grants it access to projects.
Deletes a credential owned by the authenticated user.
Lists credentials with optional project filtering.
Functions
@spec create(Plug.Conn.t(), map()) :: Plug.Conn.t()
Creates a new credential and optionally grants it access to projects.
Creates a credential owned by the authenticated user. If project_credentials are specified, the user must have access to all listed projects. The credential body is included in the response only upon creation.
Parameters
conn- The Plug connection struct with the current resource assignedparams- Map containing:name- Credential name (required)body- Credential JSON body with authentication details (required)project_credentials- List of project associations (optional)
Returns
201 Createdwith credential JSON including body422 Unprocessable Entityon validation errors403 Forbiddenif user lacks access to specified projects
Examples
# Create credential without project association
POST /api/credentials
{
"name": "My API Key",
"body": {"apiKey": "secret123"}
}
# Create credential with project associations
POST /api/credentials
{
"name": "Shared Credential",
"body": {"token": "abc123"},
"project_credentials": [
{"project_id": "a1b2c3d4-..."}
]
}
@spec delete(Plug.Conn.t(), map()) :: Plug.Conn.t()
Deletes a credential owned by the authenticated user.
Permanently removes a credential. Only the credential owner can delete it. Credentials in use by workflows cannot be deleted and will return an error.
Parameters
conn- The Plug connection struct with the current resource assignedparams- Map containing:id- Credential UUID (required)
Returns
204 No Contenton successful deletion404 Not Foundif credential doesn't exist or invalid UUID403 Forbiddenif user is not the credential owner
Examples
DELETE /api/credentials/a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d
@spec index(Plug.Conn.t(), map()) :: Plug.Conn.t()
Lists credentials with optional project filtering.
This function has two variants:
- With
project_id: Returns all credentials for a specific project (regardless of owner) - Without
project_id: Returns only credentials owned by the authenticated user
Credential bodies are excluded from responses for security.
Parameters
conn- The Plug connection struct with the current resource assignedparams- Map containing:project_id- Project UUID (optional, filters to specific project)
Returns
200 OKwith list of credentials (bodies excluded)404 Not Foundif project doesn't exist (when project_id provided)403 Forbiddenif user lacks project access (when project_id provided)
Examples
# User's own credentials
GET /api/credentials
# All credentials for a project
GET /api/credentials?project_id=a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d