Is there a way to register a data asset in Azure Data Catalog via api without user-login?

182 views Asked by At

My app gets a token and can make api calls to the ADC like searching. But the request for registration of new asset fails, because the field "LastRegisterdBy" must not be null/empty and has to correspond to current user. However the token does not contain any user information (AccessToken().Result.UserInfo.DisplayableId is null).

I mostly followed the get started get-started project MS provides (https://github.com/Azure-Samples/data-catalog-dotnet-get-started/blob/master/Program.cs)

But i use

AcquireTokenAsync(resourceUri, clientCredential).ConfigureAwait(false)

instead of

AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Always)).

This so nobody has to enter his credentials. The goal is to run the code in ssis package, which will execute on a weekly basis to catch any updates in the data automatically.

This is the outline of my code:

    class Program
        {
            static string clientIDFromAzureAppRegistration = "";
            static string clientSecret = "";
            static AuthenticationResult authResult = null;
            static string catalogName = "catalog";
            static void Main(string[] args)
            {
                var authResult = AccessToken();
                string upn = authResult.Result.UserInfo.DisplayableId;
                var id = RegisterDataAsset(authResult, SampleJson("test", upn));
            }
                static async Task<AuthenticationResult> AccessToken()
        {
            if (authResult == null)
            {
                //Resource Uri for Data Catalog API
                string resourceUri = "https://api.azuredatacatalog.com";

                //To learn how to register a client app and get a Client ID, see https://msdn.microsoft.com/en-us/library/azure/mt403303.aspx#clientID   
                string clientId = clientIDFromAzureAppRegistration;
                string clientS = clientSecret;

                // Create an instance of AuthenticationContext to acquire an Azure access token

                var authority = "https://login.microsoftonline.com/52497ec2-0945-4f55-8021-79766363dd96";
                var authContext = new AuthenticationContext(authority);
                var clientCredential = new ClientCredential(clientId, clientS);

                // Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint
                //  AcquireToken takes a Client Id that Azure AD creates when you register your client app.
                authResult = await authContext.AcquireTokenAsync(resourceUri, clientCredential).ConfigureAwait(false);
            }
            return authResult;
        }

     static string RegisterDataAsset(Task<AuthenticationResult> authResult, string json){
    ...
    }
    static HttpWebResponse SetRequestAndGetResponse(HttpWebRequest request, Task<AuthenticationResult> authResult, string payload = null){
    ...
    }
    static string SampleJson(string name, string upn){
    ...}

With upn = authResult.Result.UserInfo.DisplayableId; i get:

{"error":{"code":"InvalidPropertyValue","message":"Invalid input value for one of the properties. Path: 'properties.lastRegisteredBy.upn'. Details: Value cannot be null, empty or consists entirely of whitespaces."}}

Wit upn = "test@user":

{"error":{"code":"InvalidLastRegisteredBy","message":"LastRegisteredBy is different from the current user."}}

1

There are 1 answers

0
rollersim On BEST ANSWER

I found the solution, its quite simple:

The user-name of the app is: clientIDFromAzureAppRegistration + "@" + tenantId.