mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
* feat: add SAML authentication * refactor: change SAML icon * refactor: resolve SAML metadata paths using paths.js * test: add samlStrategy tests * fix: update setupSaml import * test: add SAML settings tests in config.spec.js * test: add client tests * refactor: improve SAML button label and fallback localization * feat: allow only one authentication method OpenID or SAML at a time * doc: add SAML configuration sample to docker-compose.override * fix: require SAML_SESSION_SECRET to enable SAML * feat: update samlStrategy * test: update samle tests * feat: add SAML login button label to translations and remove default value * fix: update SAML cert file binding * chore: update override example with SAML cert volume * fix: update SAML session handling with Redis backend --------- Co-authored-by: Ruben Talstra <RubenTalstra1211@outlook.com>
169 lines
No EOL
3 KiB
TypeScript
169 lines
No EOL
3 KiB
TypeScript
import { Schema, Document } from 'mongoose';
|
|
import { SystemRoles } from 'librechat-data-provider';
|
|
|
|
export interface IUser extends Document {
|
|
name?: string;
|
|
username?: string;
|
|
email: string;
|
|
emailVerified: boolean;
|
|
password?: string;
|
|
avatar?: string;
|
|
provider: string;
|
|
role?: string;
|
|
googleId?: string;
|
|
facebookId?: string;
|
|
openidId?: string;
|
|
samlId?: string;
|
|
ldapId?: string;
|
|
githubId?: string;
|
|
discordId?: string;
|
|
appleId?: string;
|
|
plugins?: unknown[];
|
|
twoFactorEnabled?: boolean;
|
|
totpSecret?: string;
|
|
backupCodes?: Array<{
|
|
codeHash: string;
|
|
used: boolean;
|
|
usedAt?: Date | null;
|
|
}>;
|
|
refreshToken?: Array<{
|
|
refreshToken: string;
|
|
}>;
|
|
expiresAt?: Date;
|
|
termsAccepted?: boolean;
|
|
createdAt?: Date;
|
|
updatedAt?: Date;
|
|
}
|
|
|
|
// Session sub-schema
|
|
const SessionSchema = new Schema(
|
|
{
|
|
refreshToken: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
},
|
|
{ _id: false },
|
|
);
|
|
|
|
// Backup code sub-schema
|
|
const BackupCodeSchema = new Schema(
|
|
{
|
|
codeHash: { type: String, required: true },
|
|
used: { type: Boolean, default: false },
|
|
usedAt: { type: Date, default: null },
|
|
},
|
|
{ _id: false },
|
|
);
|
|
|
|
const User = new Schema<IUser>(
|
|
{
|
|
name: {
|
|
type: String,
|
|
},
|
|
username: {
|
|
type: String,
|
|
lowercase: true,
|
|
default: '',
|
|
},
|
|
email: {
|
|
type: String,
|
|
required: [true, "can't be blank"],
|
|
lowercase: true,
|
|
unique: true,
|
|
match: [/\S+@\S+\.\S+/, 'is invalid'],
|
|
index: true,
|
|
},
|
|
emailVerified: {
|
|
type: Boolean,
|
|
required: true,
|
|
default: false,
|
|
},
|
|
password: {
|
|
type: String,
|
|
trim: true,
|
|
minlength: 8,
|
|
maxlength: 128,
|
|
},
|
|
avatar: {
|
|
type: String,
|
|
required: false,
|
|
},
|
|
provider: {
|
|
type: String,
|
|
required: true,
|
|
default: 'local',
|
|
},
|
|
role: {
|
|
type: String,
|
|
default: SystemRoles.USER,
|
|
},
|
|
googleId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
facebookId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
openidId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
samlId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
ldapId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
githubId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
discordId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
appleId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
plugins: {
|
|
type: Array,
|
|
},
|
|
twoFactorEnabled: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
totpSecret: {
|
|
type: String,
|
|
},
|
|
backupCodes: {
|
|
type: [BackupCodeSchema],
|
|
},
|
|
refreshToken: {
|
|
type: [SessionSchema],
|
|
},
|
|
expiresAt: {
|
|
type: Date,
|
|
expires: 604800, // 7 days in seconds
|
|
},
|
|
termsAccepted: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
},
|
|
{ timestamps: true },
|
|
);
|
|
|
|
export default User; |