Skip to content

Commit b632213

Browse files
authored
Merge pull request #172177 from xpouyat/xpouyat-sept21-identity
Update of the article to use the new Azure.Identity package.
2 parents 52155a1 + 232f2fe commit b632213

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

articles/media-services/latest/integrate-azure-functions-dotnet-how-to.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Run the dotnet add package command in the Terminal window to install the extensi
8181
```bash
8282
dotnet add package Azure.Storage.Blobs
8383
dotnet add package Microsoft.Azure.Management.Media
84-
dotnet add package Microsoft.Identity.Client
84+
dotnet add package Azure.Identity
8585
```
8686

8787
## Generated project files

articles/media-services/latest/security-function-app-managed-identity-cli-tutorial.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: IngridAtMicrosoft
66
manager: femila
77
ms.service: media-services
88
ms.topic: tutorial
9-
ms.date: 05/18/2021
9+
ms.date: 09/13/2021
1010
ms.author: inhenkel
1111
---
1212

@@ -112,34 +112,35 @@ func new --name OnAir --template "HTTP trigger" --authlevel "anonymous"
112112

113113
## Configure the functions project
114114

115-
### Add items to the .csproj file
115+
### Install Media Services and other extensions
116116

117-
In the autogenerated “.csproj” file, add the following lines to the first `<ItemGroup>`:
117+
Run the dotnet add package command in the Terminal window to install the extension packages that you need in your project. The following command installs the Media Services and Azure Identity packages.
118118

119-
```xml
120-
<PackageReference Include="Microsoft.Azure.Management.Fluent" Version="1.37.0" />
121-
<PackageReference Include="Microsoft.Azure.Management.Media" Version="3.0.4" />
119+
```bash
120+
dotnet add package Microsoft.Azure.Management.Media
121+
dotnet add package Azure.Identity
122122
```
123123

124124
### Edit the OnAir.cs code
125125

126126
Change the `OnAir.cs` file. Change `subscriptionId`, `resourceGroup`, and `mediaServicesAccountName` variables to the ones you decided upon earlier.
127127

128-
```aspx-csharp
129-
using System.Threading.Tasks;
128+
```csharp
129+
using Azure.Core;
130+
using Azure.Identity;
131+
using Microsoft.AspNetCore.Http;
130132
using Microsoft.AspNetCore.Mvc;
133+
using Microsoft.Azure.Management.Media;
134+
using Microsoft.Azure.Management.Media.Models;
131135
using Microsoft.Azure.WebJobs;
132136
using Microsoft.Azure.WebJobs.Extensions.Http;
133-
using Microsoft.AspNetCore.Http;
134137
using Microsoft.Extensions.Logging;
135-
using Microsoft.Azure.Management.Media;
136-
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
137-
using Microsoft.Azure.Management.ResourceManager.Fluent;
138-
using Microsoft.Azure.Management.Media.Models;
138+
using Microsoft.Rest;
139+
using System.Threading.Tasks;
139140

140141
namespace MediaServicesLiveMonitor
141142
{
142-
public static class LatestAsset
143+
public static class OnAir
143144
{
144145
[FunctionName("OnAir")]
145146
public static async Task<IActionResult> Run(
@@ -154,14 +155,18 @@ namespace MediaServicesLiveMonitor
154155
{
155156
return new BadRequestObjectResult("Missing 'name' URL parameter");
156157
}
157-
158-
var credentials = SdkContext.AzureCredentialsFactory.FromSystemAssignedManagedServiceIdentity(
159-
MSIResourceType.AppService,
160-
AzureEnvironment.AzureGlobalCloud);
161158

162-
var subscriptionId = "00000000-0000-0000-000000000000"; // Update
163-
var resourceGroup = "<your-resource-group-name>"; // Update
164-
var mediaServicesAccountName = "<your-media-services-account-name>"; // Update
159+
var credential = new ManagedIdentityCredential();
160+
var accessTokenRequest = await credential.GetTokenAsync(
161+
new TokenRequestContext(
162+
scopes: new string[] { "https://management.core.windows.net" + "/.default" }
163+
)
164+
);
165+
ServiceClientCredentials credentials = new TokenCredentials(accessTokenRequest.Token, "Bearer");
166+
167+
var subscriptionId = "00000000-0000-0000-000000000000"; // Update
168+
var resourceGroup = "<your-resource-group-name>"; // Update
169+
var mediaServicesAccountName = "<your-media-services-account-name>"; // Update
165170
166171
var mediaServices = new AzureMediaServicesClient(credentials)
167172
{
@@ -174,7 +179,7 @@ namespace MediaServicesLiveMonitor
174179
{
175180
return new NotFoundResult();
176181
}
177-
182+
178183
return new OkObjectResult(liveEvent.ResourceState == LiveEventResourceState.Running ? "On air" : "Off air");
179184
}
180185
}

0 commit comments

Comments
 (0)