【问题标题】:Azure app cannot connect to Media Services using C#Azure 应用无法使用 C# 连接到媒体服务
【发布时间】:2017-11-28 21:07:56
【问题描述】:

我正在尝试使用 Azure 媒体服务对上传到我的 Web 应用程序的视频进行编码。现在 ACS 已从 AMS .net 扩展和 api 中删除,似乎唯一的连接方式是使用 Azure AD 凭据。所以我已经在 AAD 注册了服务主体,并在 AMS 上授予了贡献者权限。

所有权限似乎都正确,我尝试运行this sample code,但 Azure 拒绝颁发令牌。

第 80 行失败:

IAsset sourceAsset = _sourceContext.Assets.Where(a => a.Id == _sourceAssetID).First();

与针对 AMS 的任何其他操作相同。

"ExceptionMessage": "Error HRESULT E_FAIL has been returned from a call to a COM component.",
        "ExceptionType": "System.Runtime.InteropServices.COMException",
        "StackTrace": "   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.WebUI.<AcquireAuthorizationAsync>d__12.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.<AcquireAuthorizationAsync>d__10.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.<PreTokenRequest>d__9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n   at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.<RunAsync>d__57.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenCommonAsync>d__39.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenAsync>d__28.MoveNext()"

此错误消息来自 AD。

想知道我是否需要在 Azure Api 应用上做任何事情来完成这项工作?

【问题讨论】:

    标签: azure azure-web-app-service azure-media-services azure-api-apps


    【解决方案1】:

    要使用服务主体,需要证书或客户端密码。这是简单的方法 - 使用客户端密码

    var tokenCredentials = new AzureAdTokenCredentials(_AADTenantDomain,
                                        new AzureAdClientSymmetricKey(clientId, clientSecret), 
                                        AzureEnvironments.AzureCloudEnvironment);
                var tokenProvider = new AzureAdTokenProvider(tokenCredentials);
    

    Client Secret 在 API Access 下的 AMS 帐户中生成 --> 使用 Service Principal 连接到 Azure API --> Manage Application --> Keys --> Passwords

    希望您不必浪费一周的时间尝试各种事情。

    PS:答案是 AMS 开发人员支持团队提供给我的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-26
      • 1970-01-01
      • 2023-02-09
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多