Necesito una respuesta de un observable para establecer valores antes de que MSAL se autentique.
¿Hay alguna manera de devolver el valor dentro del observable getAuthenticationConfiguration()?
¿Cómo puedo devolver valores después de recibir los valores dentro del observable?
ps No es posible volver dentro de la función de suscripción.
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 { }
Intentaría canalizar la respuesta (código no probado):
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 }, }); });
Creo que su getAuthenticationConfiguration()
debería verse así para devolver alguna respuesta:
getAuthenticationConfiguration() { return authenticationConfiguration$.pipe(map(data) => data.authenticationConfiguration)) }
y cuando te suscribes, puedes hacer esto:
service .getIdentityManagerApiRestService() .getAuthenticationConfiguration() .subscribe(response => { if(response.authenticationConfiguration) { return new PublicClientApplication({ auth: response.authenticationConfiguration, cache: { cacheLocation: BrowserCacheLocation.LocalStorage, storeAuthStateInCookie: isIE, } }); } })
Entonces, básicamente, puede agregar una verificación en la respuesta para la propiedad esperada en la respuesta, una vez recibida, solo ejecute más código.