Creating Microsoft Entra ID Source Issue

Summary

User is facing issues while creating a Microsoft Entra ID source in an Airbyte instance, with API documentation lacking guidance on the process.


Question

I am trying to create a Microsoft Entra ID source in our Airbyte instance, but I am encountering the following issue. Unfortunately, our API documentation does not provide guidance on how to create an Entra ID source…
airbyte. using Airbyte.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using <http://System.Net|System.Net>.Http;
using <http://System.Net|System.Net>.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace Airbyte.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class EntraController : ControllerBase
{
private static readonly string tenantId = "";
private static readonly string clientId = "";
private static readonly string clientSecret = "";
private static readonly string userId = "";
private const string AirbyteApiUrl = "<http://localhost:8000/api/public/v1>";
public string workspaceId { get; set; } = "2d637d51-f35a-4506-98cc-20b2d6f98ad7";

    `[HttpGet("createEntrasource")]`
    `public async Task&lt;IActionResult&gt; CreateEntraIdSource()`
    `{`
        `try`
        `{`
            `// Get the bearer token for Airbyte API authentication`
            `var Btoken = await GetBearerToken();`
            `if (string.IsNullOrEmpty(Btoken))`
            `{`
                `return new JsonResult(new { error = "Failed to obtain Airbyte access token" }) { StatusCode = 500 };`
            `}`

            `using (var client = new HttpClient())`
            `{`
                `client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Btoken);`

                `// Ensure that the connectionConfiguration is correctly formed`
                `var sourceConfig = new`
                `{`
                    `sourceType = "microsoft-entra-id",`
                    `name = "My Microsoft Entra Source",`
                    `workspaceId = workspaceId,`
                    `connectionConfiguration = new`
                    `{`
                        `client_id = clientId,`
                        `client_secret = clientSecret,`
                        `tenant_id = tenantId,`
                        `user_id = userId,`
                    `}`
                `};`

                `var content = new StringContent(JsonConvert.SerializeObject(sourceConfig), Encoding.UTF8, "application/json");`
                `var response = await client.PostAsync($"{AirbyteApiUrl}/sources", content);`
                `var responseString = await response.Content.ReadAsStringAsync();`

                `if (!response.IsSuccessStatusCode)`
                `{`
                    `// Return error details if the request failed`
                    `return new JsonResult(new { error = "API request failed", details = responseString }) { StatusCode = 400 };`
                `}`

                `// Deserialize the response to obtain the SourceId`
                `var res = JsonConvert.DeserializeObject&lt;Source&gt;(responseString);`
                `return new JsonResult(res.SourceId); // Return the SourceId`
            `}`
        `}`
        `catch (Exception ex)`
        `{`
            `// Log the exception and return a detailed error response`
            `return new JsonResult(new { error = "Failed to create source", message = ex.Message, details = ex.StackTrace }) { StatusCode = 500 };`
        `}`
    `}`

    `[HttpGet("token")]`
    `public async Task&lt;string&gt; GetBearerToken()`
    `{`
        `try`
        `{`
            `string clientId = ""; // Can be made dynamic as well`
            `string clientSecret = ""; // Can be made dynamic as well`

            `if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))`
            `{`
                `return null;`
            `}`

            `using (HttpClient client = new HttpClient())`
            `{`
                `var requestData = new`
                `{`
                    `client_id = clientId,`
                    `client_secret = clientSecret`
                `};`

                `var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json");`
                `var response = await client.PostAsync($"{AirbyteApiUrl}/applications/token", content);`

                `// Ensure that the response is successful`
                `response.EnsureSuccessStatusCode();`

                `var responseBody = await response.Content.ReadAsStringAsync();`
                `dynamic jsonResponse = JsonConvert.DeserializeObject(responseBody);`

                `if (jsonResponse.access_token != null)`
                `{`
                    `return jsonResponse.access_token;`
                `}`

                `return null;`
            `}`
        `}`
        `catch (Exception ex)`
        `{`
            `// Log the exception and return null`
            `return null;`
        `}`
    `}`
`}`

}



This topic has been created from a Slack thread to give it more visibility.
It will be on Read-Only mode here. Click here if you want
to access the original thread.

Join the conversation on Slack

['microsoft-entra-id', 'source-creation', 'api-request', 'bearer-token']