Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

132
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 { }
7 months 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
      },
    });
  });
7 months 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.

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos