fix and update
This commit is contained in:
@@ -2,6 +2,7 @@ import { BadRequestException, Injectable, UnauthorizedException } from '@nestjs/
|
||||
import { PrismaService } from '../infra/prisma.service';
|
||||
import { OAuthCoreService } from './oauth-core.service';
|
||||
import { SessionService } from './session.service';
|
||||
import { SettingsService } from './settings.service';
|
||||
import { assertHumanAccount, HUMAN_USER_WHERE } from './system-account.util';
|
||||
|
||||
@Injectable()
|
||||
@@ -9,7 +10,8 @@ export class FedcmService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly session: SessionService,
|
||||
private readonly oauthCore: OAuthCoreService
|
||||
private readonly oauthCore: OAuthCoreService,
|
||||
private readonly settings: SettingsService
|
||||
) {}
|
||||
|
||||
async getAccounts(userId: string, sessionId: string) {
|
||||
@@ -81,12 +83,21 @@ export class FedcmService {
|
||||
throw new BadRequestException('OAuth-приложение не найдено или отключено');
|
||||
}
|
||||
|
||||
const frontendUrl = (await this.settings.getValue('PUBLIC_FRONTEND_URL', 'http://localhost:3002')).replace(/\/+$/, '');
|
||||
const privacyFallback = `${frontendUrl}/data`;
|
||||
const privacy = (await this.settings.getValue('FEDCM_PRIVACY_POLICY_URL', '')).trim();
|
||||
const terms = (await this.settings.getValue('FEDCM_TERMS_URL', '')).trim();
|
||||
|
||||
return {
|
||||
privacy_policy_url: 'https://id.lendry.ru/data',
|
||||
terms_of_service_url: 'https://id.lendry.ru/data'
|
||||
privacy_policy_url: privacy || privacyFallback,
|
||||
terms_of_service_url: terms || privacyFallback
|
||||
};
|
||||
}
|
||||
|
||||
async isOneTapEnabled() {
|
||||
return this.settings.getBoolean('ONE_TAP_ENABLED', true);
|
||||
}
|
||||
|
||||
private async assertUnlockedSession(userId: string, sessionId: string) {
|
||||
const state = await this.session.resolveSessionState(sessionId);
|
||||
if (!state || state.userId !== userId) {
|
||||
|
||||
@@ -7,9 +7,29 @@ export const DEFAULT_SYSTEM_SETTINGS = [
|
||||
{ key: 'PROJECT_DOMAIN', value: 'id.lendry.ru', description: 'Основной домен IdP (без пути)' },
|
||||
{
|
||||
key: 'PUBLIC_API_URL',
|
||||
value: 'http://localhost:3000',
|
||||
value: 'http://localhost:3002/idp-api',
|
||||
description: 'Публичный базовый URL API для OAuth и OpenID Connect (issuer). Пример: https://sso.example.ru/idp-api'
|
||||
},
|
||||
{
|
||||
key: 'PUBLIC_FRONTEND_URL',
|
||||
value: 'http://localhost:3002',
|
||||
description: 'Публичный URL frontend IdP. Используется для login_url FedCM, popup OAuth и виджета sso-widget.js'
|
||||
},
|
||||
{
|
||||
key: 'ONE_TAP_ENABLED',
|
||||
value: 'true',
|
||||
description: 'Разрешить One Tap Login (FedCM и виджет sso-widget.js) для OAuth-клиентов'
|
||||
},
|
||||
{
|
||||
key: 'FEDCM_PRIVACY_POLICY_URL',
|
||||
value: '',
|
||||
description: 'URL политики конфиденциальности для UI FedCM. Пусто — страница «Данные» IdP'
|
||||
},
|
||||
{
|
||||
key: 'FEDCM_TERMS_URL',
|
||||
value: '',
|
||||
description: 'URL условий использования для UI FedCM. Пусто — страница «Данные» IdP'
|
||||
},
|
||||
{ key: 'PIN_LOCK_TIMEOUT_MINUTES', value: '15', description: 'Через сколько минут неактивности сессия блокируется PIN-кодом' },
|
||||
{ key: 'PIN_DELETE_GRACE_MINUTES', value: '1440', description: 'Задержка перед окончательным удалением PIN-кода после запроса (минуты)' },
|
||||
{ key: 'PIN_REQUIRE_ON_DELETE', value: 'true', description: 'Требовать текущий PIN-код при запросе удаления защиты' },
|
||||
@@ -102,6 +122,8 @@ export const PUBLIC_SETTING_KEYS = [
|
||||
'PROJECT_TAGLINE',
|
||||
'PROJECT_DOMAIN',
|
||||
'PUBLIC_API_URL',
|
||||
'PUBLIC_FRONTEND_URL',
|
||||
'ONE_TAP_ENABLED',
|
||||
'REGISTRATION_ENABLED',
|
||||
'MAINTENANCE_MODE',
|
||||
'LDAP_ENABLED',
|
||||
@@ -133,5 +155,18 @@ export class SystemSettingsSeedService implements OnModuleInit {
|
||||
update: { value: envPublicApiUrl }
|
||||
});
|
||||
}
|
||||
|
||||
const envPublicFrontendUrl = process.env.PUBLIC_FRONTEND_URL?.trim();
|
||||
if (envPublicFrontendUrl) {
|
||||
await this.prisma.systemSetting.upsert({
|
||||
where: { key: 'PUBLIC_FRONTEND_URL' },
|
||||
create: {
|
||||
key: 'PUBLIC_FRONTEND_URL',
|
||||
value: envPublicFrontendUrl,
|
||||
description: 'Публичный URL frontend IdP. Используется для login_url FedCM, popup OAuth и виджета sso-widget.js'
|
||||
},
|
||||
update: { value: envPublicFrontendUrl }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user