![](/img/trans.png)
[英]How to get thumbprint of the cert associated with a service principal in AzureAD when the sp is created independently without App and Cred
[英]How to get thumbprint of the certificate associated with a service principal using Powershell?
我有一个与 Azure AD 中的服务主体关联的证书。 如何使用 powershell 获取与其关联的证书名称或指纹?
我尝试过Get-AzureRmADServicePrincipalCredential
、 Get-AzureRmADSpCredential
和Get-AzureADServicePrincipalKeyCredential
命令,但它们返回的是Key Identifier
而不是指纹。
基本上我想在撤销它之前识别哪个证书与委托人相关联。
正如@Stanley Gong 提到的,您可以使用 MS Graph 来获取它。
这是另一种方法,请尝试以下命令, $Thumbprint
是您想要的。
注意<object-id>
是您的 AD 应用程序(应用程序注册)的 object id,而不是服务主体(企业应用程序),它们是不同的。
$CustomKeyIdentifier = (Get-AzureADApplicationKeyCredential -ObjectId "<object-id>").CustomKeyIdentifier
$Thumbprint = [System.Convert]::ToBase64String($CustomKeyIdentifier)
尝试下面的 PS 命令通过 Microsoft Graph API 获取证书指纹:
$clientId = "<your Azure AD App ID>"
$clientSec="<your Azure AD App Secret>"
$appObjId = "<object ID of the app that you want to query>"
$tenant = "<your tenant ID>"
$body=@{
"grant_type"="client_credentials";
"resource"="https://graph.microsoft.com/";
"client_id"= $clientId;
"client_secret" = $clientSec
}
$accessToken=(Invoke-RestMethod -Uri "https://login.windows.net/$tenant/oauth2/token" -Method POST -Body $body ).access_token
$keyCreds = Invoke-RestMethod -Uri "https://graph.microsoft.com/beta/applications/$appObjId/keyCredentials" -Method Get -Headers @{"Authorization" = "Bearer $accessToken"}
$keyCreds.value.customKeyIdentifier
请注意,确保您用于获取令牌的应用程序具有以下权限,以便它可以调用 Microsoft graph API 来查询您的应用程序:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.