azure - Microsoft Entra 可验证凭据管理 API - 颁发客户端凭据问题

标签 azure access-token azure-ad-verifiable-credentials

我正在尝试根据此处找到的文档连接到 Entra 可验证凭据管理 API:https://learn.microsoft.com/en-us/azure/active-directory/verifiable-credentials/admin-api ,但是我似乎无法颁发能够调用管理 API 端点的客户端凭据。

我正在创建一个访问 token ,如下所示:

GET https://login.microsoftonline.com/<tenant_id>/oauth2/token?<query_params>

Query Params:
client_id=<client_id>
client_secret=<client_secret>
scope=6a8b4b39-c021-437c-b060-5a14a3fd65f3/full_access
grant_type=client_credentials

上述调用的作用域是在这里找到的:https://learn.microsoft.com/en-us/azure/active-directory/verifiable-credentials/admin-api调用端点https://verifiedid.did.msidentity.com/v1.0/verifiableCredentials/authorities使用上面返回的 token 返回响应:

"error": {
    "code": "token_validation.audience_invalid",
    "message": "The token does not contain the expected audience '0135fd85-3010-4e73-a038-12560d2b58a9,6a8b4b39-c021-437c-b060-5a14a3fd65f3'."
}

我还尝试使用 .NET 中的 MSAL 库创建访问 token ,如下所示:

var app = ConfidentialClientApplicationBuilder.Create("<client_id>")
       .WithClientSecret("<client_secret>")
       .WithAuthority(new Uri("https://login.microsoftonline.com/<tenant_id>"))
       .Build();

var result = await app.AcquireTokenForClient(new string[] { "6a8b4b39-c021-437c-b060-5a14a3fd65f3/.default"}).ExecuteAsync();

Console.WriteLine("Access Token: {0}", result.AccessToken);

如果范围不以 /.default 结尾,MSAL 库会引发错误,因此我将可验证凭据管理 API 建议的内容切换为 6a8b4b39-c021-437c-b060- 5a14a3fd65f3/.default。使用 MSAL 库输出的凭据调用管理 API 会返回此错误:

"error": {
    "code": "Unauthorized",
    "message": "Provided access token contains no wids.",
    "innererror": {
        "code": "token_validation.invalid_aad_access_token",
        "message": "Provided access token contains no wids."
    }
}

应用程序注册已分配可验证凭据服务Admin.full_access权限,并已获得管理员同意。我不确定我做错了什么,或者需要更改什么才能获取能够调用可验证凭据管理 API 的访问 token 。

最佳答案

我尝试在我的环境中重现相同的结果并得到以下结果:

我有一个 Azure AD 应用程序并添加了 API 权限,如下所示:

enter image description here

现在我生成了具有与您相同的参数的访问 token ,如下所示:

POST https://login.microsoftonline.com/<tenantID>/oauth2/token

client_id:client_id
client_secret:client_secret
scope:6a8b4b39-c021-437c-b060-5a14a3fd65f3/full_access
grant_type:client_credentials

回应:

enter image description here

当我使用上述 token 调用当局时,我收到相同的错误,如下所示:

GET https://verifiedid.did.msidentity.com/v1.0/verifiableCredentials/authorities

回应:

enter image description here

现在,我使用 v2.0 token 端点和 /.default 范围来生成 token ,如下所示:

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

client_id:client_id
client_secret:client_secret
scope:6a8b4b39-c021-437c-b060-5a14a3fd65f3/.default
grant_type:client_credentials

回应:

enter image description here

当我使用此 token 调用当局时,我收到相同的错误,如下所示:

enter image description here

请注意,客户端凭据流程仅适用于应用程序类型权限。

如果您授予的权限是委托(delegate)类型,则需要使用授权码等交互流程来获取 token 。

为了解决该错误,我使用带有以下参数的授权代码流程生成了 token :

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

client_id:client_id
grant_type:authorization_code
client_secret:client_secret
scope:6a8b4b39-c021-437c-b060-5a14a3fd65f3/.default
code:code
redirect_uri:https://jwt.ms

回应:

enter image description here

当我使用此 token 调用当局时,我得到了 响应状态:200 OK,如下所示:

enter image description here

由于我没有任何权限,因此我得到的值为空白。您可以在您的环境中尝试相同的操作,方法是使用授权代码流程生成 token 。

关于azure - Microsoft Entra 可验证凭据管理 API - 颁发客户端凭据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74046929/

相关文章:

java - 如何将多个 Java 项目部署到同一个 Azure 云服务和存储帐户?

azure - Azure Functions 应用程序见解中的自定义属性

c# - 如何使用新名称将流上传到 Azure blob

sql - 如何在 Sql 中设计 oauth 2.0 访问 token 字段?

php - Facebook 应用程序,好友数据访问 token 不起作用

swift - 如何以编程方式快速从 youtube API 获取访问 token ?

azure - 如何使用数据工厂迭代文件夹并合并其中的所有文件?