为什么Azure AD中的“访问授权格式错误”?

时间:2014-12-10 00:04:08

标签: python azure azure-active-directory

我正在尝试使用this bit of documentation作为指南,在Azure Active Directory中进行单点登录。但是,当我进入“访问令牌请求”阶段时,我收到以下错误:

  

验证凭据时出错。 AADSTS70000:提供的访问授权无效或格式错误。

在互联网上搜索,似乎这通常是由于第二步中缺少redirect_uri参数或两步之间不同而导致的,但这似乎并非如此。

以下是每个步骤中发生的事情:

授权步骤(来自浏览器的原始HTTP请求):

GET /[snip tenant id]/oauth2/authorize?redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fpost-login%3Fdest%3D%252F&response_type=code&client_id=[snip client id] HTTP/1.1
Host: login.windows.net
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-AU,en;q=0.8,en-US;q=0.6
Cookie: [snip a handful of cookies]

重定向步骤(来自浏览器的原始HTTP请求):

GET /post-login?code=[snip base64]&session_state=[snip uuid] HTTP/1.1
Host: localhost:5000
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-AU,en;q=0.8,en-US;q=0.6
Cookie: csrftoken=vBjLMAFTw7NSFEJHb2t9GTA0Eoced4rw; azure-redirect-uri="http://localhost:5000/post-login?dest=%2F"

令牌请求步骤(来自服务器代码的原始HTTP请求):

POST /[snip tenant id]/oauth2/token HTTP/1.1
Host: login.windows.net
Content-Length: 805
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.5.0 CPython/2.7.6 Darwin/14.0.0
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded

redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fpost-login%3Fdest%3D%252F&client_secret=Dsysz7F%2FXh2Wu1YKE%2BVEOkvMHhvc38DnwFTa5qekyXM%3D&code=[snip base64]&client_id=[snip client id]&grant_type=authorization_code

对令牌请求的响应(从返回的JSON解析的Python dict):

{
    u'timestamp': u'2014-12-09 05:37:58Z', 
    u'trace_id': u'ae00a782-30f1-4e1c-a183-f19330ecca37',
    u'submit_url': None, 
    u'correlation_id': u'21a7b861-5171-4083-9da5-67e7d956ab5e',
    u'error_description': u'AADSTS70002: Error validating credentials. AADSTS70000: The provided access grant is invalid or malformed.\r\nTrace ID: ae00a782-30f1-4e1c-a183-f19330ecca37\r\nCorrelation ID: 21a7b861-5171-4083-9da5-67e7d956ab5e\r\nTimestamp: 2014-12-09 05:37:58Z',
    u'context': None, 
    u'error': u'invalid_grant',
    u'error_codes': [70002, 70000]
}

1 个答案:

答案 0 :(得分:3)

由于重定向uri末尾的查询参数,您的令牌请求失败。 OAuth重定向URI不应包含任何查询参数或片段。您可以使用state参数。

我认为授权电话也不应该成功,但显然它确实如此。我正在检查是否存在错误。

有关如何使用OAuth状态参数的更多信息,请参阅此链接:

http://www.thread-safe.com/2014/05/the-correct-use-of-state-parameter-in.html

相关问题