Microsoft Azure目录oAuth redirect_uri不接受状态查询参数

时间:2020-08-08 14:52:46

标签: oauth-2.0 azure-ad-b2c

我正在尝试实施oAuth流程以使用Microsoft登录。 我有以下端点: https://login.microsoftonline.com/common/oauth2/v2.0/authorize https://login.microsoftonline.com/common/oauth2/v2.0/token

我的流程是这样的: 通过单击“使用Microsoft登录”按钮重定向到Microsoft:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={client_id}&scope=user.read&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F1%2Ffrontend%2Flogin%3Fstate%3Dtest

我的重定向网址是:

http://localhost:8000/1/frontend/login?state=test

其中附有我从Microsoft返回的代码。

然后我对/ token端点执行POST请求。 但是,我收到一条错误消息(AADSTS50011):

AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application:

我发送的数据是正确的,但redirect_uri除外。我具有以下值:

http%3A%2F%2Flocalhost%3A8000%2F1%2Ffrontend%2Flogin%3Fstate%3Dtest

这只是我的重定向url的url编码版本,包括?state = test

我知道,除了redirect_uri之外,其他一切都正常,因为当我删除状态查询参数时,一切都正常。 但是,要在我的应用程序中正确路由redirect_uri,我需要状态参数。 我无法将其添加到“我的应用”设置中,并且必须将其添加到第一个请求中(/授权端点) 一切正常,但是第二个(/令牌)POST请求失败,我无法使用?state =参数输入redirect_uri。 我尝试了几种方法,例如对redirect_uri进行编码,但这没有帮助。

所有其他oAuth流程(如Github)都可以正常工作。除了微软。

1 个答案:

答案 0 :(得分:2)

将您的状态参数附加到auth请求本身,请勿将其放在redirect_uri参数中。然后,状态参数会自动发送回重定向uri。

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={client_id}&scope=user.read&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F1%2Ffrontend%2Flogin&state=xyz

相关问题