Azure App Registration Client Secrets Expiring? 🔐⌛

¿Los secretos de cliente de registro de aplicaciones de Azure están a punto de caducar? 🔐⌛

Usualmente, cuando necesitas conectarte a Business Central desde otra aplicación, debes utilizar las API REST, ya sean las API integradas o las API personalizadas.

La forma de conectarse y autenticarse en las API, sería utilizando la autenticación basada en Microsoft Entra ID contra el endpoint API común.

https://api.businesscentral.dynamics.com/v2.0/<environment name>/api/v2.0

De igual manera, para los escenarios en los que se requiere que las integraciones se ejecuten sin ninguna interacción del usuario, nos apoyaremos en S2S.

Identificación del vencimiento de los secretos clientes de las Aplicaciones de Microsoft Entra

El objetivo sería llevar el control del vencimiento de los secretos de las aplicaciones de Microsoft Entra que interactúan con nuestra solución, desde Business Central.

Lograremos este objetivo, apoyándonos en un API expuesta por Microsoft Graph, que nos permite identificar la fecha de creación y vencimiento del secreto de cliente.

Extenderemos en Business Central las pantallas de Microsoft Entra Applications, de tal manera, que nos permita identificar que aplicaciones deseo controlar y se habilita una notificación que nos avisa con un mes (1) de anticipación si un secreto está por vencer. A continuación, veremos como lo podemos conseguir.

Configuración de integración con Microsoft Graph

Creamos la aplicación, y creamos un secreto de cliente, el cual, le configuramos un tiempo de duración de vigencia.

Luego, vamos a la opción de permisos de API y configuraremos el de Microsoft Graph, al cual, le asignaremos los permisos de aplicación.

Seleccionamos el permiso de Aplicacion.Read.All.

Seleccionamos la opción de otorgar la confirmación del consentimiento del administrador.

Procedemos a probar la API de obtención del token de Microsoft Graph.

https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token

Propuesta de solución en Business Central

Como he indicado, nos apoyaremos en las siguientes APIs de Microsoft Graph:

La solución comprende los siguientes objetos:

  • 2 tablas: Configuración de la API, los secretos de la aplicación de Microsoft Entra seleccionada.
  • 1 extensión de tabla: Campo adicional en la tabla AAD Application
  • 2 páginas: Configuración de la API, los secretos de la aplicación de Microsoft Entra seleccionada.
  • 2 extensiones de página: Página tipo lista y card de las aplicaciones de Microsoft Entra «AAD Application»
  • 3 codeunits: Gestión de la API de Microsoft Graph, la gestión de la notificación y la gestión de los secretos y sus fechas de vencimiento.

La codeunit principal es la «GDRAADAplicationSecrets», es la que verifica cada Aplicación de Microsoft Entra, y actualiza la tabla con los secretos y sus fechas, los verifica comparándolo con la fecha actual. La actualización se ejecuta en la suscripción del evento «onAfterLogin». Y en los eventos de abrir la página de la aplicación de Microsoft Entra se encuentra el análisis para activar la notificación.

Configuración en Business Central

La configuración de la API la completamos con los datos del tenant, cliente ID y el secreto.

En la lista y la página de Aplicaciones de Microsoft Entra, tenemos 2 botones, uno para ejecutar el proceso de manera manual, y el otro nos permite ver el detalle de los secretos de la aplicación seleccionada.

Seleccionamos las aplicaciones de Microsoft Entra que requerimos revisar.

Como en otras oportunidades, la primera vez que ejecutamos el proceso nos solicita el permiso para realizar este tipo de llamadas externas.

Verificación de la caducidad de los secretos

Usaremos el siguiente API de Microsoft Graph:

https://graph.microsoft.com/v1.0/applications(appId='<appID>')

El cual nos trae mucha información, pero nos enfocaremos en los relacionados a «passwordCredential» y específicamente a los valores de «endDateTime».

En Business Central, el detalle de los secretos de cliente los veremos de la siguiente manera.

Si alguno de los secretos está a 1 mes de vencer, se marcará de color rojo.

Y adicionalmente veremos una notificación en la lista y en la ficha que nos indica que tenemos secretos cerca a expirar. Y nos permite acceder al Portal de Azure.

De esta manera, podemos gestionar el vencimiento de los secretos de clientes de las aplicaciones de Azure y evitar encontrarnos con problemas en las integraciones de otras soluciones con Business Central.

Espero que esta información te ayude.


Azure App Registration Client Secrets Expiring? 🔐⌛

Usually, when you need to connect to Business Central from another application, you need to use REST APIs, whether they are built-in APIs or custom APIs.

The way to connect and authenticate to the APIs would be using Microsoft Entra ID authentication against the common API endpoint.

https://api.businesscentral.dynamics.com/v2.0/<environment name>/api/v2.0

Likewise, for scenarios where integrations are required to run without any user interaction, we will rely on S2S.

Identification of the expiration of client secrets of Microsoft Applications Entra

The objective would be to keep track of the expiration of the secrets of the Microsoft Entra applications that interact with our solution, from Business Central.

We will achieve this goal, relying on an API exposed by Microsoft Graph, which allows us to identify the creation and expiration date of the client secret.

We will extend the Microsoft Enter Applications pages in Business Central in such a way that it allows us to identify which applications I want to control and a notification is enabled that notifies us one month (1) in advance if a secret is about to expire. Next, we will see how we can achieve it.

Microsoft Graph integration setup

We create the application, and we create a client secret, for which we configure a validity period.

Then, we go to the API permissions option and we will configure the Microsoft Graph, to which we will assign the application permissions.

We select the Application.Read.All permission.

We select the option to grant administrator consent.

We proceed to test the Microsoft Graph token obtaining API.

https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token

Solution proposal in Business Central

As I have indicated, we will rely on the following Microsoft Graph APIs:

The solution includes the following objects:

  • 2 tables: API configuration, detail of client secrets that connect to the Microsoft Entra application.
  • 1 table extension: Additional field in the AAD application table, indicating that this application and its client secrets should be reviewed.
  • 2 pages: API configuration, detail of client secrets that connect to the Microsoft Entra application.
  • 2 page extensions: List type page and card type page of Microsoft Entra Applications, new field is added. And 2 buttons are added, one button is used to test the solution and the other button allows you to see the details of the client secrets.
  • 3 codeunits: Microsoft Graph API setup, notification management and secrets and their expiration dates management.

The main codeunit is the «GDRAADAplicationSecrets», it is the one that verifies each Microsoft Entra Applications, and updates the table with the secrets and their dates, verifies them by comparing it with the current date. The update is executed on the subscription of the «onAfterLogin» event. And in the events of opening the Microsoft Entra application page, the validity of the client secrets is analyzed, and a notification is enabled.

Settings in Business Central

We complete the API configuration with the tenant data, client ID and the secret.

In the Microsoft Entra Applications pages, we have 2 buttons, one to execute the process manually, and the other allows us to see the details of the secrets of the selected application.

We select the Microsoft Entra Application that we want to review.

As on other occasions, the first time we run the process it asks us for permission to make this type of external calls.

Verification of expiration of secrets

We will use the following Microsoft Graph API:

https://graph.microsoft.com/v1.0/applications(appId='<appID>')

Which brings us a lot of information, but we will focus on those related to «passwordCredential» and specifically to the «endDateTime» values.

In Business Central, we will see the details of the client secrets as follows.

If any of the secrets are 1 month away from expiring, they will be marked red.

And additionally we will see a notification that tells us that we have secrets about to expire. And it allows us to access the Azure Portal.

This way, we can manage the expiration of client secrets for Azure applications and avoid running into issues with integrations with other Business Central solutions.

I hope this information helps you.


Más información / More information:

Deja un comentario