Tuesday, March 12, 2024

Get Graph Id of folder or file in SharePoint Online UI without code

Often when we work with SharePoint Online via its APIs we will encouter situations to know the Graph id of documents or folders. Mainly when we want to debug our automation code or any code written aginst Graph API. The Graph Id is currently not displayed anywhere in the UI. This video shows how can we get the Graph Id of a document from UI or without writing code.

Urls used in the video

https://vermarajneesh.sharepoint.com/sites/DataSite/_api/web/GetFolderByServerRelativeUrl('/sites/DataSite/Important%20Files/')

https://vermarajneesh.sharepoint.com/sites/DataSite/_api/web/GetFileByServerRelativeUrl('/sites/DataSite/Important%20Files/Project01/tracker.xlsx')/ListItemAllFields

https://vermarajneesh.sharepoint.com/sites/DataSite/_api/web/GetFileByServerRelativeUrl('/sites/DataSite/Important%20Files/Project01/tracker.xlsx')/ListItemAllFields/File?$select=VroomItemId

References

VroomId added - https://devblogs.microsoft.com/microsoft365dev/new-sharepoint-csom-version-released-for-sharepoint-online-august-2020/

Monday, February 12, 2024

[Video] Azure @ Enterprise - Adding reference line to App Insights charts

We may present KQL-generated charts to managers to show that the production is working fine, especially to show the system responds to web requests within time. If the managers are still hands-on they easily understand whether this report looks good. Sometimes particular projects may have higher performance standards than the industry standards. Also, there may be more complex metrics than just the request response time. In all these situations it is better to add a reference line to show when it is considered a problem.

Here is the way to add such a line in a short video

https://youtube.com/shorts/Vpk7L6KY2Eo?si=z7Tkts_dsek4kPam

Tuesday, January 16, 2024

Azure @ Enterprise - Postman to simulate api to api on behalf of flow

Often we encounter situation where we have one web api that needs to call another api as the incoming user. Basically our web api needs to impersonate the user to the next downstream api. Below goes the official diagram¹ from Microsoft.

Let us call the Web API A as middle tier API and Web API B as down stream api. Here we assume our application is an Angular web app.

Coding that auth flow is little complex. Before coding it is always good to understand how this can be done using Postman.

This require setting up Azure app registrations which are tricky to many developers. So we will detail those out. A glance of sample setup is below

  • Application
    • App registration (aad-testapp/b34ade37-*)
      • This app registration should have Postman's redirect url "https://oauth.pstmn.io/v1/callback"
      • This needs to have secret to be used from Postman
      • This should have permission to call aad-testapi1 with admin consent to avoid runtime individual user consent.
  • Middle tier web api (Web API A)
    • App registration (aad-testapi1/b6d5852b-*)
      • This should have secret to be used while asking for ob behalf of token
      • This should have permission to call aad-testapi2 with admin consernt to avoid runtime user consent.
  • Downstream api (Web API B)
    • App registration - (aad-testapi2/67d35db8-*)
      • No need to have certificates or secrets as this is not getting any token.
      • The expose and API section to have the aad-testapi1 to authorize and to avoid any consent
Once we have the above mental model, it would be easy to understand the relations. Below goes the screenshots for the above.

App registration for application (aad-testapp)




App registration for Middle tier api(aad-webapi1)

App registration for down stream api(aad-webapi2)


Now let us get into business of getting tokens

Getting First token A

This token is to talk between the client app and the middle tier API. This cane be done as normal way² in Postman.
We can use any url as we are not really making call to this web api. This token is used to obtain the ob behalf of token so that we can call the downstream api.

Set the Authorization to OAuth 2.0.
Now in the configure new token give the details as follows.

Here below 3 fields may attract queries. 

Let us details it, if the screenshot is not enough.

  • Auth Url - The url that ends with /authorize.
  • Access Token Url - The url that ends with /token.

These 2 urls can be seen if we take fiddler traces when the token is requested from Postman.

  • Scope - the scope to the aad-webapi1.
Once the values are set, click on the 'Get New Access Token' button. This will open a browser and ask for login. Once it is success it will redirect to the https://oauth.pstmn.io/v1/callback which will show a popup in browser to open Postman again. If all that is success Postman will show the new token.

This token we will be using as assertion in next step.

Getting on behalf of token B

Now we simulated the Angular client getting the token and it will be sending that in Authorization header. Let us simulate how the middle tier API going to get the on behalf of token using this token.

The url we are using is the normal token url of the tenant.
  • grant_type - no idea why it needs to be this string. It is as per the docs³. We normally expect this to be 'on_behalf_of', but it is not.
  • requested_token_use - here comes the word 'on_behalf_of'
  • client_id - is the id of middle tier app registration
  • client_secret - created in middle tier app registration
  • scope - poining to downstream api
  • assertion - this is the incoming token to middle tier api from the client application.
When we are coding in .Net we can use X509 certificate instead of client_secret
Click 'Send' button to get new token. This token can be used to call the downstream api.

Reference