Andy Mathews
Andy Mathews

Reputation: 11

Application Token based Request returning not 401 Unauthorized

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

Answers (2)

umasankar
umasankar

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.

enter image description here

enter image description here

So, Change and Check the you not get 401 Unauthorized

I think it's help for you.

Upvotes: 0

Monica
Monica

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

Related Questions