【问题标题】:Unauthorized: 401 Azure Media Service in PHP. How do I connect to Azure Media Service through PHP未经授权:PHP 中的 401 Azure 媒体服务。如何通过 PHP 连接到 Azure 媒体服务
【发布时间】:2019-01-12 09:43:31
【问题描述】:

我正在尝试通过 Azure 在 github 上提供的 PHP SDK 连接到 Azure Media Service。 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

【问题讨论】:

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


    【解决方案1】:

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

    要解决此问题,请导航到门户中的媒体服务 -> Access control (IAM) -> Add role assignment -> 选择您的服务主体(只需搜索 clientId )并提供 ContributorOwner角色 -> Save,那么它应该可以工作。

    更多详情,请参考此link

    【讨论】:

    • 我什么都做了。我不明白这里似乎有什么问题。好消息是,当我尝试连接 clientId 和 clientKey 时,我获得了访问权限。但它不适用于用户名和密码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    相关资源
    最近更新 更多