简体   繁体   English

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

[英]Unauthorized: 401 Azure Media Service in PHP. How do I connect to Azure Media Service through PHP

I am trying to connect to Azure Media Service through PHP SDK provided by Azure on github. 我正在尝试通过Azure在github上提供的PHP SDK连接到Azure Media Service The userconfig.php has few params, I gave all my credentials but I'm getting userconfig.php有几个参数,我给了我所有的凭据,但我得到了

"Fatal error: Uncaught WindowsAzure\\Common\\ServiceException: Fail: Code: 401" “致命错误:未捕获的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";

I'm getting this error.. 我收到此错误。

$ 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

According to the error message, I suppose you have not given a role to your service principal for the media service. 根据错误消息,我想您尚未为媒体服务的服务主体赋予角色。

To fix the issue, navigate to the media service in the portal -> Access control (IAM) -> Add role assignment -> select your service principal(just search the clientId ) and give the Contributor or Owner role -> Save , then it should work. 要解决此问题,请导航至门户中的媒体服务-> Access control (IAM) -> Add role assignment ->选择您的服务主体(只需搜索clientId ),然后赋予ContributorOwner角色-> Save ,然后应该管用。

For more details, refer to this link . 有关更多详细信息,请参考此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM