Reputation: 11
I have a background application which is supposed to connect to Data Catalog and fetch information related to a table. Since its a background application, I cannot have any user intervention to authenticate the Data Catalog request. So I am trying to authenticate using ClientID and ClientSecret instead.
string authorityUri = "https://login.microsoftonline.com/{adtenanthere}";
string resourceUri = "https://datacatalog.azure.com";
string clientId = "{clientidhere}";
string clientSecret = "{clientsecrethere}";
AuthenticationContext authContext1 = new AuthenticationContext(authorityUri, false);
ClientCredential credential = new ClientCredential(clientId, clientSecret);
AuthenticationResult authResult = authContext1.AcquireTokenAsync(resourceUri, credential).Result;
string token = authResult.CreateAuthorizationHeader();
Getting the token using this method is being successful, however when I use this token for the Data Catalog API request, the request returns "401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials you supplied".
Please suggest what I could be missing here!
Upvotes: 1
Views: 702
Reputation: 607
First Check Your Application Permission in Azure Ad Permission. I was check No permission in Application Azure data catalog. So, you must access using user credentials.below see the images
Application permission is based on client credentials. the delegate permission based on login user permission.
you should need without login popup you must pass the user credentials
in authContext1.AcquireTokenAsync
directly.
So, Change and Check the you not get 401 Unauthorized
I think it's help for you.
Upvotes: 0
Reputation: 29
Some data is incorrect, here are the correct values:
string authorityUri = "https://login.windows.net/common/oauth2/authorize"; string resourceUri = "https://api.azuredatacatalog.com";
Hope this helps, Monica
Upvotes: -1