未经授权:PHP中的401 Azure媒体服务。如何通过PHP连接到Azure媒体服务

时间:2019-01-12 09:43:32

标签: php azure http-status-code-401 azure-media-services unauthorized

我正尝试通过Azure在github上提供的Azure Media Service连接到PHP SDK。 userconfig.php有几个参数,我给了我所有的凭据,但是我得到了

  

“致命错误:未捕获的WindowsAzure \ Common \ ServiceException:失败:   代码:401“

<?php

set_time_limit(600); //set timeout to 10 minutes, or you can set max_execution_time in php.ini

date_default_timezone_set('America/Los_Angeles');

$tenant =  "******.onmicrosoft.com";
$username = '***@*****.com';
$password = '****@12345';
$clientId = "*******-*******-46e9-b525-5f1f2ec4e4ea";
$clientKey = "*******-*******/uUS+hKm67kfwZZs4w4=";
$restApiEndpoint = "https://indwaretest1.restv2.japanwest.media.azure.net/api/";
// $pfxFileName = "C:\\Path\\To\\keystore.pfx";
// $pfxPassword = "KeyStorePassword";

我遇到此错误。

$ php index.php
PHP Fatal error:  Uncaught WindowsAzure\Common\ServiceException: Fail:
Code: 401
Value: Unauthorized
details (if any): . in D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\Http\HttpClient.php:405
Stack trace:
#0 D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\Http\HttpClient.php(301): WindowsAzure\Common\Internal\Http\HttpClient::throwIfError(401, 'Unauthorized', Object(GuzzleHttp\Psr7\Stream), Array)
#1 D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\RestProxy.php(144): WindowsAzure\Common\Internal\Http\HttpClient->sendAndGetHttpResponse(Array, Object(WindowsAzure\Common\Internal\Http\Url))
#2 D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\ServiceRestProxy.php(89): WindowsAzure\Common\Internal\RestProxy->sendHttpContext(Object(WindowsAzure\Common\Internal\Http\HttpCallContext))
#3 D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\ServiceRestProxy.php(128): WindowsAzure\Common\Internal\ServiceRestProxy->sendHttpContext(Object(WindowsAzure\Common\Internal in D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\Http\HttpClient.php on line 405

Fatal error: Uncaught WindowsAzure\Common\ServiceException: Fail:
Code: 401
Value: Unauthorized
details (if any): . in D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\Http\HttpClient.php:405
Stack trace:
#0 D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\Http\HttpClient.php(301): WindowsAzure\Common\Internal\Http\HttpClient::throwIfError(401, 'Unauthorized', Object(GuzzleHttp\Psr7\Stream), Array)
#1 D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\RestProxy.php(144): WindowsAzure\Common\Internal\Http\HttpClient->sendAndGetHttpResponse(Array, Object(WindowsAzure\Common\Internal\Http\Url))
#2 D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\ServiceRestProxy.php(89): WindowsAzure\Common\Internal\RestProxy->sendHttpContext(Object(WindowsAzure\Common\Internal\Http\HttpCallContext))
#3 D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\ServiceRestProxy.php(128): WindowsAzure\Common\Internal\ServiceRestProxy->sendHttpContext(Object(WindowsAzure\Common\Internal in D:\PHP\azure\vendor\microsoft\windowsazure\src\Common\Internal\Http\HttpClient.php on line 405

1 个答案:

答案 0 :(得分:0)

根据错误消息,我想您尚未为媒体服务的服务主体赋予角色。

要解决此问题,请在门户中导航至媒体服务-> Access control (IAM)-> Add role assignment->选择服务主体(只需搜索clientId)并为{ {1}}或Contributor角色-> Owner,那么它应该可以工作。

有关更多详细信息,请参阅此link