import { SsoInterface } from 'sso';
import { AppConfiguration } from '../../app-configuration';
import { AuthConfig } from 'angular-oauth2-oidc';
import { Injectable } from '@angular/core';

@Injectable()
export class SsoConfigurationService implements SsoInterface {
  constructor(private appConfig: AppConfiguration) {}

  getConfigurations(): AuthConfig {
    const config = this.appConfig.sso;

    if (!config.redirectUri) {
      config.redirectUri = window.location.origin;
    }

    if (!config.silentRefreshRedirectUri) {
      config.silentRefreshRedirectUri = window.location.origin + '/silent-refresh.html';
    }

    return config;
  }
}
