Application Insights - user_AuthenticatedId to Azure UPN - azure

I have hooked up a Power App to Azure Application Insights to track useage.
When the events are logged, the user ID is recorded with the Azure Active Directory ID (a Guid).
Whilst I can interrogate AAD for the user ID manually to get the UPN, is there any way in the App Insights Data Explorer to map the user ID to the UPN.
pageViews
| where timestamp > datetime(2021-02-04 14:30:00)
| project user_AuthenticatedId, '[UPN]'

Unfortunately, short answer is no for default telemetry like page view. Inbuilt telemetry does not capture any PII for data compliance (for example, UPN user#example.com reveals the user email).
However, you can write custom trace to capture that. Example:
Trace(
"App Feedback",
TraceSeverity.Information,
{
UserName: User().FullName,
UserEmail: User().Email
}
);
Note: If you are logging any personnel data, you will need to consider any data compliance obligations, such as GDPR, that you might also need to implement.
For details, refer Analyze app telemetry using Application Insights.

Well, it was a bit of a round-a-bout way of doing this, but I created a Power Automate flow using various HTTP REST calls.
Firstly, I pulled the list of User IDs from App Insights using the REST Api with a query and then cycled over the response making HTTP requests to the MS Graph API requesting the user information.
It needed an Azure App Registration with appropriate security access to call into Graph but it was a simple task end the end.

Related

Azure AD: Send welcome email when user is assigned to the application

I would like to send a welcome email to the user when the Azure AD admin assigns the user to the application (enterprise or custom). It would be nice to use a custom template to define an access URL and maybe some additional info (how to use, some rules, etc.). I haven't found anything similar in the Azure portal.
Does Azure AD provide such functionality? Or should I build custom implementation (Graph API, EventGrid + Azure Functions, SCIM protocol, etc.)?
From what I understand, at the very base, you want an email to be sent whenever a user is assigned to an enterprise application (or custom - assuming that also falls under same). I assume you do not need to know much about who actually assigned the permissions. Either way, with the query below you should have enough to get going.
As far as I know there's no native support for this in AD (I couldn't find anything at all that's available but I could be wrong) but a workaround for us was to do it using Log Analytics + Azure Logic App. While our use case is slightly different (we use it to monitor and be alerted for logins to a specific account), the same logic might apply to you - I put together a few lines to query log analytics. but I couldn't get the alert part working - Azure could just be sleepy right now.
EDIT: Alert worked the following day. Just needed some time to warm up I guess.
Give it a try:
Make sure Azure AD has diagnostic settings configured to send logs to a Log Workspace
Query the workspace using the following:
AuditLogs
| where TimeGenerated > ago(5m) //Change as required
| where ActivityDisplayName has "Add app role assignment grant to user"
| project Time = TimeGenerated, Activity = ActivityDisplayName, Application=parse_json(TargetResources)[0].displayName, User=parse_json(TargetResources)[1].userPrincipalName
| where Application contains "myapp"
Create an alert from Log Analytics (hopefully you get it working right away - each alert cost USD 1.50/month).
(a) You will need to create an Action Group
(b) Under Action Group, configure your email in the Notifications.
(c) You will need to come back to reconfigure an Action field to the Logic App you will create below.
Create a Logic App and start with an HTTP connector as the trigger to receive the content in JSON format.
Setup a Send an Email (v2) action with all variables and such, or another connector if applicable in your case. Customise the email in HTML
One alternative to using Log Analytics and Alerts could also be to use PowerShell to query AAD logs and then parse the information to Logic App through the HTTP POST Url that shows up when you save the HTTP Connector.
Another alternative to using the HTTP Connector could be to use the O365 connector with trigger When a new email arrives (v3)
Things to consider:
There's at least a 5 minutes delay between the time the event is logged and triggered. This is just the way the alert query works.
You will need to login to Logic App using the mailbox from which you want to send that email. That's something you might want to manage separately - expiring credentials etc.
Hope this gives you some ideas.

How can I detect the user sign up event from Azure API Management?

I've been using Azure API Management recently, and I would like to know if there is a way to detect the sign up process performed from the included Developer Portal.
Basically I need to be able to get the user unique id, to be able to map data stored in a database.
Is configuring Delegation the only way to capture this event?
Try to enable the Resource Logs, it includes the userId.
Reference - https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor#resource-logs

Retrieving user's calendar events in Microsoft graph using application permissions

I'm trying to build a small application that can retrieve a particular user's calendar events without a signed in user, that is to utilize the application permissions in Graph API and query the events by authenticating with App ID, Tenant ID and Secret values. I was able to follow this documentation https://learn.microsoft.com/en-us/graph/auth-v2-service and generate JWT tokens to query the graph API. And it worked fine when i tried to retrieve all the users information, or even retrieve a particular users information using the following paths.
/users
/users/{id | userPrincipalName}
Both the above endpoints worked fine and i was able to retrieve details, but when i tried to access the calendar events of a particular user using the following Graph API path
/users/{id | userPrincipalName}/events
I get the following error,
I'm not sure what i'm doing wrong here, i have the following Application permissions set up in Azure AD Portal and the permissions are reflected in the JWT token.
I feel like the token generation part is working fine since the first two Graph API endpoints i mentioned above are functional, but I'm not sure where else I'm going wrong and as to why I'm not able to retrieve a particular user's calendar events. Any help would be much appreciated.

Getting azure ad users list for specific application with graph api

In the azure graph I have a list of users, some of which can be assigned to enterprise applications(my registered app). How can we get users of a specific application using the graph api(with Postman)?
with this api i get list of all users without depending on application application
https://graph.microsoft.com/v1.0/users
also tried find some information about applications from users license by id, but still no success
POST /users/{id | userPrincipalName}/assignLicense
and from application information
GET /applications/{id}
i have a full stack of permissions for graph api for users, directories, application both for the delegated user and for the application so this is definitely not the problem.
I hope for your help, thanks!
You can use this api below to list all users or groups assigned to an app:
https://graph.microsoft.com/beta/servicePrincipals/{id}/appRoleAssignedTo
For more information about this api, please refer to this tutorial.

API for registering your app to Azure

I am trying to write an app that, upon receiving the credentials of an Azure user, will be able to show him various pieces of information using the Azure billing apis.
However, the following git sample that shows how to use one of those apis, lists a series of steps that should be done in the Azure cloud platform in order for things to work, and these steps need to be done by the user himself. Specifically, step 1 talks about registering an app and configuring it so that it has access and permissions to use the apis.
Only after those steps, will I be able to access the billing apis and retrieve his information.
Seeing as how I don't want the user to have to do anything after he gives me his username and password, is there an API or some other automated way with which I can register my app to view his account?
https://github.com/Azure-Samples/billing-dotnet-usage-api
Ideally, I would want some sort of imaginary code that maybe looks like:
someObj obj = someAPI.loginToAzureWithCredentials("123456", "someUserName")
obj.registerApplication();
Obviously the "code" is very lacking in details, but it's just for emphasizing what I'm searching for.

Resources