flexi-cdn-auth
v4.7.4
Published
Чтобы конфигурировать сессию Electron необходимо импортировать функцию:
Downloads
689
Readme
Чтобы конфигурировать сессию Electron необходимо импортировать функцию:
import {initSession} from 'flexi-cdn-auth/controller/sessionController';
Функция принимает следующие параметры:
-ses - Сессия Electron (получается в main, по ссылке win.webContents.session, где win это экземпляр BrowserWindow)
-origin - Ссылка которую требуется вставлять в запросы вместо localhost:3000
f.e. - http://front.flexisoft.net для stage,
https://front.flexiligner.com для production
-domain - домен с которого требуется перенаправить куки
f.e. - .flexisoft.net для stage,
.flexiligner.com для production
Функции AuthController который импортируется из flexi-cdn-auth:
-checkUserAuth() возвращает промис при удачной авторизации, иначе перекидывает на account
-static getInstance() возвращает Singleton инстанс AuthController
-getInterfaceLanguage() возвращает промис с языком пользователя
-setUserLogout(username:string):Promise<any> производит выход пользователя из аккаунта(перекидывает на account)
-getCurrentUserInfo():Promise<any>; отдаёт информацию по текущему пользователю
Настройки BrowserWindow для корректной работы:
webPreferences: {
sandbox: true,
webSecurity: false
}
Для корректной работы в Electron в конфигурацию AuthController нужно добавить поле:
isDesktop:true
Для базовой инициализации AuthController необходимо: -Инициализировать контроллер со следующими параметрами: const authController = new AuthController({ refresh_duration: {Время обновления токена, 30000 в самый раз}, api_url: {Ссылка на AuthApi}, auth_app_url: {Ссылка на Account}, except_url: {Исключения для авторизации в ввиде массива, можно оставить пустым массивом}, erp_api_url: {Ссылка на ERPApi}, file_api_url: {Ссылка на FileApi}, }); -Запустить проверку авторизации: authController .checkUserAuth() .then(() => {В этой точке если всё хорошо, то можете рендерить ваше приложение, если что-то не так, то контроллер сам это обработает.})