azure ad b2c 运行用户流不返回带有范围的 token

标签 azure azure-active-directory

我已经配置了用户流程。我选择访问 token -> 资源 {我的 API 之一} 范围 {我的所有相关范围} 并按运行用户流程并将回调 URL 添加为 jwt.ms ,我没有看到 token 上的范围。为什么?

最佳答案

对于要包含在 token 中的范围,必须调用 token 端点。 当我们运行用户流时,我们会获得来自授权端点的访问 token ,如下所示:

enter image description here

https://xxxb2c.b2clogin.com/xxxb2c.onmicrosoft.com/oauth2/v2.0/authorize?p=B2C_1_reposcope&client_id=1cf9xxxa5&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fxxxb2c.b2clogin.com%2Fxxxb2c.onmicrosoft.com%2Foauth2%2Fauthresp&scope=openid&response_type=id_token&prompt=login

在这里我们获取应用程序的访问 token :

enter image description here

对于存在的范围:

确保授予调用 API 所需的正确 API 权限,并公开 API 的范围。

enter image description here

公开 API:

enter image description here

使用下面的端点,只需修改从运行用户流中获取的 URL:

<强> response_type=code ,包括范围,&scope= https://xxxb2c.onmicrosoft.com/1cf9d6axxx2a5/.default &scope = openid配置文件offline_access

验证网址:

<强> https://xxx2c.b2clogin.com/xb2c.onmicrosxxxoft.com/oauth2/v2.0/authorize?p=B2C_1_reposcope&client_id=1cf9d6xxx098e2a5&client_secret=6oo8Q~Ax_ZC-xxcfw&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.ms&scope= https://xxxb2c.onmicrosoft.com/1cf9xxxx18-2c719098e2a5/.default openid profile offline_access&response_type=code&prompt=login

enter image description here

获取代码,记下它,然后检查 token 端点的范围和正确的客户端 key ,将复制的代码放在下面的 token 端点中:

token 端点:

https://xxxb2c.b2clogin.com/xxxb2c.onmicrosoft.com/oauth2/v2.0/token?p=B2C_1_reposcope&client_id=1cf9d6xxx2a5&client_secret=6oo8xxx_ZC-cfw&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.ms&scope=https://xxxb2c.onmicrosoft.com/1cf9xxx098e2a5/.default openid profile offline_access&response_type=id_token&prompt=login&grant_type=authorization_code&code=<paste the code here>

token 中的声明:

可以在 token 中看到范围:

        {
    
"id_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ilg1ZVhrNHh5b2pORnVtMWtsMll0djhkbE5QNC1jNTdkTzZRR1RWQndhTmsixxxxxxxxxxxx ",
        "token_type":"Bearer",
        "not_before":1677569996,
        "id_token_expires_in":3600,
        "profile_info":"xx",
        "scope":"offline_access openid",
        "refresh_token":"eyJraWQiOiJjcGltY29yZV8wOTI1MjAxNSIsInZlciI6IjEuMCIsInppcCI6IkRlZmxhdGUiLCJzZXIiOiIxLjAifQ..xxx",
        "refresh_token_expires_in":1209600
    }

enter image description here

关于azure ad b2c 运行用户流不返回带有范围的 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75584161/

相关文章:

azure - 除了注册 Active Directory 之外,还有其他方法可以获取 azure clientID 吗?

Azure 服务主体 - 将成员添加到 AD 组的权限

azure - 将身份验证从基于 VM 的 AD 集成到 Azure SQL DB

azure - 在 azure 上部署 Microsoft 企业机器人模板时出现错误

azure - 使用Azure逻辑应用程序发送带有多个附件的电子邮件

linux - 如何解决这个 omsagent 僵尸问题

angular - Azure CDN 与 Verizon - 重写 URL 以始终加载 index.html

来自 Github 的 Azure 部署失败

asp.net-mvc - 使用WindowsAzureActiveDirectoryBearer身份验证和应用程序级凭据

没有电子邮件的 Azure B2C 用户流