标签:services new point tin sele existing png director 内容
在简书中查看,请点击我。
关于相关内容解释,请参考docs文档 https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-dotnet-get-started-with-aad
说明: 本步骤默认我们已经有Azure订阅,并且步骤是针对Global Azure,如果是China Mooncake请仅供参考。
单击All services,在搜索框中,键入Media Service
单击Media Services,在Media Services,单击+ Add
在左侧服务列表中,单击Azure Active Directory
单击New application registration
记录下app的名字,Application ID等信息 (稍后,Application ID在Desktop程序中用到,它在App.config中的变量名是AMSClientId)
在Passwords中,键入Key Description, 比如Key1,选择duration,单击Save
保存完成以后,记录下Value的值 (稍后,这个值在Desktop程序中用到,它在App.config中的变量名是AMSClientSecret)
选择API access
单击Connect to Azure Media Services API with service principal
选择找到的app,并单击OK
右键单击项目,选择Manage NuGet Packages
右键单击References,选择Add Reference
<appSettings> <add key="AMSAADTenantDomain" value="{your AAD Tenant Domain}"/> <add key="AMSRESTAPIEndpoint" value="{your REST API Endpoint}"/> <add key="AMSClientId" value="{your Application ID}"/> <add key="AMSClientSecret" value="{your Client secret}"/> </appSettings>
注意: 请使用你记录下来的值替换{ }中的内容。
using Microsoft.WindowsAzure.MediaServices.Client; using System.Configuration;
private static readonly string _AADTenantDomain = ConfigurationManager.AppSettings["AMSAADTenantDomain"]; private static readonly string _RESTAPIEndpoint = ConfigurationManager.AppSettings["AMSRESTAPIEndpoint"]; private static readonly string _AMSClientId = ConfigurationManager.AppSettings["AMSClientId"]; private static readonly string _AMSClientSecret = ConfigurationManager.AppSettings["AMSClientSecret"];
AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(_AADTenantDomain, new AzureAdClientSymmetricKey(_AMSClientId, _AMSClientSecret), AzureEnvironments.AzureCloudEnvironment); var tokenProvider = new AzureAdTokenProvider(tokenCredentials);
CloudMediaContext context = new CloudMediaContext(new Uri(_RESTAPIEndpoint), tokenProvider);
App.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> </startup> <appSettings> <add key="AMSAADTenantDomain" value="{your AAD Tenant Domain}"/> <add key="AMSRESTAPIEndpoint" value="{your REST API Endpoint}"/> <add key="AMSClientId" value="{your Application ID}"/> <add key="AMSClientSecret" value="{your Client secret}"/> </appSettings> </configuration>
注意: 请使用你记录下来的值替换{ }中的内容。
Program.cs
using System; using System.Linq; using Microsoft.WindowsAzure.MediaServices.Client; using System.Configuration; namespace ConsoleApp4 { class Program { private static readonly string _AADTenantDomain = ConfigurationManager.AppSettings["AMSAADTenantDomain"]; private static readonly string _RESTAPIEndpoint = ConfigurationManager.AppSettings["AMSRESTAPIEndpoint"]; private static readonly string _AMSClientId = ConfigurationManager.AppSettings["AMSClientId"]; private static readonly string _AMSClientSecret = ConfigurationManager.AppSettings["AMSClientSecret"]; static void Main(string[] args) { AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(_AADTenantDomain, new AzureAdClientSymmetricKey(_AMSClientId, _AMSClientSecret), AzureEnvironments.AzureCloudEnvironment); var tokenProvider = new AzureAdTokenProvider(tokenCredentials); CloudMediaContext context = new CloudMediaContext(new Uri(_RESTAPIEndpoint), tokenProvider); var assets = context.Assets; foreach (var item in assets) { Console.WriteLine(item.Name); } Console.ReadLine(); Console.WriteLine(context.StorageAccounts.First().Name.ToString()); } } }
手把手:使用service principal连接Azure Media Service
标签:services new point tin sele existing png director 内容
原文地址:https://www.cnblogs.com/qixue/p/10076759.html