我正在尝试实现oAuth流程以登录到微软。我有以下端点:https://login.microsoftonline.com/common/oauth2/v2.0/authorize https://login.microsoftonline.com/common/oauth2/v2.0/token
我的流程是这样的:单击Sign in with 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我的重定向url是:
http://localhost:8000/1/frontend/login?state=test它附加了我从微软收到的代码。
然后,我对/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,我需要状态参数。我无法将其添加到我的应用程序设置中,我必须将其包含在第一个请求(/authorize端点)中,以确保一切正常,但第二个(/token) POST请求失败,我无法使用?state=参数输入我的redirect_uri。我尝试了几种方法,比如对redirect_uri进行编码,但没有任何帮助。
所有其他oAuth流(如Github)都工作得很好。除了微软。
发布于 2020-08-09 00:08:23
将状态参数附加到身份验证请求本身,不要将其放在redirect_uri参数中。则状态参数被自动发送回重定向uri。
https://stackoverflow.com/questions/63316748
复制相似问题