gpt4 book ai didi

python - 重定向 URL 在 azure 上不匹配

转载 作者:行者123 更新时间:2023-12-03 07:06:20 27 4
gpt4 key购买 nike

我正在构建一个托管在 azure Web 应用程序服务上的 django 应用程序。我使用了 azure ad 进行身份验证并支持我使用了 python 的 MSAL 库。

在本地主机中,我已经能够使用 azure 登录并查看站点数据,但当应用程序部署到 azure web 应用程序时无法访问该站点。我收到以下错误。

enter image description here

我已使用 HTTP://localhos:8000/auth/redirect 作为重定向 uri,并对部署到 azure web 应用程序的应用程序使用相同的内容:https://.azurewebsites.net/auth/redirect 但它不起作用,并且是上面显示以下错误。

我正在使用 https://github.com/Azure-Samples/ms-identity-python-django-tutorial/tree/main/1-Authentication 提供的以下代码.

我不知道是什么问题。请帮忙。

编辑:

我无法获得解决方案,我已将相同的重定向 URL 添加到 Azure 和代码中。

https://appname.azurewebsites.net/auth/redirect

以下是我如何在内部代码中配置重定向 URL 的代码:这是 aad.config.json 文件:

{
"type": {
"client_type": "CONFIDENTIAL",
"authority_type": "SINGLE_TENANT",
"framework": "DJANGO"
},
"client": {
"client_id": "**",
"client_credential": "*",
"authority": "https://login.microsoftonline.com/*"
},
"auth_request": {
"redirect_uri": null,
"scopes": [],
"response_type": "code"
},
"flask": null,
"django": {
"id_web_configs": "MS_ID_WEB_CONFIGS",
"auth_endpoints": {
"prefix": "auth",
"sign_in": "sign_in",
"edit_profile": "edit_profile",
"redirect": "redirect",
"sign_out": "sign_out",
"post_sign_out": "post_sign_out"
}
}
}

this is the context_processors.py file:
Python
from django.urls import reverse
from django.conf import settings

def context(request):
claims = request.identity_context_data._id_token_claims
exclude_claims = ['iat', 'exp', 'nbf', 'uti', 'aio', 'rh']
claims_to_display = {claim: value for claim, value in claims.items() if claim not in exclude_claims}

client_id=settings.AAD_CONFIG.client.client_id
aad_link="https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Authentication/appId/" + client_id +"/isMSAApp/"


return dict(claims_to_display=claims_to_display,
redirect_uri_external_link = request.build_absolute_uri(reverse(settings.AAD_CONFIG.django.auth_endpoints.redirect)),
aad_link=aad_link)

最佳答案

AADSTS50011 - The reply URL specified in the request does not matchthe reply URLs configured for the application

原因:Azure 门户 中定义的回复 URL 与应用程序向 Azure AD 提供的回复 URL 之间存在不匹配时,通常会出现此错误.

Azure AD 仅接受已在 Azure 门户中定义的保存的回复 URL

解决方法:
要解决此错误,请检查(解码)您登录时出现错误的网址。为此,复制该 Microsoft 登录页面的 URL 并将其粘贴到记事本中。观察重定向 URI,并确保在 codeAzure 门户 注册 URI 中添加该重定向 URI。

转到 Azure 门户 -> Azure AD -> 应用注册 -> 您的应用 -> 身份验证 -> 添加平台 -> Web

1

2

检查您是否有类似这样的重定向 URI -> https://yourappname.azurewebsites.net/signin-oidc 来部署 Azure Web 应用。

如需了解更多信息,请阅读以下引用资料(如果它们有帮助)。

引用文献:

How to authenticate in Django with Azure AD via django-microsoft-auth

https://learn.microsoft.com/en-us/azure/active-directory/develop/reply-url

关于python - 重定向 URL 在 azure 上不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71354132/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com