Limit Client app to access only to a specific web api - azure

We are configuring a new client app in Azure Active Directory to be used to access a specific web api with Client Credential flow by using the App Registration feature. I would ensure that Azure Active Directory will issue the Authz Token only for a specific registered web api (resource), returning an error in case the target client application request a token for a different resource.
So far we have been able to block access to clients for a specific web api, but what we want is to configure AAD so that a specific client id is able to call only a specific web api (let's say, we want to "change the point of view").
Is there a way to configure a client app on azure AD so that it is able to obtain a token only for a specific resource, regardless how we configure other web api on Azure Active Directory?

Your client app may obtain token for different resources but not for non allowed roles (Configured permissions) which are the basis for authorization, not just the token.

Related

Authenticate users with Microsoft without registering an app

I want to authenticate users to my nodejs app via Login with Microsoft but I don't want access to any of their AD data other than read access to email and first name.
I know I have authenticated to apps via my work MS account and that app has not been "registered" in my company's Azure env. I have even used apps that do request access to my Calendar (Graph API) and I can grant it without that app being registered.
How does this work? Is it possible to just use MS as my identity provider for authentication without my app being registered?
In order to authenticate a user, a client ID is required.
This must come from a registered application.
There could be a situation in which another application is just using a client ID of another application (in case redirect URIs are able to match).
In the general case I would say that you must register an application.

Azure Active Directory Oauth 2.0 Client Credentials Flow with API Management Access Token issue

I have had been struggling to make my Azure Active Directory Oauth 2.0 Client Credentials Flow work with API Management. but I get authenticated via postman too. But in return I do not get any access token just a bunch of HTML. How can I fix this? The settings of the applications are exactly as per the documents including the validation of JWT Policy.
Basically I want my client apps to connect with my azure API's using Oauth 2.o without any consent using provided client id/secret. I'm trying to set this up for now with ECHO API provided out of the box with API Management console.
thanks
Postman Access token Error Screen
To use application permissions with your own API (as opposed to Microsoft Graph), you must first expose the API by defining scopes in the API's app registration in the Azure portal. Then, configure access to the API by selecting those permissions in your client application's app registration. If you haven't exposed any scopes in your API's app registration, you won't be able to specify application permissions to that API in your client application's app registration in the Azure portal.
For an example, if I sent scope parameter with custom name like https://testwebapp.in/.default without configuring same as application ID URI in Azure AD then is an expected behavior and you will get error AADSTS500011.
scope parameter in the request should be the resource identifier (application ID URI) of the resource you want, affixed with the .default suffix. For the Microsoft Graph example, the value is https://graph.microsoft.com/.default. This value tells the Microsoft identity platform that of all the direct application permissions you have configured for your app, the endpoint should issue a token for the ones associated with the resource you want to use.
Reference: https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow#application-permissions

In an Azure Web App, can you lock specific routes from being accessed externally?

I have implemented AAD SSO using react-adal for my React application, but all my node REST endpoints are still accessible via external users & resources. Does Azure offer any way of securing these routes so that they can not be accessed by anything other than the application itself?
i.e. block external users from access to example.com/get-users/
but allow the application to still have access to this route.
Thanks!
You must read/define groups that will be allowed to access that particular route, and set it in your app level. Azure AD only authenticate / return the token with user information (including claims).
More info:
https://blog.bitscry.com/2020/04/21/azure-active-directory-group-based-authorization/
Azure AD and Group-based authorization with token in Web API

Securing shared APIs with Azure AD

I'm working with a client to define a security strategy and have got stuck trying to get something working. I'm new to Azure AD so this may actually not be possible.
Consider the following application landscape.
I have 4 "API" applications:
API-A, requires interactive user and role based permissions
API-B, access via service demon, client_credential grant
API-C, must not be authenticated against directly
API-D, access via service demon, client_credential grant
A user / demon authenticated against API-A or API-B should be able to access API-C as well. However the demon authenticated against API-D must not be able to access API-C.
I was expecting to be able to use the "Expose an API" and "API Permissions" of the App Registrations to be able to control to "roles" returned in the JWT, I cannot seem to get it to work or find any decent guide on how this can be achieved.
EDIT: For clarity the API applications are not hosted within Azure, I am just looking to use Azure AD to provide authentication
It may be helpful for you to distinguish between client apps and API apps (or resource servers in OAuth2 lingo). Each of them has to be registered separately. Your list above seems to merge them together, which is a likely source of confusion for you.
The former (client apps) acquire tokens, the latter receive them from the clients with the service request. Authentication is only only involved when client apps acquire tokens. APIs do not authenticate - they use tokens to authorize access to their services. Clients acquire tokens either on behalf of a user - and the user authenticates and consents as part of the process, or on their own behalf (client creds). In AAD an API app may expose/define scopes/permissions which may be included in one or both of these token types. An API may decide not to require any tokens (sounds like your API-C). You Expose (available) Permissions on API apps, you specify (required) API Permissions on client apps. At runtime (if using the AAD V2 endpoint) a client may request fewer scopes than it is is configured with as Required. That applies only if the client is using delegated tokens (user based). (Note that an API app may also be a client app to another API app (common in multi-tier systems).
BTW, where the clients or APIs are deployed is totally immaterial to the above. At most deployment affects the value of the reply url you need to specify for some client apps (not APIs).

How to acquire token in a native client to access a Web API that has been registered for Azure Active Directory?

I have a native client (console app) from where I am trying to access a WebAPI. The API has been authenticated using Azure AAD. So, in order to acquire a token using the method AuthenticationContext.AcquireToken(), ClientCredentials are needed which in turn need the "client secret" that one is supposed to receive from Azure while registering the application to Azure AAD. Is there any other way for me to be able to retrieve the access token to access the WebAPI?
If you want to call the WebAPI on behalf of (or "as") the current user then you can use the Resource Owner Credentials flow. Otherwise, the client credential flow you described is the appropriate solution.
Note that your client app should be registered separately from your WebAPI in AAD.

Resources