Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Are you constantly challenged with keeping up with all your Azure Active Directory Enterprise Application client secrets and certificates and their associated expiration dates?
I sometimes work with customers who have a thousand or more Azure AD applications to manage. Unfortunately, trying to keep up with all the client secrets and certificates expiring on each one of these apps can be a futile experience.
I came up with a solution to this problem by using Power Automate to proactively notify the Azure Active Directory administrators of upcoming client secret and certificate expirations. You can also optionally notify application owners as well, assuming you've defined the owner property on each application. This solution was a big help for customers with thousands of AAD apps to keep track of. I owe a huge thanks to a friend and peer of mine, Norman Drews, for his CSS & HTML expertise.
Here’s how I solved it using Power Automate. If you’d like to download the Power Automate flow and import it into your environment, click here to download it from my Github repository. I have also since the original publishing of this article, worked on creating a Logic Apps version of the same process and have it working well. If you're interested in that instead, visit Use Azure Logic Apps to notify of pending AAD application client secrets and certificate expirations...
PLEASE take a moment to provide your feedback on this solution! https://forms.office.com/r/b7hHXLb7R1
Variable definitions in the Flow
Content of this step:
{
"tableStyle": "style=\"border-collapse: collapse;\"",
"headerStyle": "style=\"font-family: Helvetica; padding: 5px; border: 1px solid black;\"",
"cellStyle": "style=\"font-family: Calibri; padding: 5px; border: 1px solid black;\"",
"redStyle": "style=\"background-color:red; font-family: Calibri; padding: 5px; border: 1px solid black;\"",
"yellowStyle": "style=\"background-color:yellow; font-family: Calibri; padding: 5px; border: 1px solid black;\""
}
11. Initialize variable (String) – html – this creates the table headings and rows that will be populated with each of the Azure AD applications and associated expiration info.
Content of this step:
<table @{variables('styles').tableStyle}><thead><th @{variables('styles').headerStyle}>Application ID</th><th @{variables('styles').headerStyle}>Display Name</th><th @{variables('styles').headerStyle}>Days until Expiration</th><th @{variables('styles').headerStyle}>Type</th><th @{variables('styles').headerStyle}>Expiration Date</th></thead><tbody>
Request token step of the Flow
Retrieve token info JSON schema
The JSON schema to use is as follows:
{
"type": "object",
"properties": {
"token_type": {
"type": "string"
},
"expires_in": {
"type": "integer"
},
"ext_expires_in": {
"type": "integer"
},
"access_token": {
"type": "string"
}
}
}
Do Until loop
The schema for this Parse JSON step is as follows:
{
"type": "object",
"properties": {
"properties": {
"properties": {
"@@odata.context": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"value": {
"properties": {
"items": {
"properties": {
"properties": {
"properties": {
"@@odata.id": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"appId": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"displayName": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"keyCredentials": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"passwordCredentials": {
"properties": {
"items": {
"properties": {
"properties": {
"properties": {
"customKeyIdentifier": {
"properties": {},
"type": "object"
},
"displayName": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"endDateTime": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"hint": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"keyId": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"secretText": {
"properties": {},
"type": "object"
},
"startDateTime": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"required": {
"items": {
"type": "string"
},
"type": "array"
},
"type": {
"type": "string"
}
},
"type": "object"
},
"type": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"required": {
"items": {
"type": "string"
},
"type": "array"
},
"type": {
"type": "string"
}
},
"type": "object"
},
"type": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"type": {
"type": "string"
}
}
}
ForEach apps loop
ForEach passwordCreds loop
div(div(div(mul(sub(outputs('EndTimeTickValue'),outputs('StartTimeTickValue')),100),1000000000) , 3600), 24)
<tr><td @{variables('styles').cellStyle}><a href="https://ms.portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Credentials/appId/@{variables('appId')}/isMSAApp/">@{variables('appId')}</a></td><td @{variables('styles').cellStyle}>@{variables('displayName')}</td><td @{if(less(variables('daystilexpiration'),15),variables('styles').redStyle,if(less(variables('daystilexpiration'),30),variables('styles').yellowStyle,variables('styles').cellStyle))}>@{variables('daystilexpiration')} </td><td @{variables('styles').cellStyle}>Secret</td><td @{variables('styles').cellStyle}>@{formatDateTime(item()?['endDateTime'],'g')}</td></tr>
<tr><td @{variables('styles').cellStyle}><a href="https://ms.portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Credentials/appId/@{variables('appId')}/isMSAApp/">@{variables('appId')}</a></td><td @{variables('styles').cellStyle}>@{variables('displayName')}</td><td @{if(less(variables('daystilexpiration'), 15), variables('styles').redStyle, if(less(variables('daystilexpiration'), 30), variables('styles').yellowStyle, variables('styles').cellStyle))}>@{variables('daystilexpiration')} </td><td @{variables('styles').cellStyle}>Certificate</td><td @{variables('styles').cellStyle}>@{formatDateTime(item()?['endDateTime'], 'g')}</td></tr>
ForEach Key Credentials loop
Yes branch
End of the flow including send email
And below is the resulting e-mail received when the flow runs on its scheduled time. Included is a hyperlink for each application that takes you directly to where you need to update the client secret and/or certificates for each application within the Azure portal.
Sample e-mail
Now - if you also want to notify the application owners as well, you can add an HTTP get to https://graph.microsoft.com/v1.0/applications/{id}/owners endpoint to query the application owner property of each application. The logic check after Get Secret Owner uses an expression length(body('Get_Secret_owner')?['value']) to see if it is equal to an expression int(0).
If it's True, there's no owner to notify so it just appends "No Owner" to the html variable. If it's not, there's an owner defined, and it will use the UserPrincipalName to build a mailto: hyperlink for the html using the expression body('Get_Secret_Owner')?['value'][0]?['userPrincipalName']
Thanks for reading! And again, PLEASE take a moment to provide your feedback on this solution! https://forms.office.com/r/b7hHXLb7R1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.