Creates a new OAuth client instance
Initializes an OAuth client application with the provided configuration. The client manages authentication and authorization for accessing the Mosaia API securely.
Configuration data including: - name: Client application name - client_id: OAuth client ID - client_secret: OAuth client secret - redirect_uris: Authorized redirect URIs - scopes: Authorized scope list - grant_types: Supported OAuth grant types - metadata: Custom metadata object
Optionaluri: stringOptional custom URI path for the client endpoint
Web application client:
const webClient = new Client({
name: 'Web App',
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
redirect_uris: [
'https://app.example.com/oauth/callback',
'http://localhost:3000/callback' // Development
],
scopes: ['read:users', 'write:data']
});
Machine-to-machine client:
const serviceClient = new Client({
name: 'API Service',
client_id: process.env.SERVICE_CLIENT_ID,
client_secret: process.env.SERVICE_CLIENT_SECRET,
grant_types: ['client_credentials'],
scopes: ['service:full'],
metadata: {
type: 'service-account',
owner: 'system'
}
}, '/service/client');
Check if the entity is active
This method checks the active status of the entity. Most entities in the system can be active or inactive, which affects their availability and usability in the platform.
True if the entity is active, false otherwise
Convert model instance to interface data
This method serializes the model instance to a plain object that matches the interface type. This is useful for:
The model data as a plain object matching the interface type
Convert model instance to API payload
This method creates a payload suitable for API requests by:
A clean object suitable for API requests
Update model data with new values
This method updates the model's data and instance properties with new values. It performs a shallow merge of the updates with existing data, allowing for partial updates of the model's properties.
Object containing properties to update
const user = new User({
email: 'old@example.com',
firstName: 'John'
});
// Update multiple properties
user.update({
email: 'new@example.com',
lastName: 'Doe'
});
// Save changes to API
await user.save();
This method only updates the local model instance. To persist changes to the API, call save after updating.
Save the model instance to the API
This method persists the current state of the model to the API using a PUT request. It requires the model to have an ID (existing instance). For new instances, use the collection's create method instead.
The method:
Promise resolving to the updated model data
Delete the model instance from the API
This method permanently deletes the model instance from the API and clears the local data. This operation cannot be undone.
The method:
Promise that resolves when deletion is successful
Client class for managing OAuth client applications
This class represents an OAuth client application that can authenticate with the Mosaia API through various OAuth flows. It manages client credentials, redirect URIs, and scopes for secure API access.
Features:
Remarks
OAuth clients are essential for:
The class supports multiple OAuth 2.0 flows:
Example
Basic client setup:
Example
Service account setup: