In this post, we will look at how to secure an Azure app service with a subscription. We will do this by adding the App Service to Azure API Management.
First, we have an Azure app service like below:
Let’s add this to API Management (APIM). Go to APIM and click Create:
Give the APIM a name, and click Review + Create, then Create:
Now let’s go to our new APIM:
And add our App Service:
Scrolling down in the API settings, we can see Subscription Required:
Now let’s try to access the API through Postman. We can get the URL of the API from the Settings menu:
Sending this through Postman, we get a 401 error, “Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API”:
In APIM, go to Subscriptions, and choose a subscription. I will choose the build-in all access subscription:
You can select one, then Show/Hide Keys to reveal the actual key, then copy they key:
Now in Postman, go to the Headers tab and add a key for Ocp-Apim-Subscription-Key, and paste the key value into the Value section. Then click Send, and we see we get a response from our API:
You have now required your API to provide a subscription.
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL