Код: Выделить всё
https://myfunc-dev-we-01.azurewebsites.net/api/http_trigger
Правильно перенаправляет меня на страницу аутентификации Microsoft, а аутентификация работает нормально. Я попытался извлечь его, используя заголовок X-MS-Client Principal , но я не могу заставить его работать.
Код: Выделить всё
import azure.functions as func
import logging
import base64
import json
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="http_trigger")
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
# Retrieve the X-MS-CLIENT-PRINCIPAL header
client_principal_header = req.headers.get('X-MS-CLIENT-PRINCIPAL')
logging.info(f"X-MS-CLIENT-PRINCIPAL header: {client_principal_header}")
user_name = None
if client_principal_header:
try:
# Decode the Base64-encoded header
decoded_header = base64.b64decode(client_principal_header).decode('utf-8')
logging.info(f"Decoded X-MS-CLIENT-PRINCIPAL: {decoded_header}")
client_principal = json.loads(decoded_header)
# Log the entire client principal for debugging
logging.info(f"Client Principal: {client_principal}")
# Extract the user's name from the claims
user_name = client_principal.get('userPrincipalName') or client_principal.get('name')
except Exception as e:
logging.error(f"Error decoding client principal: {e}")
if user_name:
return func.HttpResponse(f"Hello, {user_name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. However, no authenticated user information was found.",
status_code=200
)
Я продолжаю получать ответ:
"Эта функция, запускаемая HTTP, успешно выполненная. Однако мне не было обнаружено аутентифицированной информации. В Azure Ad Authentication для включения заявления по электронной почте?>
Подробнее здесь: https://stackoverflow.com/questions/795 ... informatio