Microsoft Partner API认证失败:获取access_token后调用接口返回401错误
问题:调用Microsoft Partner Center API返回401 invalid_grant错误
背景
- 已在Azure AD中创建应用,并遵循《应用与用户访问》相关步骤
- 确认Microsoft Partner API仅支持MFA认证,无法通过用户名+密码方式向
https://login.microsoftonline.com发起认证
获取令牌的操作步骤
- 在浏览器中打开授权链接获取授权码:
https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/authorize?client_id=CLIENT_ID&response_type=code&redirect_uri=https://****/test.php&response_mode=form_post&scope=offline_access%20openid%20profile%20User.Read&state=1
- 通过回调URL接收授权码后,执行以下请求获取access_token和refresh_token:
curl --request POST 'https://login.microsoftonline.com/TENANT_ID/oauth2/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=authorization_code' \ --data-urlencode 'client_id=CLIENT_ID' \ --data-urlencode 'client_secret=CLIENT_SECRET' \ --data-urlencode 'resource=https://api.partner.microsoft.com' \ --data-urlencode 'code=CODE_FROM_PREVIOUS_REQUEST' \ --data-urlencode 'redirect_uri=https://****/test.php'
当前问题
已成功获取access_token和refresh_token,但调用以下Partner Center API时返回401 invalid_grant错误:
curl --request GET 'https://api.partnercenter.microsoft.com/v1/customers' \ --header 'Authorization: Bearer ACCESS_TOKEN'
此前参考过同类问题但未解决。
内容的提问来源于stack exchange,提问作者Marijn
相关产品推荐
相关产品推荐

