refactor: read auth provider info from app config

This commit is contained in:
Jovan Krunić
2022-02-07 16:46:29 +00:00
committed by Rainer Killinger
parent a1592f84cc
commit fb7b3fd1d2
19 changed files with 216 additions and 287 deletions

View File

@@ -20,12 +20,23 @@ import {RouterTestingModule} from '@angular/router/testing';
import {AuthModule} from '../../auth/auth.module';
import {ProfilePageComponent} from './profile-page.component';
import {TranslateModule} from '@ngx-translate/core';
import {ConfigProvider} from '../../config/config.provider';
import {sampleAuthConfiguration} from '../../../_helpers/data/sample-configuration';
describe('ProfilePage', () => {
let component: ProfilePageComponent;
let fixture: ComponentFixture<ProfilePageComponent>;
let configProvider: ConfigProvider;
beforeEach(async(() => {
configProvider = jasmine.createSpyObj('ConfigProvider', [
'init',
'getAnyValue',
]);
configProvider.getAnyValue = jasmine.createSpy().and.callFake(function () {
return sampleAuthConfiguration;
});
TestBed.configureTestingModule({
declarations: [ProfilePageComponent],
imports: [
@@ -34,6 +45,7 @@ describe('ProfilePage', () => {
AuthModule,
TranslateModule.forRoot(),
],
providers: [{provide: ConfigProvider, useValue: configProvider}],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
}).compileComponents();
}));

View File

@@ -18,9 +18,12 @@ import {IonicUserInfoHandler} from 'ionic-appauth';
import {DefaultAuthService} from '../../auth/default-auth.service';
import {Requestor, TokenResponse} from '@openid/appauth';
import {PAIAAuthService} from '../../auth/paia/paia-auth.service';
import {SCAuthorizationProviderType, SCUserConfiguration} from '../user';
import {Subscription} from 'rxjs';
import {AuthHelperService} from '../../auth/auth-helper.service';
import {
SCAuthorizationProviderType,
SCUserConfiguration,
} from '@openstapps/core';
@Component({
selector: 'app-home',

View File

@@ -1,82 +0,0 @@
/*
* Copyright (C) 2022 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/>.
*/
/**
* TODO: Take it from the StApps Core
*/
import {SCAcademicPriceGroup} from '@openstapps/core';
/**
* A user configuration
*/
export interface SCUserConfiguration {
/**
* User's e-mail
*/
email?: string;
/**
* User's family name
*/
familyName?: string;
/**
* User's given name
*/
givenName?: string;
/**
* ID given to the user
*/
id: string;
/**
* The complete name of the user combining all the parts of the name into one
*/
name: string;
/**
* Role assigned to the user
*/
role: keyof SCAcademicPriceGroup;
/**
* Student ID given to the user
*/
studentId?: string;
}
/**
* TODO: Take it from the backend's config
*/
type mapping = {[key in keyof SCUserConfiguration]: string};
/**
* TODO: Take it from the backend's config
*/
export const userMapping: mapping = {
id: 'id',
name: 'sn',
role: 'attributes.eduPersonPrimaryAffiliation',
email: 'attributes.mailPrimaryAddress',
studentId: 'attributes.employeeNumber',
givenName: 'attributes.givenName',
familyName: 'attributes.sn',
};
/**
* TODO: Take it from the StApps Core
*/
export type SCAuthorizationProviderType = 'default' | 'paia';