• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

281
Vistas
How to return a value inside an observable in Angular

I need a response from an observable to set values before the MSAL authenticates.

Is there a way to return value inside the getAuthenticationConfiguration() observable?

How can I return values after the values are received inside the observable.

p.s. It is not possible to return inside the subscribe function.

export function MSALInstanceFactory(service: AzureService): IPublicClientApplication {
    service.getIdentityManagerApiRestService().getAuthenticationConfiguration().subscribe(response => {
        return new PublicClientApplication({
            auth: response.authenticationConfiguration, <-------- I want this
            cache: {
                cacheLocation: BrowserCacheLocation.LocalStorage,
                storeAuthStateInCookie: isIE, // set to true for IE 11. Remove this line to use Angular Universal
            }
        });
    })
}


@NgModule({
    declarations: [
        AzureComponent
    ],
    exports: [
        AzureComponent
    ],
    providers: [
        {
            provide: MSAL_INSTANCE,
            useFactory: MSALInstanceFactory,
            deps: [AzureService]
        }
    ]
})

export class AzureModule { }
about 3 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I would try to pipe the response (untested code):

service
  .getIdentityManagerApiRestService()
  .getAuthenticationConfiguration()
  .pipe(switchMap((res) => res.authenticationConfiguration))
  .subscribe((config) => {
    return new PublicClientApplication({
      auth: config,
      cache: {
        cacheLocation: BrowserCacheLocation.LocalStorage,
        storeAuthStateInCookie: isIE, // set to true for IE 11. Remove this line to use Angular Universal
      },
    });
  });
about 3 years ago · Juan Pablo Isaza Denunciar

0

I believe your getAuthenticationConfiguration() should look like this to return some response from it:

getAuthenticationConfiguration() {
  return authenticationConfiguration$.pipe(map(data) => data.authenticationConfiguration))
}

and when you subscribe to it, you can do this:

service
.getIdentityManagerApiRestService()
.getAuthenticationConfiguration()
.subscribe(response => {
    if(response.authenticationConfiguration) {
        return new PublicClientApplication({
            auth: response.authenticationConfiguration,
            cache: {
                cacheLocation: BrowserCacheLocation.LocalStorage,
                storeAuthStateInCookie: isIE,
            }
        });
    }
})

So basically you can add a check on response for the expected property in the response, once received then only do further code execution.

about 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda