🔍 Authentication Schema Blocks
Authentication schema blocks provide JSON Schema definitions for authentication data validation in Nodeblocks applications. These schemas ensure secure authentication flows and provide clear contracts for authentication-related API endpoints.
🎯 Overview
Authentication schema blocks are designed to:
- Validate authentication data before processing
- Support multiple auth methods (OAuth, email/password)
- Ensure secure authentication with proper validation
- Enable email verification workflows
- Support device fingerprinting for enhanced security
📋 Authentication Schema Types
Provider Authentication Schemas
OAuth and third-party authentication validation.
Credentials Authentication Schemas
Email/password authentication validation.
Identity Schemas
Flexible authentication with support for multiple methods.
Email Verification Schemas
Email verification and confirmation workflows.
🔧 Available Authentication Schemas
providerSchema
Provider authentication schema for OAuth and third-party authentication.
Purpose: Validates OAuth provider authentication data
Schema Details:
- Type:
object
- Required Fields:
provider
,providerId
- Additional Properties:
false
(strict validation) - Properties:
provider: string
- OAuth provider nameproviderId: string
- Provider-specific user ID
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { providerSchema } = schemas;
const providerSchema = providerSchema({});
const validate = ajv.compile(providerSchema.schemas as SchemaDefinition);
const isValid = validate({ provider: 'google', providerId: '12345' });
credentialsSchema
Credentials authentication schema for email/password authentication.
Purpose: Validates email/password authentication data
Schema Details:
- Type:
object
- Required Fields:
email
,password
- Additional Properties:
false
(strict validation) - Properties:
email: string
- User email addressemailVerified: boolean
- Email verification status (default: false)password: string
- User password
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { credentialsSchema } = schemas;
const credentialsSchema = credentialsSchema({});
const validate = ajv.compile(credentialsSchema.schemas as SchemaDefinition);
const isValid = validate({ email: 'user@example.com', password: 'password123' });
identitySchema
Identity schema that supports both provider and credentials authentication.
Purpose: Validates authentication data with support for multiple auth methods
Schema Details:
- Type:
object
- Required Fields: Either
provider
+providerId
ORemail
+password
- Additional Properties:
false
(strict validation) - Validation: Requires either provider+providerId OR email+password
- Content-Type:
application/json
- Request Body:
required
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { identitySchema } = schemas;
const identitySchema = identitySchema({});
const validate = ajv.compile(identitySchema.schemas as SchemaDefinition);
// Provider auth
const isValidProvider = validate({ provider: 'google', providerId: '12345' });
// Credentials auth
const isValidCredentials = validate({ email: 'user@example.com', password: 'password123' });
loginWithCredentialsSchema
Login credentials schema for user authentication.
Purpose: Validates login request data with optional device fingerprinting
Schema Details:
- Type:
object
- Required Fields:
email
,password
- Optional Fields:
fingerprint
- Additional Properties:
false
(strict validation) - Content-Type:
application/json
- Request Body:
required
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { loginWithCredentialsSchema } = schemas;
const loginSchema = loginWithCredentialsSchema({});
const validate = ajv.compile(loginSchema.schemas as SchemaDefinition);
const isValid = validate({
email: 'user@example.com',
password: 'password123',
fingerprint: 'device-fingerprint-hash'
});
registerCredentialsSchema
User registration schema with email/password or token/password validation.
Purpose: Schema validator for user registration requests
Schema Details:
- Type:
object
- Required Fields:
password
(always required) - Optional Fields:
email
,token
- Validation: Requires either
email
+password
ORtoken
+password
- Content-Type:
application/json
- Request Body:
required
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { registerCredentialsSchema } = schemas;
const registerSchema = registerCredentialsSchema({});
const validate = ajv.compile(registerSchema.schemas as SchemaDefinition);
const isValid = validate({
email: 'user@example.com',
password: 'password123'
});
sendVerificationEmailSchema
JSON Schema for validating send verification email requests.
Purpose: Validates the request body for the send verification email endpoint
Schema Details:
- Type:
object
- Required Fields: None (all fields optional)
- Additional Properties:
false
(strict validation) - Parameters:
userId
(path parameter) - Content-Type:
application/json
- Request Body:
required
- Properties:
fingerprint?: string
- Optional device fingerprinting
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { sendVerificationEmailSchema } = schemas;
const verificationSchema = sendVerificationEmailSchema({});
const validate = ajv.compile(verificationSchema.schemas as SchemaDefinition);
const isValid = validate({
fingerprint: 'device-fingerprint-hash'
});
confirmEmailSchema
Email confirmation schema with token validation for email verification.
Purpose: Schema validator for email confirmation requests
Schema Details:
- Type:
object
- Required Fields:
token
- Additional Properties:
false
(strict validation) - Content-Type:
application/json
- Request Body:
required
- Properties:
token: string
- Verification token from email
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { confirmEmailSchema } = schemas;
const confirmSchema = confirmEmailSchema({});
const validate = ajv.compile(confirmSchema.schemas as SchemaDefinition);
const isValid = validate({
token: 'verification-token-123'
});
🔗 Related Documentation
- Authentication Domain Overview - Authentication domain overview