0

I am trying to access a service using Azure API management. I have enabled oAuth authentication on top of the service by using API's > Settings > Security and selexting oAuth 2.0. But Even after making this change, I am able to access the endpoints without providing any tokens. Am I missing anything ?

enter image description here

2 Answers 2

0

I did not add the JWT validation policy to pre-authorize requests

To add the policy select Design tab & click on </> icon (for policy code editor) under Inbound Processing & add following code:

<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid.">
    <openid-config url="https://login.microsoftonline.com/{aad-tenant}/v2.0/.well-known/openid-configuration" />
    <required-claims>
        <claim name="aud">
            <value>{backend-app-client-id}</value>
        </claim>
    </required-claims>
</validate-jwt>

enter image description here

After saving it make a new request.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

I hope you have configured JWT policy could you please confirm ? if someone calls your API without a token or with an invalid token? For example, try to call the API without the Authorization header, the call will still go through.

This is because the API Management does not validate the access token, It simply passes the Authorization header to the back-end API.

To pre-Authorize requests, we can use Policy by validating the access tokens of each incoming request. If a request does not have a valid token, API Management blocks it.

reference: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-protect-backend-with-aad#configure-a-jwt-validation-policy-to-pre-authorize-requests

4 Comments

I realized the same few minutes back & added the policy & now i am getting 401 error when testing api. Only question I have is what is aad-tenant is it the client id of client application (not the client id of backend-api/service)?
aad-tenant is where you need to provide your tenant id of your app registration which you get it from the overview page. please refer this blog post techcommunity.microsoft.com/t5/azure-paas-blog/… for troubleshooting similar scenarios
As per this linl learn.microsoft.com/en-us/azure/api-management/… it says A user or application acquires a token from Azure AD with permissions that grant access to the backend-app. does it means I need to register a client app with Azure AD and then make calls to get token? If yes, where can I find that information ?
yes, you're right you need to register your client app with Azure AD please refer this blog which explains everything in detail techcommunity.microsoft.com/t5/azure-paas-blog/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.