Managed Identity Authority

Modified on Wed, 13 Aug at 4:23 PM

Table of content

Introduction

This document provides an example of how to authenticate to ILAP Analytics using Microsoft Identity platform.


To learn more about Microsoft Identity platform, please refer to the official documentation here.


Intended audience

This document is intended for Developers with knowledge in:

  • Entra Id
    • Application registrations
    • Managed identities
  • C# and .Net


Prerequisites

To use managed identity, your application needs to be registered in Entra as an app registration and you need to either add a client secret or a certificate to use for authentication in Entra.


Furthermore, your application needs to be assigned permissions to use Ilap Analytics as an Api. To set this up, you will require permissions to do so in you Corporate Entra.


For this document, we assume that the app has been registered with a client secret. For production, use of certificates are recommended and replaces the client secret. This guide is using Promineo Beta environment hosted at https://app-ilapanalytics-api-beta.azurewebsites.net. You need to replace this with the FQDN of your installation of ILAP Analytics Api.


App registration

Create an app registration for your new app.



Make a note of Tenant Id, Client Id and Object Id, this is required to configure the sample application.



Click on "Add a certificate or secret"



Click on "New Secret"



The name of the secret is not important but should make sense to you. You may change the expiry date of the secret if allowed by your corporate policies. This secret will be used as the password for the managed identity. Keep it safe.



Make sure to copy the secret as you need it to configure the sample application. It will not be displayed again.


Click on "API Permissions" and then on "Add a permission"



Find your ILAP Analytics Api app registration and select it



Click on "Application permissions" to allow your application to access Ilap Analytics



Select "DataReader" in the list and click "Add permissions". Note: if you are writing an app that will update information in Ilap Analytics, chose "DataWriter".




Click on "Grant Admin consent for {Your organization}" to grant access for application



You are now ready to configure your application and test it out.


Console app

The example app is based on a sample app from Microsoft, official git repository is here
Daemon means that it runs on behalf of itself, no user is required.


Files in the example

FileDescription
Cli.csprojProject file, refer to that file to build the application
Program.csProgram code, contains all the code required to run the application and authenticate to Ilap Analytics


The example is meant to be as simple as possible and keeps the information regarding authentication in Program.cs. This is not recommended for use beyond simple testing.

Source code for the example can be downloaded from here


Code

Program.cs

Based on our app registration above, this is how the sample needs to be configured. The client secret has been shortened for brevity and security.


Using Microsoft.Identity.Client;
using Microsoft.Identity.Web;
using System.Net.Http.Headers;
using System.Text.Encodings.Web;
using System.Text.Json;

var config = new {
// Full directory URL, in the form of https://login.microsoftonline.com/<tenant_id>
Authority = " https://login.microsoftonline.com/e8ddb777-121f-4abc-a113-6b91d4b5defc",
// Enter the client ID obtained from the Microsoft Entra admin center
ClientId = "e8d0159f-3df0-4b5a-8e5a-3d0d35bdd330",
// Client secret 'Value' (not its ID) from 'Client secrets' in the Microsoft Entra admin center
ClientSecret = "Qc68Q~Za2uZ38...",
// Client 'Object ID' of app registration in Microsoft Entra admin center - this value is a GUID
ClientObjectId = "409c9b95-8fcf-4319-8593-86b0c3913bf1"
};

// This app instance should be a long-lived instance because
// it maintains the in-memory token cache.
IConfidentialClientApplication msalClient = ConfidentialClientApplicationBuilder.Create(config.ClientId)
.WithClientSecret(config.ClientSecret)
.WithAuthority(new Uri(config.Authority))
.Build();

msalClient.AddInMemoryTokenCache();

string[] scopes = {
"api://5f9d20ce-8ac7-4115-80a7-2f1b2acd7bda/.default" //Note that "Reader" has been replaced by ".Default"
};

const string ilapAnalyticsUrl = "https://app-ilapanalytics-api-beta.azurewebsites.net/";

AuthenticationResult msalAuthenticationResult = await msalClient.AcquireTokenForClient(scopes).ExecuteAsync();

var httpClient = new HttpClient();

//Send a request to Ilap Analytics to GET all ReportScheduleTypes

using var request = new HttpRequestMessage(HttpMethod.Get, `${ilapAnalyticsUrl}/api/ReportScheduleType`);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", msalAuthenticationResult.AccessToken);
var graphResponseMessage = await httpClient.SendAsync(request);
graphResponseMessage.EnsureSuccessStatusCode();

//Write the response as JSON Formatted text to the Console
using var graphResponseJson = JsonDocument.Parse(await graphResponseMessage.Content.ReadAsStreamAsync());
Console.WriteLine(JsonSerializer.Serialize(graphResponseJson, new JsonSerializerOptions { WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }));


Output from Program

The response shown is truncated but may vary as is is dependent of the amount of data stored in your Ilap Analytics application


[
  {
    "planningLevel": 1,
    "planningLevelText": "Level 1",
    "title": "Schedule type MHL _edited",
    "receivedFromSchedule": false,
    "description": "My test schedule type",
    "timesInUse": 2,
    "numberOfActivityMetadataFields": 0,
    "numberOfReportScheduleMetadataFields": 2,
    "reportSchedules": [],
    "metadataFields": [
      {
        "ilapId": "R-5230ffe6-be9e-4b71-900f-edd69f574a0c",
        "isVisible": true,
        "name": "OG_Act_ISO_PBSCode",
        "description": "Physical Breakdown Structure: Hierarchical structure of SCCS (Standard Cost Coding System) that defines the types of physical asset components of field installations being delivered by the activity",
        "receivedFromSchedule": false,
        "validationRequirement": 0,
        "validationRequirementText": "None",
        "planningObjectTypes": 2,
        "type": 18,
        "iri": "http://ilap.org/community/oilandgas/R-5230ffe6-be9e-4b71-900f-edd69f574a0c",
        "metadataFieldValues": [
          {
            "metadataFieldId": 4,
            "type": 0,
            "value": "K",
            "stringValue": "K",
            "id": 4,
            "created": "2023-10-30T12:47:48.42Z"
          },
          {
            "metadataFieldId": 4,
            "type": 18,
            "value": "AAD",
            "stringValue": "AAD",
            "lastModified": "2023-12-04T12:28:29.3366667Z",
            "id": 5,
            "created": "2023-12-04T12:28:29.3366667Z"
          },
          {
            "metadataFieldId": 4,
            "type": 18,
            "value": "K",
            "stringValue": "K",
            "creatorId": 2,
            "creatorName": "Mahedi Hasan",
            "lastModified": "2023-12-07T10:55:18.2133333Z",
            "lastModifierId": 2,
            "lastModifierName": "Mahedi Hasan",
            "id": 9,
            "created": "2023-12-07T10:55:18.2133333Z"
          },
          {
            "metadataFieldId": 4,
            "type": 18,
            "value": "Do nothing ",
            "stringValue": "Do nothing ",
            "creatorId": 4,
            "lastModified": "2024-07-08T04:09:59.8933333Z",
            "lastModifierId": 4,
            "id": 36,
            "created": "2024-07-08T04:09:59.8933333Z"
          }
        ],
        "usedBy": "Schedule",
        "id": 4,
        "created": "2023-10-30T12:47:48.0766667Z"
      },
      {
        "ilapId": "R-7b2fcd79-be1b-4d02-8647-af61294efdcd",
        "isVisible": true,
        "name": "OG_Act_ISO_SABCode",
        "description": "Standard Activity Breakdown structure: Hierarchical structure of SCCS (Standard Cost Coding System) that defines the type of activity that is being performed",
        "receivedFromSchedule": false,
        "validationRequirement": 2,
        "validationRequirementText": "ValueInListOrBlank",
        "planningObjectTypes": 2,
        "type": 18,
        "iri": "http://ilap.org/community/oilandgas/R-7b2fcd79-be1b-4d02-8647-af61294efdcd",
        "metadataFieldValues": [],
        "usedBy": "Schedule",
        "id": 5,
        "created": "2023-10-30T12:47:48.0766667Z"
      }
    ],
    "creatorId": 2,
    "creatorName": "Mahedi Hasan",
    "lastModified": "2023-12-04T12:57:44.0070184Z",
    "lastModifierId": 2,
    "lastModifierName": "Mahedi Hasan",
    "id": 2,
    "created": "2023-12-04T12:26:43.5966667Z"
  },
  {
    "planningLevel": 2,
    "planningLevelText": "Level 2",
    "title": "Test type",
    "receivedFromSchedule": false,
    "timesInUse": 3,
    "numberOfActivityMetadataFields": 2,
    "numberOfReportScheduleMetadataFields": 1,
    "reportSchedules": [],
    "metadataFields": [
      {
        "ilapId": "R-72ef6abf-4b66-4070-ac1e-64cfb41136c6",
        "isVisible": true,
        "name": "OG_Act_Phase",
        "description": "Phase code (identification is solved in a different way)",
        "receivedFromSchedule": true,
        "validationRequirement": 0,
        "validationRequirementText": "None",
        "planningObjectTypes": 8,
        "type": 18,
        "iri": "http://ilap.org/community/oilandgas/R-72ef6abf-4b66-4070-ac1e-64cfb41136c6",
        "metadataFieldValues": [
          {
            "metadataFieldId": 2,
            "type": 0,
            "value": "K",
            "stringValue": "K",
            "id": 2,
            "created": "2023-10-30T12:47:48.42Z"
          },
          {
            "metadataFieldId": 2,
            "description": "",
            "type": 18,
            "value": "P1",
            "stringValue": "P1",
            "creatorId": 2,
            "creatorName": "Mahedi Hasan",
            "lastModified": "2023-12-11T11:29:15.87Z",
            "lastModifierId": 2,
            "lastModifierName": "Mahedi Hasan",
            "id": 35,
            "created": "2023-12-11T11:29:15.87Z"
          }
        ],
        "usedBy": "Activity",
        "lastModified": "2023-12-11T11:29:15.8690097Z",
        "lastModifierId": 2,
        "lastModifierName": "Mahedi Hasan",
        "id": 2,
        "created": "2023-10-30T12:47:48.0766667Z"
      },
      {
        "ilapId": "R-5230ffe6-be9e-4b71-900f-edd69f574a0c",
        "isVisible": true,
        "name": "OG_Act_ISO_PBSCode",
        "description": "Physical Breakdown Structure: Hierarchical structure of SCCS (Standard Cost Coding System) that defines the types of physical asset components of field installations being delivered by the activity",
        "receivedFromSchedule": false,
        "validationRequirement": 0,
        "validationRequirementText": "None",
        "planningObjectTypes": 2,
        "type": 18,
        "iri": "http://ilap.org/community/oilandgas/R-5230ffe6-be9e-4b71-900f-edd69f574a0c",
        "metadataFieldValues": [
          {
            "metadataFieldId": 4,
            "type": 0,
            "value": "K",
            "stringValue": "K",
            "id": 4,
            "created": "2023-10-30T12:47:48.42Z"
          },
          {
            "metadataFieldId": 4,
            "type": 18,
            "value": "AAD",
            "stringValue": "AAD",
            "lastModified": "2023-12-04T12:28:29.3366667Z",
            "id": 5,
            "created": "2023-12-04T12:28:29.3366667Z"
          },
          {
            "metadataFieldId": 4,
            "type": 18,
            "value": "K",
            "stringValue": "K",
            "creatorId": 2,
            "creatorName": "Mahedi Hasan",
            "lastModified": "2023-12-07T10:55:18.2133333Z",
            "lastModifierId": 2,
            "lastModifierName": "Mahedi Hasan",
            "id": 9,
            "created": "2023-12-07T10:55:18.2133333Z"
          },
          {
            "metadataFieldId": 4,
            "type": 18,
            "value": "Do nothing ",
            "stringValue": "Do nothing ",
            "creatorId": 4,
            "lastModified": "2024-07-08T04:09:59.8933333Z",
            "lastModifierId": 4,
            "id": 36,
            "created": "2024-07-08T04:09:59.8933333Z"
          }
        ],
        "usedBy": "Schedule",
        "id": 4,
        "created": "2023-10-30T12:47:48.0766667Z"
      },
      {
        "ilapId": "R-69a44f84-e77b-424a-aec3-65a602c54754",
        "isVisible": true,
        "name": "OG_Act_SiteLocation",
        "description": "Test",
        "receivedFromSchedule": true,
        "validationRequirement": 0,
        "validationRequirementText": "None",
        "planningObjectTypes": 8,
        "type": 18,
        "iri": "http://ilap.org/community/oilandgas/",
        "metadataFieldValues": [
          {
            "metadataFieldId": 10,
            "description": "",
            "type": 18,
            "value": "T",
            "stringValue": "T",
            "creatorId": 2,
            "creatorName": "Mahedi Hasan",
            "lastModified": "2023-12-07T11:11:18.8666667Z",
            "lastModifierId": 2,
            "lastModifierName": "Mahedi Hasan",
            "id": 10,
            "created": "2023-12-07T11:11:18.8666667Z"
          },
          {
            "metadataFieldId": 10,
            "description": "",
            "type": 18,
            "value": "Onshore",
            "stringValue": "Onshore",
            "creatorId": 2,
            "creatorName": "Mahedi Hasan",
            "lastModified": "2023-12-07T11:12:23.5733333Z",
            "lastModifierId": 2,
            "lastModifierName": "Mahedi Hasan",
            "id": 11,
            "created": "2023-12-07T11:12:23.5733333Z"
          },
          {
            "metadataFieldId": 10,
            "description": "",
            "type": 18,
            "value": "Offshore",
            "stringValue": "Offshore",
            "creatorId": 2,
            "creatorName": "Mahedi Hasan",
            "lastModified": "2023-12-11T04:39:23.09Z",
            "lastModifierId": 2,
            "lastModifierName": "Mahedi Hasan",
            "id": 28,
            "created": "2023-12-11T04:39:23.09Z"
          }
        ],
        "usedBy": "Activity",
        "creatorId": 2,
        "creatorName": "Mahedi Hasan",
        "lastModified": "2023-12-11T04:39:23.0921728Z",
        "lastModifierId": 2,
        "lastModifierName": "Mahedi Hasan",
        "id": 10,
        "created": "2023-12-07T11:11:18.8633333Z"
      }
    ],
    "creatorId": 2,
    "creatorName": "Mahedi Hasan",
    "lastModified": "2023-12-07T11:19:04.2231007Z",
    "lastModifierId": 2,
    "lastModifierName": "Mahedi Hasan",
    "id": 4,
    "created": "2023-12-07T10:53:02.23Z"
  }
]

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article