Azure应用程序无法使用C#连接到媒体服务 [英] Azure app cannot connect to Media Services using C#

查看:139
本文介绍了Azure应用程序无法使用C#连接到媒体服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Azure媒体服务对上传到我的Web应用程序的视频进行编码.现在ACS已从AMS .net扩展和api中删除,似乎唯一的连接方法是使用Azure AD凭据.因此,我已经在AAD注册了服务负责人,并在AMS上授予了 contributor .

I am trying to use Azure Media Services to encode videos uploaded to my web app. Now that ACS is removed from AMS .net extensions and api, it seems the only way to connect is using Azure AD credentials. So I have registered service principal with AAD and Granted contributor right on AMS.

所有权限似乎都是正确的,我尝试运行

All the permissions seems correct and I try to run this sample code and Azure refuses to issue token.

第80行失败:

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

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

Same case with any other operation against 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()"

此错误消息来自广告.

想知道我是否需要在Azure Api应用程序上进行任何操作才能使这项工作正常进行?

Wondering if there is anything I need to do on Azure Api app to make this work?

推荐答案

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

To use Service Principal either a certificate or a Client Secret is required. Here is the easy way - use Client Secret

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

在AMS帐户的API访问下生成客户端密钥->使用服务主体连接到Azure API->管理应用程序->密钥->密码

Client Secret is generated in AMS account under API Access --> Connect to Azure API using Service Principal --> Manage Application --> Keys --> Passwords

希望您不必花一个星期来尝试各种事情.

Hope you don't need to waste a week trying all sort of things.

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

PS: Answer was provided to me by AMS developer support team.

这篇关于Azure应用程序无法使用C#连接到媒体服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆