![](/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.