2

I created the sample Python Flask Webapp by following the below link.

https://learn.microsoft.com/en-us/azure/app-service/containers/quickstart-python?tabs=bash

I also added the AD Authentication for the Flask application by enabling Authentication in the Settings of the App Services. Now the app works only when the user is logged in and cannot access otherwise.

I would want to fetch the email id if the user who is logged in. I tried checking online but unable to find a way to get the email address of the user.

Any help is really appreciated.

Ashok KS
  • 659
  • 5
  • 21

1 Answers1

8

App Service passes user claims to your application by using special headers. So you can get user information from the request header. Some example headers include:

  • X-MS-CLIENT-PRINCIPAL-NAME
  • X-MS-CLIENT-PRINCIPAL-ID

You can use res.headers to see all the values.

Reference:

Access user claims

Tony Ju
  • 14,891
  • 3
  • 17
  • 31
  • Thank you for your response. Currently the code is just to display "Hello World". How can i change it to display user email in place of hello world? `from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" ` – Ashok KS Jan 07 '20 at 01:30
  • 1
    @AshokKS grab the respective header and return that value instead of Hello World. https://stackoverflow.com/a/29387151/8016720 – John Hanley Jan 07 '20 at 01:50
  • Thanks a lot for that. X-MS-CLIENT-PRINCIPAL-NAME had the email id which is exactly what i wanted. – Ashok KS Jan 07 '20 at 02:49