Azure应用无法使用C#连接到媒体服务

时间:2017-11-28 21:07:57

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

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

所有权限似乎都是正确的,我尝试运行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应用程序上执行此操作?

1 个答案:

答案 0 :(得分:0)

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

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

客户端密钥在API访问下的AMS帐户中生成 - &gt;使用Service Principal连接到Azure API - &gt;管理应用程序 - &gt;键 - &gt;密码

希望你不需要浪费一周的时间来尝试各种各样的事情。

PS:AMS开发人员支持团队向我提供了答案。