我有一个Web API试图为B2C用户获取一组访问和刷新令牌。用户登录通过配置的“社交身份提供商”完成。Azure AD B2C在令牌请求中返回AADSTS70000错误
API接收授权码。在交换令牌代码时,Azure AD B2C租户的端点端点返回invalid_grant
错误。
我查看了我在网站上找到的其他答案。问题依然存在。指针非常感谢。
详情如下。
的注册和登录型材问题索赔
- 给定的名称
- 电子邮件
- 身份提供商
- 对象ID
从令牌端点错误:
{
"error": "invalid_grant",
"error_description": "AADSTS70000: Transmission data parser failure: Authorization Code is malformed or invalid. [...]",
"error_codes": [
70000
],
[...]
}
授权请求看起来如下:
AUTHORIZATION_ENDPOINT = 'https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize'
authorization_url = f'{AUTHORIZATION_ENDPOINT}' \
f'?client_id={CLIENT_ID}' \
f'&response_type=code' \
f'&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcode' \
f'&scope=openid offline_access' \
f'&nonce=hellobob' \
f'&p=B2C_1_<profile>'
在用户授权,授权码是POST
ED通过API令牌端点。 Payload被表示为一个Python字典。
TOKEN_ENDPOINT = 'https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token'
payload = {
'p': 'B2C_1_<profile>',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'code': code,
'grant_type': 'authorization_code',
'redirect_uri': 'http://localhost:8000/code',
'scope': 'openid offline_access'
}
response = requests.post(TOKEN_ENDPOINT, data=payload)
看起来问题是应该是'https://login.microsoftonline.com/te/ .onmicrosoft.com//oauth2/v2.0/token'的令牌端点URL。除了一些提及'https://login.microsoftonline.com/tfp/ ...'外,我在B2C文档中找不到任何这方面的参考资料。这是最近的变化吗? –
MrBink
这很奇怪,我会与B2C团队签到。 –
有三种方法可以定位Azure AD B2C: 1.使用您使用的URL(在路径中没有te或tfp)并指定策略作为查询参数(p = policyName) 2.沿着路径使用te与b2c政策名称 3.在路径中使用tfp以及b2c策略名称 – Parakh