• 0

Securing an Azure Function App with OAUTH


Question

Hi, I'm looking at building an API in Azure - and that's an immovable, I am bound to Azure here for various reasons.

It seems the best way for me to achieve what I need is to use a Function App, so I've done this and created a very simple Hello World api.  Great... it works, pat on the back - I can follow a tutorial.

And to manage this very simple API, I am going to use an API Management Service - it can handle the traffic management and so on.  So yeah, got that set up too.

I'm a bit confused.  While the API Management Service exposes the API through a specific URL that applies all the benefits of the service, the "raw/native" url of the Function App still exists.  This seems a bit like... easily bypassed and any end user could just go to the original Function App url.  Am I missing something?

Anyhow yeah, so I have this all set up, but I want to secure it with OAUTH so that anyone calling this API has to authenticate and so on.  I believed that Azure API Management Service could do this for me, but I seem to be missing something.

Anyone here setup anything similar and able to guide me a little please?

I'm aware that this comes very close to consultation, so if that's the case, please do also feel free to discuss that via PM.

Thanks

4 answers to this question

Recommended Posts

  • 0

You can secure your Functions by using (and rotating) the App and Function Keys (configured through the Azure Portal), and you can also configure the firewall (under Networking) to disallow the general public from accessing it.

If there's a more "official" way to do it, I don't know what it us.

  • 0
  On 28/01/2023 at 01:30, virtorio said:

You can secure your Functions by using (and rotating) the App and Function Keys (configured through the Azure Portal), and you can also configure the firewall (under Networking) to disallow the general public from accessing it.

If there's a more "official" way to do it, I don't know what it us.

Expand  

Thanks.  My query was more about how to implement OAUTH2 against the app?

  • 0

Just done some googling.

Good idea to read up on Azure Active Directory: https://learn.microsoft.com/en-us/azure/active-directory/fundamentals/active-directory-whatis and 

 

Please see these links which relate to the use of OAUTH in AD:

 

https://scomnewbie.github.io/posts/authenticatedazfunc/

 

Hope this helps, and is what you're looking for? 

 

I'm afraid I don't have experience with Azure, however I'm a massive googler in my day-to-day job as a professional software developer! When I struggle to find the information I need via documentation, I've always found it helpful to watch youtube videos!

  • 0

I think you may have a misconception about OAUTH...  OAUTH is an authorization method, not an authentication method.

In  a nutshell, if you have ever visited a site that you want to become a member of, and instead of creating your own userid and password, you click a button that says login with Amazon or Login with Facebook, or Login with Google... and you use a pre-established account from one of those services which has already done the authentication, and now you are only authorizing that account the privilege of now using an additional site/service.

This is exactly what OAUTH is.  This is usually applied to your front end...

 

It sounds to me what you want to do is make your back end api private and only usable with your front end... ("the "raw/native" url of the Function App still exists.  This seems a bit like... easily bypassed and any end user could just go to the original Function App url.  Am I missing something?")

There are usually only 2 ways to do this... you either make it available only on your internal network

OR

you need to require a security token as part of the API request paremeters and reject all calls that do not contain it and reject all calls with a submitted token which is invalid...

How you generate and validate those tokens is up to you... (Cryptography hashes?)

 

Also you need to properly implement CORS policies within your http headers to prevent false/fake front ends from using your API.

https://stackoverflow.com/questions/54369416/how-to-secure-own-backend-api-which-serves-only-my-frontend

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Posts

    • many people specially intel users stick with 23h2 because for some 24h2 have degraded performance, meanwhile they took 4 years to fix ryzen performance, amd and microsoft put the work to optimize but now crippling intel. for me windows 11 it feels like a beta OS, its not stable or reliable, every patch tuesday you have to pray that they dont break something.
    • Hi all! My motherboard is Gigabyte x570 Gaming X, and believe it or not I just realised it has two M2 slots 😅 So I wanna buy a new SSD, which would mostly be used for gaming. What would you recommend I buy? Is 990 Evo Plus good choice?
    • Windows 7 its the peak of windows desktop experience, it felt polished, it was CONSISTENT, the UI was not something made to ###### people off it was more functional and productive because everything felt like a improvement. Windows 8 was horrible they did fix a little with 8.1 but the thing its that in usability it was the same as 7 you can avoid all the metro stuff, you don't need to use the cripple setting or metro stuff, for me it was bearable because it can be customized and you can make it like 7 (sure you waste time setting stuff) even if you needed a third party app. And there are serious performance improvement over 7 faster startup, Windows 10 was ok too nothing felt out of place and the start menu was usable it was filled with bloat but as usual you can remove it, what i really hated about 10 at that time it have worse windows update, you cant customize what update to install and the privacy and telemetry is horrible again it was bearable even but w11, not only they double down on things that i seriously hate on 10 like the bloat, they force changes that make no sense, make an worse start menu, worse context menu, worse task bar. force microsoft account. When i tried w10 iot enterprise LTSC on a ancient laptop, i felt that it was a throwback of what OLD windows should be a normal desktop OS with only the basics and you put the rest it was fast fluid functional, no nagging, its a productive, spend less time setting up the OS the way i want it. every windows after 7 its making it worse for me because i have to spend more time setting up
    • https://filepilot.tech/ File Pilot is a whole lot faster and offers a lot of the same features. Has a free beta available, but it looks like it's going to be a paid app in the future.
    • 24H2 was absolutely plagued with stability and compatibility problems, many of which are still not solved. You don't have to take my word for that either, given that Microsoft have an official know issues page available. Games using older versions of Easy Anti-Cheat still cause 24H2 to lock up and/or BSOD, and there's still a compatbility hold on upgrades if you have them installed as a result. Maybe 25H2 will be less of a dumpster fire, but I wouldn't count on it given Microsoft's recent track record.
  • Recent Achievements

    • Explorer
      DougQuaid went up a rank
      Explorer
    • Week One Done
      MIghty Haul earned a badge
      Week One Done
    • One Month Later
      MIghty Haul earned a badge
      One Month Later
    • Collaborator
      KD2004 earned a badge
      Collaborator
    • One Month Later
      ataho31016 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      593
    2. 2
      Michael Scrip
      200
    3. 3
      ATLien_0
      192
    4. 4
      +FloatingFatMan
      140
    5. 5
      Xenon
      127
  • Tell a friend

    Love Neowin? Tell a friend!