fix: browser logout only if endSession url defined

Closes #395
This commit is contained in:
Jovan Krunić
2023-04-11 16:29:53 +02:00
committed by Rainer Killinger
parent cc939f3887
commit 7f6de94ab5
2 changed files with 29 additions and 31 deletions

View File

@@ -29,6 +29,7 @@ import {StorageProvider} from '../storage/storage.provider';
import {DefaultAuthService} from './default-auth.service';
import {PAIAAuthService} from './paia/paia-auth.service';
import {SimpleBrowser} from '../../util/browser.factory';
import {AlertController} from '@ionic/angular';
const AUTH_ORIGIN_PATH = 'stapps.auth.origin_path';
@@ -45,6 +46,7 @@ export class AuthHelperService {
private defaultAuth: DefaultAuthService,
private paiaAuth: PAIAAuthService,
private browser: SimpleBrowser,
private alertController: AlertController,
) {
this.userConfigurationMap = (
this.configProvider.getAnyValue('auth') as {
@@ -118,11 +120,33 @@ export class AuthHelperService {
/**
* Ends browser session by opening endSessionEndpoint URL of the provider
*
* @param providerType Type of the provider (e.g. 'default' or 'paia')
*/
async endBrowserSession(providerType: SCAuthorizationProviderType) {
const endSessionEndpoint = (await this.getProvider(providerType).configuration).endSessionEndpoint ?? '';
if (endSessionEndpoint.length > 0) {
this.browser.open(new URL(endSessionEndpoint).href);
const endSessionEndpoint = (await this.getProvider(providerType).configuration).endSessionEndpoint;
if (endSessionEndpoint) {
const alert: HTMLIonAlertElement = await this.alertController.create({
header: this.translateService.instant(`auth.messages.${providerType}.log_out_alert.header`),
message: this.translateService.instant(`auth.messages.${providerType}.log_out_alert.message`),
buttons: [
{
text: this.translateService.instant('no'),
cssClass: 'default',
},
{
text: this.translateService.instant('yes'),
role: 'confirm',
cssClass: 'preferred',
handler: () => {
this.browser.open(new URL(endSessionEndpoint).href);
},
},
],
});
await alert.present();
}
}
}

View File

@@ -19,8 +19,6 @@ import {AuthHelperService} from '../../auth/auth-helper.service';
import {Observable, Subscription} from 'rxjs';
import {SCAuthorizationProviderType} from '@openstapps/core';
import Swiper from 'swiper';
import {AlertController} from '@ionic/angular';
import {TranslateService} from '@ngx-translate/core';
@Component({
selector: 'stapps-profile-page-section',
@@ -55,11 +53,7 @@ export class ProfilePageSectionComponent implements OnInit, OnDestroy {
},
};
constructor(
private authHelper: AuthHelperService,
private alertController: AlertController,
private translateService: TranslateService,
) {}
constructor(private authHelper: AuthHelperService) {}
ngOnInit() {
if (this.item.authProvider) {
@@ -100,27 +94,7 @@ export class ProfilePageSectionComponent implements OnInit, OnDestroy {
async signOut(providerType: SCAuthorizationProviderType) {
await this.authHelper.getProvider(providerType).signOut();
const alert: HTMLIonAlertElement = await this.alertController.create({
header: this.translateService.instant(`auth.messages.${providerType}.log_out_alert.header`),
message: this.translateService.instant(`auth.messages.${providerType}.log_out_alert.message`),
buttons: [
{
text: this.translateService.instant('no'),
cssClass: 'default',
},
{
text: this.translateService.instant('yes'),
role: 'confirm',
cssClass: 'preferred',
handler: () => {
this.authHelper.endBrowserSession(providerType);
},
},
],
});
await alert.present();
await this.authHelper.endBrowserSession(providerType);
}
ngOnDestroy() {