javascriptazure-active-directoryadal.jsazure-data-catalog

Access token getting 401 from Adal.JS for Azure Data Catalog


I am building an angular web application using ADAL.js that accesses other Azure APIs and I am successful in accessing custom web API, Power BI API, and the Graph API. Unfortunately I am unable to access the Azure Data Catalog, I am acquiring the token like all the other services by requesting by resource URI. I have added the users and the app service principal name as Catalog Users and the app registration has Azure Data Catalog delegated access. Below is the code that I use to get the token and then I attach it to the header like I do for the other APIs. This is the only Azure API I have had problems accessing. Thanks in advance if anyone is able to help.

var token = authContext.acquireToken('https://api.azuredatacatalog.com')

Solution

  • If you want to call the Azure Data Catalog rest api with adad.js, please refer to the following steps

    1. Register an Azure AD application

    2. Configure permissions enter image description here

    3. Code

    var resource ="https://api.azuredatacatalog.com"
    authContext.acquireToken(resource, function (error, token) {
    
                // Handle ADAL Error
                if (error || !token) {
                    printErrorMessage('ADAL Error Occurred: ' + error);
                    return;
                }
    
                // Get TodoList Data
                $.ajax({
                    type: "GET",
                    url: "https://api.azuredatacatalog.com/catalogs/{catalog_name}/search/search?api-version={api-version}&searchTerms={search_terms}",
                    headers: {
                        'Authorization': 'Bearer ' + token,
                    },
                });