【问题标题】:AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or passwordAADSTS70002:验证凭据时出错。 AADSTS50126:用户名或密码无效
【发布时间】:2019-05-19 15:54:32
【问题描述】:

无法获取访问令牌,授权类型:密码

网址:

https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token?resources=https%3A%2F%2Fgraph.microsoft.com%2F

请求:

  {'grant_type': 'password', 'client_id': <client_id>, 'scope': 'openid User.Read Mail.Read', 'username': '<email_id>', 'client_secret': '<client_secret>, 'password':<password>}

回复:

    {'correlation_id': 'bbe33e96-aeb8-4e8f-8a2f-1330510c298f', 
     'error_codes': [70002, 50126],
     'timestamp': '2018-12-19 06:58:03Z',
     'error': 'invalid_grant',
     'trace_id': 'c69686fb-a84e-4299-a72c-0cf079381300', 
     'error_description': 'AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password\r\nTrace ID: c69686fb-a84e-4299-a72c-0cf079381300\r\nCorrelation ID: bbe33e96-aeb8-4e8f-8a2f-1330510c298f\r\nTimestamp: 2018-12-19 06:58:03Z'}

任何人都可以找出问题所在。 用户名和密码正确。

【问题讨论】:

  • 可能是编码问题。正文需要进行 URL 编码。通常,如果您使用框架提供的工具来构建主体,它会为您完成。

标签: azure-active-directory microsoft-graph-api access-token


【解决方案1】:

建议您尝试以下方式:

网址:

Post https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token

内容类型:

application/x-www-form-urlencoded

请求正文:

client_id=<client_id>&
scope=https://graph.microsot.com/Mail.Read openid User.Read&
grant_type=password&
username=<email_id>&
client_secret=<client_secret>&
password=<password>

然后回应:

【讨论】:

  • @Gaurav Modi,我已经更新了新答案。如果有什么不清楚的地方请告诉我,谢谢。
  • 不应该是graph.microsoFt.com吗?
【解决方案2】:

对我来说,下面是在 Postman 中解决的。

网址(POST):

https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token

标题:

Content-Type 
application/x-www-form-urlencoded

请求正文(文本):

client_id=<client_id>&
scope=https://graph.microsoft.com/.default&
grant_type=client_credentials&
client_secret=<client_secret>

【讨论】:

  • 这里你使用的是grant_type=client_credentials,它肯定会给你错误的grant_type=password
  • @shobhit-walia,我没有说它适用于grant_type=password。我只是提供了一个获取访问令牌的解决方案,对我有用的,我建议了这个解决方案。你能把反对票去掉吗?
  • 嗨@Arpita,是的,您是对的,您的解决方案将有效,但不适用于上述情况,因为在这里,给定问题中明确提到了 grant_type=password。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-12
  • 1970-01-01
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多