从过去几周开始,我们很少有客户抱怨我们的应用每 1 小时自动撤销一次 Office365 oauth。这是典型的行为,因为访问令牌的有效期为 1 小时,因此我们的应用旨在使用在 oauth 期间捕获的刷新令牌自动刷新访问令牌。
从过去几周开始,这似乎对至少少数客户不起作用。Office365 令牌 API 抛出以下异常 - https://login.windows.net/common/oauth2/token
{"error":"invalid_grant","error_description":"AADSTS9002313: Invalid request. Request is malformed or invalid.\r\nTrace ID: 7f80c2c3-41bc-41bd-8304-b56969c83a00\r\nCorrelation ID: 5a08714a-1e7d-4f32-814d-146bc721e8ab\r\nTimestamp: 2020-10-12 05:42:11Z","error_codes":[9002313],"timestamp":"2020-10-12 05:42:11Z","trace_id":"7f80c2c3-41bc-41bd-8304-b56969c83a00","correlation_id":"5a08714a-1e7d-4f32-814d-146bc721e8ab","error_uri":"https://login.windows.net/error?code=9002313"}
在这里,错误代码“9002313”表明存在一些与身份验证参数相关的问题,尤其是我们的 azure 应用程序的“client_id”。(参考)
发送以下数据以获取新的访问令牌
- client_id(与 azure 应用相关)
- client_secret(与 azure app 相关)
- grant_type = 'refresh_token'
- 刷新令牌
编辑 1:将令牌端点更新到 v2.0
请求 URI
POST https://login.microsoftonline.com/common/oauth2/v2.0/token
请求正文
client_id=<client-id> &scope=https://outlook.office365.com/Calendars.ReadWrite https://outlook.office365.com/Contacts.ReadWrite https://outlook.office365.com/Mail.ReadWrite &refresh_token=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq... &grant_type=refresh_token &client_secret=<client-secret>
响应体
{"error":"invalid_grant","error_description":"AADSTS9002313: Invalid request. Request is malformed or invalid.\r\nTrace ID: 4447c69e-09d6-4a00-8dfe-735106d71200\r\nCorrelation ID: 1820e135-a511-4516-99d9-b6cebb342eb2\r\nTimestamp: 2020-10-13 03:39:37Z","error_codes":[9002313],"timestamp":"2020-10-13 03:39:37Z","trace_id":"4447c69e-09d6-4a00-8dfe-735106d71200","correlation_id":"1820e135-a511-4516-99d9-b6cebb342eb2","error_uri":"https://login.microsoftonline.com/error?code=9002313"}