### Install casdoor-nodejs-sdk Source: https://github.com/casdoor/casdoor-nodejs-sdk/blob/master/README.md Instructions for installing the casdoor-nodejs-sdk using NPM or Yarn package managers. ```shell # NPM npm i casdoor-nodejs-sdk # Yarn yarn add casdoor-nodejs-sdk ``` -------------------------------- ### Casdoor SDK User and Authentication Operations Source: https://github.com/casdoor/casdoor-nodejs-sdk/blob/master/README.md Provides examples of using the initialized Casdoor SDK to retrieve a list of users and obtain an authentication token. It also shows how to parse a JWT token to get user information. ```typescript // user const { data: users } = await sdk.getUsers() // auth const token = await sdk.getAuthToken('') const user = sdk.parseJwtToken(token) ``` -------------------------------- ### Manage Multi-Factor Authentication (MFA) with Casdoor Node.js SDK Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt This snippet demonstrates how to manage Multi-Factor Authentication (MFA) settings for users, including initiating setup, verifying codes, enabling MFA, setting preferred methods, and deleting MFA configurations using the Casdoor Node.js SDK. It requires SDK and MfaData types. ```typescript import { SDK, MfaData } from 'casdoor-nodejs-sdk'; const sdk = new SDK(config); // Initiate MFA setup const mfaData: MfaData = { owner: 'my-organization', name: 'alice_smith', mfaType: 'totp' }; const initResult = await sdk.initiateMfa(mfaData); console.log('MFA Secret:', initResult.data.secret); console.log('QR Code URL:', initResult.data.qrCodeUrl); // Verify MFA code during setup const passcode = '123456'; const verifyResult = await sdk.verifyMfa(mfaData, passcode); if (verifyResult.data.status === 'ok') { console.log('MFA code verified successfully'); // Enable MFA for user const enableResult = await sdk.enableMfa(mfaData); console.log('MFA enabled:', enableResult.data.status); } // Set preferred MFA method mfaData.mfaType = 'sms'; await sdk.setPreferredMfa(mfaData); // Delete MFA configuration await sdk.deleteMfa('my-organization', 'alice_smith'); ``` -------------------------------- ### Initialize Casdoor NodeJS SDK Source: https://github.com/casdoor/casdoor-nodejs-sdk/blob/master/README.md Demonstrates how to initialize the Casdoor SDK with configuration. Includes optional Axios configuration for custom HTTPS agents, such as using a self-signed CA. The initialization requires endpoint, clientId, clientSecret, certificate, orgName, and optionally appName. ```typescript import { SDK, Config } from 'casdoor-nodejs-sdk' import type { AxiosRequestConfig } from 'axios'; import https from 'node:https'; // Optional param for providing a self-signed CA with requests. const axiosConfig: AxiosRequestConfig = { httpsAgent: new https.Agent({ ca: ... }) } const authCfg: Config = { endpoint: '', clientId: '', clientSecret: '', certificate: '', orgName: '', } const sdk = new SDK(authCfg) // or const sdk = new SDK(authCfg, axiosConfig) // call sdk to handle ``` -------------------------------- ### Initialize Casdoor Node.js SDK Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt Initializes the Casdoor Node.js SDK with basic configuration or custom Axios settings. Requires Casdoor server endpoint, client ID, client secret, certificate, organization name, and application name. Supports custom Axios configurations for specific network needs like self-signed certificates. ```typescript import { SDK, Config } from 'casdoor-nodejs-sdk'; import type { AxiosRequestConfig } from 'axios'; import https from 'node:https'; import fs from 'fs'; // Read the certificate from file const cert = fs.readFileSync('./cert.pem', 'utf8'); // Basic configuration const config: Config = { endpoint: 'https://casdoor.example.com', clientId: 'your-client-id', clientSecret: 'your-client-secret', certificate: cert, orgName: 'my-organization', appName: 'my-application' }; // Initialize SDK const sdk = new SDK(config); // Or with custom axios configuration for self-signed certificates const axiosConfig: AxiosRequestConfig = { httpsAgent: new https.Agent({ ca: fs.readFileSync('./ca-cert.pem') }) }; const sdkWithCustomAxios = new SDK(config, axiosConfig); ``` -------------------------------- ### Manage Casdoor Applications with Node.js SDK Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt Provides functions for managing Casdoor applications, including fetching all applications, retrieving a specific application, creating a new one, updating an existing application, and deleting an application. Requires SDK configuration and application details. ```typescript import { SDK, Application } from 'casdoor-nodejs-sdk'; const sdk = new SDK(config); // Get all applications const appsResponse = await sdk.getApplications(); const applications = appsResponse.data.data; // Get specific application const appResponse = await sdk.getApplication('my-application'); const app = appResponse.data.data; // Create new application const newApp: Application = { owner: 'my-organization', name: 'mobile-app', createdTime: new Date().toISOString(), displayName: 'Mobile Application', description: 'iOS and Android mobile app', clientId: 'mobile-app-client-id', clientSecret: 'mobile-app-secret', redirectUris: ['myapp://callback'], tokenFormat: 'JWT', expireInHours: 168, enablePassword: true, enableSignUp: true, enableSigninSession: true, enableAutoSignin: false }; await sdk.addApplication(newApp); // Update application app.displayName = 'Mobile App v2.0'; await sdk.updateApplication(app); // Delete application await sdk.deleteApplication(app); ``` -------------------------------- ### Resource Upload and Management API Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt APIs for uploading, retrieving, updating, and deleting resources (files). ```APIDOC ## POST /api/upload-resource ### Description Uploads a resource file. ### Method POST ### Endpoint /api/upload-resource ### Parameters #### Request Body - **resource** (object) - Required - Metadata for the resource. - **owner** (string) - Required - The owner of the resource. - **name** (string) - Required - The name of the resource. - **parent** (string) - Optional - The parent directory or category. - **fullFilePath** (string) - Optional - The full path where the resource will be stored. - **file** (file) - Required - The actual file to upload. ### Request Example ```plaintext --YOUR_BOUNDARY Content-Disposition: form-data; name="resource" { "owner": "my-organization", "name": "profile-photo", "parent": "avatars" } --YOUR_BOUNDARY Content-Disposition: form-data; name="file"; filename="alice.jpg" Content-Type: image/jpeg [binary image data] --YOUR_BOUNDARY-- ``` ### Response #### Success Response (200) - **data** (object) - **url** (string) - The URL of the uploaded resource. #### Response Example ```json { "data": { "url": "https://casdoor.example.com/uploads/avatars/alice.jpg" } } ``` ## GET /api/resources ### Description Retrieves a list of resources with filtering and sorting options. ### Method GET ### Endpoint /api/resources ### Parameters #### Query Parameters - **owner** (string) - Required - The owner of the resources. - **user** (string) - Optional - Filter by user. - **tag** (string) - Optional - Filter by tag. - **name** (string) - Optional - Filter by resource name. - **sortField** (string) - Optional - Field to sort by (e.g., 'createdTime'). - **sortOrder** (string) - Optional - Sort order ('asc' or 'desc'). ### Request Example None ### Response #### Success Response (200) - **data** (array) - An array of resource objects. #### Response Example ```json { "data": [ { "owner": "my-organization", "name": "profile-photo", "parent": "avatars", "fullFilePath": "/uploads/avatars/alice.jpg", "url": "https://casdoor.example.com/uploads/avatars/alice.jpg", "tag": "profile", "size": 102400, "createdTime": "2023-10-27T10:00:00Z", "updatedTime": "2023-10-27T10:05:00Z" } ] } ``` ## GET /api/resource/:id ### Description Retrieves a specific resource by its ID. ### Method GET ### Endpoint /api/resource/:id ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the resource to retrieve. ### Request Example None ### Response #### Success Response (200) - **data** (object) - The resource object. #### Response Example ```json { "data": { "owner": "my-organization", "name": "profile-photo", "parent": "avatars", "fullFilePath": "/uploads/avatars/alice.jpg", "url": "https://casdoor.example.com/uploads/avatars/alice.jpg", "tag": "profile", "size": 102400, "createdTime": "2023-10-27T10:00:00Z", "updatedTime": "2023-10-27T10:05:00Z" } } ``` ## PUT /api/resources ### Description Updates the metadata of an existing resource. ### Method PUT ### Endpoint /api/resources ### Parameters #### Request Body - **owner** (string) - Required - The owner of the resource. - **name** (string) - Required - The name of the resource. - **parent** (string) - Optional - The parent directory or category. - **fullFilePath** (string) - Optional - The full path where the resource is stored. - **url** (string) - Optional - The URL of the resource. - **tag** (string) - Optional - A tag associated with the resource. - **description** (string) - Optional - A description for the resource. ### Request Example ```json { "owner": "my-organization", "name": "profile-photo", "parent": "avatars", "fullFilePath": "/uploads/avatars/alice.jpg", "url": "https://casdoor.example.com/uploads/avatars/alice.jpg", "tag": "profile", "description": "User profile photo" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "ok" } ``` ## DELETE /api/resources/:id ### Description Deletes a specific resource by its ID. ### Method DELETE ### Endpoint /api/resources/:id ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the resource to delete. ### Request Example None ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### Upload and Manage Resources with Casdoor Node.js SDK Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt This snippet covers resource management, including uploading files, retrieving lists of resources with filters, fetching specific resources, updating metadata, and deleting resources using the Casdoor Node.js SDK. It requires SDK, Resource types, and `form-data` and `fs` modules. ```typescript import { SDK, Resource } from 'casdoor-nodejs-sdk'; import fs from 'fs'; import FormData from 'form-data'; const sdk = new SDK(config); // Upload a resource file const resource: Resource = { owner: 'my-organization', name: 'profile-photo', parent: 'avatars', fullFilePath: '/uploads/avatars/alice.jpg' }; const form = new FormData(); form.append('file', fs.createReadStream('./alice.jpg')); const uploadResult = await sdk.uploadResource(resource, form); console.log('Upload URL:', uploadResult.data.url); // Get resources with filtering and sorting const resourcesResponse = await sdk.getResources( 'my-organization', 'alice_smith', 'tag', 'profile-photo', 'createdTime', 'desc' ); const resources = resourcesResponse.data.data; // Get specific resource const resourceResponse = await sdk.getResource('resource-001'); const fetchedResource = resourceResponse.data.data; // Update resource metadata fetchedResource.description = 'User profile photo'; await sdk.updateResource(fetchedResource); // Delete resource await sdk.deleteResource(fetchedResource); ``` -------------------------------- ### Generate Authentication URLs with Node.js SDK Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt Generates various URLs for user authentication flows, including sign-up (with password or OAuth), sign-in, and user profile access. Requires the SDK instance and optionally an access token. These URLs redirect users to the Casdoor service for authentication. ```typescript import { SDK } from 'casdoor-nodejs-sdk'; const sdk = new SDK(config); // Assuming config is defined elsewhere // Generate sign-up URL with password enabled const signUpUrl = sdk.getSignUpUrl(true, 'http://localhost:3000/callback'); // Returns: https://casdoor.example.com/signup/my-application // Generate sign-up URL with OAuth flow const signUpUrlOAuth = sdk.getSignUpUrl(false, 'http://localhost:3000/callback'); // Returns: https://casdoor.example.com/signup/oauth/authorize?client_id=...&response_type=code&redirect_uri=http://localhost:3000/callback&scope=read&state=my-application // Generate sign-in URL const signInUrl = sdk.getSignInUrl('http://localhost:3000/callback'); // Returns: https://casdoor.example.com/login/oauth/authorize?client_id=... // Generate user profile URL const profileUrl = sdk.getUserProfileUrl('john_doe', accessToken); // Assuming accessToken is defined // Returns: https://casdoor.example.com/users/my-organization/john_doe?access_token=... // Generate current user profile URL const myProfileUrl = sdk.getMyProfileUrl(accessToken); // Assuming accessToken is defined // Returns: https://casdoor.example.com/account?access_token=... ``` -------------------------------- ### Send Email and SMS Notifications with Casdoor SDK Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt Demonstrates sending email and SMS messages using the Casdoor Node.js SDK. Requires SDK configuration, email/SMS provider details, and recipient information. Outputs status of the sent messages. ```typescript import { SDK, Email, Sms } from 'casdoor-nodejs-sdk'; const sdk = new SDK(config); // Send email const email: Email = { title: 'Welcome to Our Platform', content: '

Welcome!

Thank you for joining us.

', sender: 'noreply@example.com', receivers: ['alice@example.com', 'bob@example.com'], provider: 'provider_smtp' }; const emailResult = await sdk.sendEmail(email); if (emailResult.data.status === 'ok') { console.log('Email sent successfully'); } // Send SMS const sms: Sms = { content: 'Your verification code is: 123456', receivers: ['+1234567890'], provider: 'provider_twilio' }; const smsResult = await sdk.sendSms(sms); if (smsResult.data.status === 'ok') { console.log('SMS sent successfully'); } ``` -------------------------------- ### User Management API Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt Provides endpoints for creating, retrieving, updating, and deleting users within an organization, including managing user profiles. ```APIDOC ## GET /api/users ### Description Retrieves a list of all users within an organization. ### Method GET ### Endpoint /api/users ### Parameters #### Query Parameters - **owner** (string) - Required - The owner of the users to retrieve. ### Response #### Success Response (200) - **data** (array) - An array of user objects. - **owner** (string) - The owner of the user. - **name** (string) - The unique name of the user. - **displayName** (string) - The display name of the user. - **email** (string) - The email address of the user. - **phone** (string) - The phone number of the user. - **createdTime** (string) - The ISO 8601 timestamp of when the user was created. - **... (other user fields)** ### Response Example ```json { "status": "ok", "data": { "users": [ { "owner": "my-organization", "name": "john_doe", "displayName": "John Doe", "email": "john.doe@example.com", "phone": "+11223344556", "createdTime": "2023-10-27T10:00:00Z" } ] } } ``` ## GET /api/users/{id} ### Description Retrieves a specific user by their unique identifier (name). ### Method GET ### Endpoint /api/users/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique name of the user to retrieve. ### Response #### Success Response (200) - **data** (object) - The user object. - **owner** (string) - The owner of the user. - **name** (string) - The unique name of the user. - **displayName** (string) - The display name of the user. - **email** (string) - The email address of the user. - **phone** (string) - The phone number of the user. - **createdTime** (string) - The ISO 8601 timestamp of when the user was created. - **... (other user fields)** ### Response Example ```json { "status": "ok", "data": { "owner": "my-organization", "name": "john_doe", "displayName": "John Doe", "email": "john.doe@example.com", "phone": "+11223344556", "createdTime": "2023-10-27T10:00:00Z" } } ``` ## GET /api/user/count ### Description Retrieves the count of users, optionally filtering by online status. ### Method GET ### Endpoint /api/user/count ### Parameters #### Query Parameters - **online** (boolean) - Optional - If true, counts only online users. ### Response #### Success Response (200) - **data** (number) - The total count of users. ### Response Example ```json { "status": "ok", "data": 150 } ``` ## POST /api/users ### Description Creates a new user. ### Method POST ### Endpoint /api/users ### Parameters #### Request Body - **owner** (string) - Required - The owner organization of the user. - **name** (string) - Required - The unique name of the user. - **displayName** (string) - Required - The display name of the user. - **email** (string) - Required - The email address of the user. - **phone** (string) - Optional - The phone number of the user. - **password** (string) - Required - The password for the new user. - **type** (string) - Optional - The type of user (e.g., 'normal-user'). - **isAdmin** (boolean) - Optional - Whether the user is an administrator. - **... (other user fields)** ### Request Example ```json { "owner": "my-organization", "name": "alice_smith", "createdTime": "2023-10-27T10:00:00Z", "displayName": "Alice Smith", "email": "alice@example.com", "phone": "+1234567890", "password": "SecurePassword123!", "type": "normal-user", "isAdmin": false } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success ('ok'). ### Response Example ```json { "status": "ok", "data": {} } ``` ## PUT /api/users ### Description Updates an existing user. ### Method PUT ### Endpoint /api/users ### Parameters #### Request Body - **owner** (string) - Required - The owner of the user. - **name** (string) - Required - The unique name of the user. - **displayName** (string) - Optional - The updated display name. - **title** (string) - Optional - The updated title. - **... (other user fields to update)** ### Request Example ```json { "owner": "my-organization", "name": "alice_smith", "displayName": "Alice Johnson", "title": "Senior Engineer" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success ('ok'). ### Response Example ```json { "status": "ok", "data": {} } ``` ## POST /api/user/set-password ### Description Sets a new password for a user. ### Method POST ### Endpoint /api/user/set-password ### Parameters #### Request Body - **owner** (string) - Required - The owner of the user. - **name** (string) - Required - The name of the user. - **oldPassword** (string) - Required - The current password of the user. - **newPassword** (string) - Required - The new password for the user. ### Request Example ```json { "owner": "my-organization", "name": "alice_smith", "oldPassword": "SecurePassword123!", "newPassword": "NewSecurePassword456!" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success ('ok'). ### Response Example ```json { "status": "ok", "data": {} } ``` ## DELETE /api/users/{owner}/{name} ### Description Deletes a user. ### Method DELETE ### Endpoint /api/users/{owner}/{name} ### Parameters #### Path Parameters - **owner** (string) - Required - The owner of the user. - **name** (string) - Required - The name of the user to delete. ### Response #### Success Response (200) - **status** (string) - Indicates success ('ok'). ### Response Example ```json { "status": "ok", "data": {} } ``` ``` -------------------------------- ### Token Management and Introspection API Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt APIs for managing OAuth tokens, including retrieval, creation, and introspection. ```APIDOC ## GET /api/tokens ### Description Retrieves a paginated list of tokens. ### Method GET ### Endpoint /api/tokens ### Parameters #### Query Parameters - **p** (number) - Optional - The page number (default is 1). - **pageSize** (number) - Optional - The number of items per page (default is 20). ### Request Example None ### Response #### Success Response (200) - **data** (array) - An array of token objects. #### Response Example ```json { "data": [ { "owner": "admin", "name": "token-001", "createdTime": "2023-10-27T10:00:00Z", "application": "app-1", "organization": "org-1", "user": "user-1", "code": "", "accessToken": "...", "refreshToken": "...", "expiresIn": 7200, "scope": "read", "tokenType": "Bearer", "codeChallenge": "", "codeIsUsed": false, "codeExpireIn": 300 } ] } ``` ## GET /api/tokens/:id ### Description Retrieves a specific token by its ID. ### Method GET ### Endpoint /api/tokens/:id ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the token to retrieve. ### Request Example None ### Response #### Success Response (200) - **data** (object) - The token object. #### Response Example ```json { "data": { "owner": "admin", "name": "token-001", "createdTime": "2023-10-27T10:00:00Z", "application": "app-1", "organization": "org-1", "user": "user-1", "code": "", "accessToken": "...", "refreshToken": "...", "expiresIn": 7200, "scope": "read", "tokenType": "Bearer", "codeChallenge": "", "codeIsUsed": false, "codeExpireIn": 300 } } ``` ## POST /introspect ### Description Introspects a token to check its validity and retrieve associated information. ### Method POST ### Endpoint /introspect ### Parameters #### Request Body - **token** (string) - Required - The token to introspect. - **token_type_hint** (string) - Optional - A hint about the token type (e.g., 'access_token', 'refresh_token'). ### Request Example ```json { "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", "token_type_hint": "access_token" } ``` ### Response #### Success Response (200) - **active** (boolean) - Indicates if the token is active. - **scope** (string) - The scope granted to the token. - **exp** (number) - The expiration time of the token (Unix timestamp). - **sub** (string) - The subject of the token (e.g., user ID). - **iss** (string) - The issuer of the token. - **aud** (string) - The audience of the token. #### Response Example ```json { "active": true, "scope": "read write", "exp": 1678886400, "sub": "user-id-123", "iss": "casdoor.org", "aud": "my-application" } ``` ## POST /api/tokens ### Description Creates a new token. ### Method POST ### Endpoint /api/tokens ### Parameters #### Request Body - **owner** (string) - Required - The owner of the token. - **name** (string) - Required - The name of the token. - **createdTime** (string) - Required - The creation timestamp in ISO format. - **application** (string) - Optional - The application associated with the token. - **organization** (string) - Optional - The organization associated with the token. - **user** (string) - Optional - The user associated with the token. - **code** (string) - Optional - The authorization code. - **accessToken** (string) - Optional - The access token string. - **refreshToken** (string) - Optional - The refresh token string. - **expiresIn** (number) - Optional - The token's validity period in seconds. - **scope** (string) - Optional - The scope of the token. - **tokenType** (string) - Optional - The type of the token (e.g., 'Bearer'). - **codeChallenge** (string) - Optional - The code challenge for PKCE. - **codeIsUsed** (boolean) - Optional - Whether the code has been used. - **codeExpireIn** (number) - Optional - The expiration time for the code in seconds. ### Request Example ```json { "owner": "admin", "name": "api-token-001", "createdTime": "2023-10-27T10:00:00Z", "application": "my-application", "organization": "my-organization", "user": "alice_smith", "expiresIn": 7200, "scope": "read write", "tokenType": "Bearer" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### Organization Management API Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt APIs for managing organizations, including fetching, creating, updating, and deleting them. ```APIDOC ## GET /api/organizations ### Description Retrieves a list of all organizations. ### Method GET ### Endpoint /api/organizations ### Parameters None ### Request Example None ### Response #### Success Response (200) - **data** (array) - An array of organization objects. #### Response Example ```json { "data": [ { "owner": "admin", "name": "my-organization", "createdTime": "2023-01-01T10:00:00Z", "displayName": "My Organization", "websiteUrl": "https://myorg.com", "passwordType": "salt", "passwordOptions": [ "AtLeast6" ], "countryCodes": [ "US" ], "defaultAvatar": "https://cdn.example.com/default.png", "defaultApplication": "app-built-in", "languages": [ "en" ], "initScore": 1000, "enableSoftDeletion": false, "isProfilePublic": true, "themeData": { "themeType": "default", "colorPrimary": "#007bff", "borderRadius": 4, "isCompact": false, "isEnabled": true } } ] } ``` ## GET /api/organizations/:name ### Description Retrieves a specific organization by its name. ### Method GET ### Endpoint /api/organizations/:name ### Parameters #### Path Parameters - **name** (string) - Required - The name of the organization to retrieve. ### Request Example None ### Response #### Success Response (200) - **data** (object) - The organization object. #### Response Example ```json { "data": { "owner": "admin", "name": "my-organization", "createdTime": "2023-01-01T10:00:00Z", "displayName": "My Organization", "websiteUrl": "https://myorg.com", "passwordType": "salt", "passwordOptions": [ "AtLeast6" ], "countryCodes": [ "US" ], "defaultAvatar": "https://cdn.example.com/default.png", "defaultApplication": "app-built-in", "languages": [ "en" ], "initScore": 1000, "enableSoftDeletion": false, "isProfilePublic": true, "themeData": { "themeType": "default", "colorPrimary": "#007bff", "borderRadius": 4, "isCompact": false, "isEnabled": true } } } ``` ## POST /api/organizations ### Description Creates a new organization. ### Method POST ### Endpoint /api/organizations ### Parameters #### Request Body - **owner** (string) - Required - The owner of the organization. - **name** (string) - Required - The unique name of the organization. - **createdTime** (string) - Required - The creation timestamp in ISO format. - **displayName** (string) - Optional - The display name of the organization. - **websiteUrl** (string) - Optional - The website URL of the organization. - **passwordType** (string) - Optional - The password type for the organization. - **passwordOptions** (array of strings) - Optional - Options for password complexity. - **countryCodes** (array of strings) - Optional - Supported country codes. - **defaultAvatar** (string) - Optional - URL for the default avatar. - **defaultApplication** (string) - Optional - The default application for the organization. - **languages** (array of strings) - Optional - Supported languages. - **initScore** (number) - Optional - Initial score for users. - **enableSoftDeletion** (boolean) - Optional - Whether to enable soft deletion. - **isProfilePublic** (boolean) - Optional - Whether the profile is public by default. - **themeData** (object) - Optional - Theme configuration for the organization. - **themeType** (string) - Optional - Type of theme. - **colorPrimary** (string) - Optional - Primary color of the theme. - **borderRadius** (number) - Optional - Border radius for UI elements. - **isCompact** (boolean) - Optional - Whether the theme is compact. - **isEnabled** (boolean) - Optional - Whether the theme is enabled. ### Request Example ```json { "owner": "admin", "name": "new-company", "createdTime": "2023-10-27T10:00:00Z", "displayName": "New Company Inc.", "websiteUrl": "https://newcompany.com", "passwordType": "salt", "passwordOptions": ["AtLeast6"], "countryCodes": ["US", "CA", "GB"], "defaultAvatar": "https://cdn.example.com/default-avatar.png", "defaultApplication": "app-built-in", "languages": ["en", "zh", "es"], "initScore": 2000, "enableSoftDeletion": true, "isProfilePublic": false, "themeData": { "themeType": "default", "colorPrimary": "#4CAF50", "borderRadius": 4, "isCompact": false, "isEnabled": true } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "ok" } ``` ## PUT /api/organizations ### Description Updates an existing organization. ### Method PUT ### Endpoint /api/organizations ### Parameters #### Request Body - **owner** (string) - Required - The owner of the organization. - **name** (string) - Required - The unique name of the organization. - **createdTime** (string) - Required - The creation timestamp in ISO format. - **displayName** (string) - Optional - The display name of the organization. - **websiteUrl** (string) - Optional - The website URL of the organization. - **passwordType** (string) - Optional - The password type for the organization. - **passwordOptions** (array of strings) - Optional - Options for password complexity. - **countryCodes** (array of strings) - Optional - Supported country codes. - **defaultAvatar** (string) - Optional - URL for the default avatar. - **defaultApplication** (string) - Optional - The default application for the organization. - **languages** (array of strings) - Optional - Supported languages. - **initScore** (number) - Optional - Initial score for users. - **enableSoftDeletion** (boolean) - Optional - Whether to enable soft deletion. - **isProfilePublic** (boolean) - Optional - Whether the profile is public by default. - **themeData** (object) - Optional - Theme configuration for the organization. - **themeType** (string) - Optional - Type of theme. - **colorPrimary** (string) - Optional - Primary color of the theme. - **borderRadius** (number) - Optional - Border radius for UI elements. - **isCompact** (boolean) - Optional - Whether the theme is compact. - **isEnabled** (boolean) - Optional - Whether the theme is enabled. ### Request Example ```json { "owner": "admin", "name": "my-organization", "createdTime": "2023-01-01T10:00:00Z", "displayName": "My Updated Organization", "websiteUrl": "https://myorg.com", "passwordType": "salt", "passwordOptions": ["AtLeast6"], "countryCodes": ["US", "CA"], "defaultAvatar": "https://cdn.example.com/default.png", "defaultApplication": "app-built-in", "languages": ["en", "fr"], "initScore": 1500, "enableSoftDeletion": true, "isProfilePublic": false, "themeData": { "themeType": "custom", "colorPrimary": "#ff0000", "borderRadius": 5, "isCompact": true, "isEnabled": true } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "ok" } ``` ## DELETE /api/organizations/:name ### Description Deletes a specific organization by its name. ### Method DELETE ### Endpoint /api/organizations/:name ### Parameters #### Path Parameters - **name** (string) - Required - The name of the organization to delete. ### Request Example None ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### Manage Tokens and Introspection with Casdoor Node.js SDK Source: https://context7.com/casdoor/casdoor-nodejs-sdk/llms.txt This snippet shows how to manage OAuth tokens, including fetching lists, retrieving specific tokens, introspecting their validity, and creating new tokens using the Casdoor Node.js SDK. It requires the SDK and Token types. ```typescript import { SDK, Token } from 'casdoor-nodejs-sdk'; const sdk = new SDK(config); // Get paginated tokens list const tokensResponse = await sdk.getTokens(1, 20); const tokens = tokensResponse.data.data; // Get specific token const tokenResponse = await sdk.getToken('token-id-123'); const token = tokenResponse.data.data; // Introspect token to check validity const introspectionResult = await sdk.introspect( 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...', 'access_token' ); if (introspectionResult.data.active) { console.log('Token is valid'); console.log('Token scope:', introspectionResult.data.scope); console.log('Expires at:', introspectionResult.data.exp); } else { console.log('Token is invalid or expired'); } // Create new token const newToken: Token = { owner: 'admin', name: 'api-token-001', createdTime: new Date().toISOString(), application: 'my-application', organization: 'my-organization', user: 'alice_smith', code: '', accessToken: '', refreshToken: '', expiresIn: 7200, scope: 'read write', tokenType: 'Bearer', codeChallenge: '', codeIsUsed: false, codeExpireIn: 300 }; await sdk.addToken(newToken); ```