我正在尝试使用以下示例将 Azure Key Vault 集成到我的 PHP 应用程序中。
https://github.com/bentaylorwork/php-azure-key-vault
使用本文和 GIT 库中提到的方法,我可以从 Azure Key Vault 获取我的 secret 。然而,这里的挑战是上述方法使用客户端 key 而不是身份验证证书(这是我的首选方法)。
我对上述库进行了相同的更改,并发送以下身份验证请求:
public static function getKeyVaultToken(array $azureAppDetails)
{
$guzzle = new \GuzzleHttp\Client();
$token = $guzzle->post(
"https://login.microsoftonline.com/{$azureAppDetails['appTenantDomainName']}/oauth2/token",
[
'form_params' => [
'client_id' => $azureAppDetails['clientId'],
'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
'resource' => 'https://management.azure.com/',
'grant_type' => 'client_credentials',
'client_assertion' => '', // This contains JWT token consisting with header, payload and digital signature using key.
]
]
)->getBody()->getContents();
return json_decode($token, true)['access_token'];
}
这里的 header、payload 如下:
$header = json_encode(['x5t' => 'thumbprint of certificate uploaded on Aazure', 'alg' => 'RS256', 'typ' => 'JWT']);
$payload = json_encode(['aud' => "https://login.microsoftonline.com/$azureAppDetails['appTenantDomainName']/oauth2/token", "exp" => 1609372800, "iss" => "ClientID", "jti" => "77b2b25f-0288-471f-8b44-3f3c134c0d4f","nbf" => 1603929600,"sub" => "ClientID" ]);
此处的客户端断言是以下组合:
base64uriencode($header).base64uriencode($payload).base65uriencode(digitalsignature)
当我发送带有上述参数的上述请求时,我收到以下错误:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `POST https://login.microsoftonline.com/xxxxx.onmicrosoft.com/oauth2/token` resulted in a `401 Unauthorized` response: {"error":"invalid_client","error_description":"AADSTS700027: Client assertion contains an invalid signature. [Reason - T (truncated...)
任何有关我做错的事情的帮助或指导将不胜感激。
提前致谢。
最佳答案
如果使用服务主体,则可以发送主体 ID 和 key ,如下例所示,这就是我们在适用于 .NET 和其他语言的 Azure Key Vault SDK 中所做的操作。您还发送了错误的资源:
grant_type=client_credentials&client_id={{clientId}}&client_secret={{clientSecret}}&resource=https://vault.azure.net
这将为您提供一个 JSON 负载,其中包含 access_token
,您可以将您的 Authorization
header 作为不记名 token 传递。
关于php - Azure Key Vault 访问错误 - AADSTS700027 : Client assertion contains an invalid signature. [原因 - 通过 PHP 访问时 T(截断...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64765506/