Connecting to Kinetic API from Excel with Azure AD (Organizational Account)

There has been a few topics (mostly by me) regarding connecting to a Kinetic API data source in Excel using AzureAD credentials (aka Organizational Account).
AzureAd credentials to retrieve OData feed from excel
Using Azure Active Directory to Link Kinetic to Excel
The www-Authenicate header doesn’t contain a valid authorization URL header value: Basic ream = Epicor.Ice

I gave it another whirl today and was able to figure it out. There’s not really any documentation for this, so here is mine.

  1. If you haven’t set up AzureAD authentication in Kinetic, go set up that first using the Kinetic documentation.

  2. Go grab a resource (ie BAQ) from the Rest Help page at /Apps/resthelp. For the purpose of this documentation, I’m going to use API v1 so I don’t have to deal with adding API keys to excel. I’ll let v2 be a challenge for another day.

https://<your_sever>/<your_instance>/api/v1/BaqSvc/zAttribute(<your_company>)/'
  1. This is where I was stuck. Previously if I tried to use an organizational account, I would get the following error: “The WWW-Authenticate header doesn’t contain a valid authorization URI. Header value: 'Basic realm='Epicor ICE”

  2. To fix this, go to your Server app registration in Azure portal and add an Application ID URI that matches your server FQDN. The URI value must be a verified domain in Azure. See the following for more information
    Understanding the app manifest (Azure AD Graph format) - Microsoft identity platform | Microsoft Learn
    image

  3. In Azure Active Directory Settings within Kinetic, set the Application ID URI to the same value in Step 4.

  4. Recycle your app pool

  5. Now when you attempt to sign in from Excel, you should be met with the Microsoft account selector. Awesome.
    However, after you authenticate, you will likely get an error “access_denied: AADSTS650057: Invalid resource. The client has requested access to a resource which is not listed in the requested permissions in the client’s application registration. Client app ID: a672d62c-fc7b-4e81-a576-e60dc46e951d(Microsoft Power Query for Excel). Resource value from request: your_server. Resource app ID: your_id. List of valid resources from app registration:”


    image

  6. To fix this, add the Client app ID for Microsoft Power Query for Excel (a672d62c-fc7b-4e81-a576-e60dc46e951d) to the Authorized Client Applications under Expose an API on your app registration. Allow access to the user_impersonation scope. Wait a few minutes for the changes to take effect.

  7. Try to sign in again. Your sign in should be successful :tada:
    image

  8. Go nuts with your data source within Excel

5 Likes

How does this relate, if at all, to @josecgomez 's comment on this thread saying:

Have you effectively mitigated what Jose is saying here? Or, have you allowed “a bumm of the street with access to excel and azure to be able to generate a valid token?”

I’m pretty sure you have mitigated that risk because you’re using Azure to authenticate the user and then authorize the user to connect… does that look right @Mark_Wonsil ?

1 Like

Wow I am going to try it.

3 Likes

Such a cool feeling to use all these azure tools to pull off something like this. Really awesome stuff as always @mbayley!

1 Like

I am not worried. Our azure tenant has MFA and conditional access policies applied. Our server is also not public facing.

This is way better than having Basic auth as the only other alternative option once Windows auth has been disabled.

If we can also pair this with an API key, that would secure access from Excel even more.

2 Likes

I’m hoping my post didn’t come off as judgmental at all or saying “this is unsafe” I was just trying to understand what Jose was saying and what you put in place here and if what you put in place effectively handles the security concern that Jose had. Cause anyone with basic auth creds they phished or guessed or whatever could also get access. This has MFA and paired with API keys is a good duo for limited access. And since it’s azure you could probably even get more granular with other tools about conditional access etc.

Again, incredible contribution to the forum! Thanks for sharing this.

2 Likes

Oh no, not at all. If the experts here see anything unsafe, I’d like to know.

2 Likes

I’m not sure if its “unsafe” but I believe you are authorizing any excel “client” to use this Epicor Azure app. Is that an issue in it of itself? Probably not because you’d have to have a matching Epicor external identity to be a problem (maybe)

But it does mean that technically anyone who uses excel could throw “YOUR” app url in there and it would be “allowed” to use that app to authenticate assuming they can find a matching identity on the other side.

4 Likes

When we set up the client, we usually restrict it only to our own tenant:

image

So that is more restrictive to your own AD Users.

I also see that Entra has a nice utility to check your security settings:

3 Likes

Thanks for clarifying Jose!

Nice Mark, thanks for showing others what they might do to strengthen their security posture.