feat: add auth support (default and paia)

This commit is contained in:
Michel Jonathan Schmitz
2022-01-24 18:43:00 +00:00
committed by Jovan Krunić
parent 046a95ba1d
commit b5f239ea4e
85 changed files with 3626 additions and 119 deletions

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {
StorageBackend,
Requestor,
AuthorizationServiceConfiguration,
} from '@openid/appauth';
import {Browser} from 'ionic-appauth';
import {environment} from 'src/environments/environment';
import {DefaultAuthService} from '../default-auth.service';
import {PAIAAuthService} from '../paia/paia-auth.service';
export const authFactory = (
requestor: Requestor,
browser: Browser,
storage: StorageBackend,
) => {
const authService = new DefaultAuthService(browser, storage, requestor);
authService.authConfig = environment.oauth2.client.his;
authService.localConfiguration = new AuthorizationServiceConfiguration(
environment.oauth2.service.his,
);
return authService;
};
export const paiaAuthFactory = (
requestor: Requestor,
browser: Browser,
storage: StorageBackend,
) => {
const authService = new PAIAAuthService(browser, storage, requestor);
authService.authConfig = environment.oauth2.client.paia;
authService.localConfiguration = new AuthorizationServiceConfiguration(
environment.oauth2.service.paia,
);
return authService;
};

View File

@@ -0,0 +1,9 @@
import {Platform} from '@ionic/angular';
import {DefaultBrowser} from 'ionic-appauth';
import {CapacitorBrowser} from 'ionic-appauth/lib/capacitor';
export const browserFactory = (platform: Platform) => {
return platform.is('capacitor')
? new CapacitorBrowser()
: new DefaultBrowser();
};

View File

@@ -0,0 +1,10 @@
import {HttpClient} from '@angular/common/http';
import {Platform} from '@ionic/angular';
import {CapacitorRequestor} from '../capacitor-requestor';
import {NgHttpService} from '../ng-http.service';
export const httpFactory = (platform: Platform, httpClient: HttpClient) => {
return platform.is('capacitor')
? new CapacitorRequestor()
: new NgHttpService(httpClient);
};

View File

@@ -0,0 +1,3 @@
export * from './auth.factory';
export * from './browser.factory';
export * from './storage.factory';

View File

@@ -0,0 +1,9 @@
import {Platform} from '@ionic/angular';
import {CapacitorSecureStorage} from 'ionic-appauth/lib/capacitor';
import {IonicStorage} from 'ionic-appauth/lib';
export const storageFactory = (platform: Platform) => {
return platform.is('capacitor')
? new CapacitorSecureStorage()
: new IonicStorage();
};