Access user info in a python Azure function

JDR 90 Reputation points
2023-09-21T01:42:51.4933333+00:00

Hi,

Failry new to Azure. I have created a React web app service and protected it with authentication following https://learn.microsoft.com/en-us/azure/active-directory/develop/multi-service-web-app-authentication-app-service.

Using this web app, my users can call azure functions (rest api calls from React) to perform data manipulation operations (upload, edit, remove, etc.).

Q1: do I need to follow the same process to add authentication to my azure functions?

Q2: Can I access some info about the user (for ex. a user id) in my azure functions? My functions are in python, python examples would be fantastic.

Thanks in advance for any help.

JD

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,399 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JDR 90 Reputation points
    2023-09-21T23:17:54.5533333+00:00

    As simple as

    def main(req: func.HttpRequest) -> func.HttpResponse:
        # Retrieve the claims from the request headers
        claims = req.headers.get("X-MS-CLIENT-PRINCIPAL")
    
    

    and claims contains a Base64 encoded JSON representation of the available claims.

    See https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-user-identities#access-user-claims-in-app-code


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.