You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Graph API设置应用密码过期时间为60天不生效,默认仍设为2年的问题排查求助

Azure Graph API设置应用密码过期时间为60天不生效,默认仍设为2年的问题排查求助

我现在正尝试通过Azure Graph API给应用程序设置密码/密钥的过期时间,按照官方文档的说明,默认起始时间是当前时间,过期时间是起始时间加2年,但我想把过期时间改成起始时间加60天。

不过现在遇到了一个棘手的问题:我在请求里明明指定了60天后的过期时间,但API还是自动把过期时间设成了2年,而且全程没有任何错误提示,这让我完全摸不着头脑。我翻遍了官方文档,也问过ChatGPT,但都没找到问题所在。

有没有朋友遇到过类似的情况?麻烦给我点建议,谢谢了!

下面是我用到的代码片段:

print(f"inside add_application_password_rest: {application_id}")
access_token = self.get_authorization_token()
print(f"access_token: {access_token}")
url = f"https://graph.microsoft.com/v1.0/applications/{application_id}/addPassword"

start_date = datetime.now(timezone.utc)
end_date = start_date + timedelta(days=60)
# Format in ISO 8601 format with 'Z' suffix
start_date_str = start_date.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
end_date_str = end_date.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
logger.info("end_date: %s", end_date)
logger.info("start_date_str, end_date_str: %s, %s", start_date_str, end_date_str)

payload = json.dumps({"passwordCredential": {"displayName": "KeyRenewal","startDateTime":start_date_str,"endDateTime":end_date_str}})
response = requests.post(url=url,headers={'Authorization': f'Bearer {access_token}',"Content-Type": "application/json"},json=payload)
logger.info("add_application_password_rest response: %s",response)
logger.info(f"add_application_password.status_code: ${response.status_code}")
response.raise_for_status()
json_response = response.json()
logger.info("json_response: %s",json_response)

备注:内容来源于stack exchange,提问作者K P

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 11:09:33